-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
docs: added play dialogue code example
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Replaced when project is built from commit logs via Semantic Release. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors { | ||
public class NodeTypeAttribute : Attribute { | ||
public Type Type { get; } | ||
|
||
public NodeTypeAttribute (Type type) { | ||
Type = type; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System.Linq; | ||
using CleverCrow.Fluid.Dialogues.Graphs; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors { | ||
public static class CreateDialogueGraph { | ||
[MenuItem("Assets/Create/Fluid/Dialogue/Graph", priority = 0)] | ||
public static void CreateAsset () { | ||
var graph = CreateGraph(); | ||
|
||
var root = ScriptableObject.CreateInstance<NodeRootData>(); | ||
root.rect.position = | ||
new Vector2(50 + ScrollManager.WINDOW_SIZE /2, 200 + ScrollManager.WINDOW_SIZE / 2); | ||
graph.AddNode(root); | ||
graph.root = root; | ||
|
||
AssetDatabase.AddObjectToAsset(root, graph); | ||
AssetDatabase.SaveAssets(); | ||
} | ||
|
||
private static DialogueGraph CreateGraph () { | ||
var graph = ScriptableObject.CreateInstance<DialogueGraph>(); | ||
graph.name = "Dialogue"; | ||
var path = AssetDatabase.GetAssetPath(Selection.activeObject); | ||
var assetsInPath = AssetDatabase | ||
.FindAssets("t:DialogueGraph", new[] {path}) | ||
.Select(i => { | ||
var p = AssetDatabase.GUIDToAssetPath(i); | ||
var parts = p.Split('/'); | ||
return parts[parts.Length - 1].Replace(".asset", ""); | ||
}) | ||
.ToList(); | ||
|
||
var count = 0; | ||
while (assetsInPath.Find(i => i == graph.name) != null) { | ||
count++; | ||
var name = graph.name.Split('(')[0]; | ||
graph.name = $"{name}({count})"; | ||
} | ||
|
||
AssetDatabase.CreateAsset(graph, $"{path}/{graph.name}.asset"); | ||
return graph; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Choices; | ||
using CleverCrow.Fluid.Dialogues.Graphs; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using CleverCrow.Fluid.SimpleSpellcheck; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
[CustomEditor(typeof(DialogueGraph))] | ||
public class DialogueGraphInspector : Editor { | ||
private SerializedProperty _nodes; | ||
|
||
private void OnEnable () { | ||
_nodes = serializedObject.FindProperty("_nodes"); | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
DrawDefaultInspector(); | ||
|
||
if (GUILayout.Button("Spell Check")) { | ||
RunSpellCheck(); | ||
} | ||
|
||
if (GUILayout.Button("Edit Dialogue")) { | ||
DialogueWindow.ShowGraph(target as DialogueGraph); | ||
} | ||
} | ||
|
||
private void RunSpellCheck () { | ||
var logList = new List<LogEntry>(); | ||
|
||
for (var i = 0; i < _nodes.arraySize; i++) { | ||
var node = new SerializedObject(_nodes.GetArrayElementAtIndex(i).objectReferenceValue); | ||
CreateLog(node, logList); | ||
} | ||
|
||
SpellCheck.Instance.ShowLogs($"Dialogue: {target.name}", logList); | ||
} | ||
|
||
private void CreateLog (SerializedObject node, List<LogEntry> logList) { | ||
var textProp = node.FindProperty("dialogue"); | ||
var choiceProp = node.FindProperty("choices"); | ||
|
||
if (textProp == null && choiceProp == null) return; | ||
|
||
var textIsInvalid = textProp != null && SpellCheck.Instance.IsInvalid(textProp.stringValue); | ||
|
||
var choiceIsInvalid = false; | ||
if (choiceProp != null) { | ||
for (var j = 0; j < choiceProp.arraySize; j++) { | ||
var choice = choiceProp.GetArrayElementAtIndex(j).objectReferenceValue as ChoiceData; | ||
choiceIsInvalid = SpellCheck.Instance.IsInvalid(choice.text); | ||
if (choiceIsInvalid) break; | ||
} | ||
} | ||
|
||
if (textIsInvalid || choiceIsInvalid) { | ||
var preview = "Invalid choice(s)"; | ||
if (textProp != null) preview = textProp.stringValue; | ||
|
||
var log = new LogEntry(preview, () => { | ||
NodeDataBaseEditor.ShowValidation(node.targetObject as NodeDataBase); | ||
Selection.activeObject = node.targetObject; | ||
}); | ||
|
||
logList.Add(log); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using CleverCrow.Fluid.Dialogues.Choices; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using CleverCrow.Fluid.SimpleSpellcheck; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
[CustomEditor(typeof(NodeDataBase), true)] | ||
public class NodeDataBaseEditor : Editor { | ||
private SerializedProperty _dialogue; | ||
private SerializedProperty _choices; | ||
|
||
private ConditionSortableList _conditions; | ||
private ActionsSortableList _enterActions; | ||
private ActionsSortableList _exitActions; | ||
|
||
private void OnEnable () { | ||
var node = target as NodeDataBase; | ||
|
||
_dialogue = serializedObject.FindProperty("dialogue"); | ||
_choices = serializedObject.FindProperty("choices"); | ||
|
||
_conditions = new ConditionSortableList(this, "conditions", node, node.conditions); | ||
if (!node.HideInspectorActions) { | ||
_enterActions = new ActionsSortableList(this, "enterActions", node, node.enterActions); | ||
_exitActions = new ActionsSortableList(this, "exitActions", node, node.exitActions); | ||
} | ||
} | ||
|
||
public override void OnInspectorGUI () { | ||
base.OnInspectorGUI(); | ||
SpellCheckText(); | ||
|
||
_conditions.Update(); | ||
_enterActions?.Update(); | ||
_exitActions?.Update(); | ||
} | ||
|
||
private void SpellCheckText () { | ||
if (_dialogue == null && _choices == null) return; | ||
if (!GUILayout.Button("Spell Check")) return; | ||
|
||
ShowValidation(target as NodeDataBase); | ||
} | ||
|
||
public static void ShowValidation (NodeDataBase target) { | ||
var serializedObject = new SerializedObject(target); | ||
var dialogue = serializedObject.FindProperty("dialogue"); | ||
var choices = serializedObject.FindProperty("choices"); | ||
|
||
SpellCheck.Instance.ClearValidation(); | ||
|
||
if (dialogue != null) { | ||
SpellCheck.Instance.AddValidation(dialogue.displayName, dialogue.stringValue); | ||
} | ||
|
||
if (choices != null) { | ||
for (var i = 0; i < choices.arraySize; i++) { | ||
var choice = choices.GetArrayElementAtIndex(i).objectReferenceValue as ChoiceData; | ||
SpellCheck.Instance.AddValidation($"Choice {i}", choice.text); | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Actions; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
public class ActionsSortableList : SortableListBase { | ||
private static TypesToMenu<ActionDataBase> _actionTypes; | ||
|
||
private readonly ScriptableObjectListPrinter _soPrinter; | ||
private readonly NestedDataCrud<ActionDataBase> _actionCrud; | ||
|
||
private static TypesToMenu<ActionDataBase> ActionTypes => | ||
_actionTypes ?? (_actionTypes = new TypesToMenu<ActionDataBase>()); | ||
|
||
public ActionsSortableList (Editor editor, string property, NodeDataBase node, List<ActionDataBase> actions) | ||
: base(editor, property) { | ||
_soPrinter = new ScriptableObjectListPrinter(_serializedProp); | ||
_actionCrud = new NestedDataCrud<ActionDataBase>(node, actions, ActionTypes); | ||
|
||
_list.drawElementCallback = _soPrinter.DrawScriptableObject; | ||
_list.elementHeightCallback = _soPrinter.GetHeight; | ||
|
||
_list.onAddDropdownCallback = _actionCrud.ShowMenu; | ||
_list.onRemoveCallback = _actionCrud.DeleteItem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Collections.Generic; | ||
using CleverCrow.Fluid.Dialogues.Conditions; | ||
using CleverCrow.Fluid.Dialogues.Nodes; | ||
using UnityEditor; | ||
|
||
namespace CleverCrow.Fluid.Dialogues.Editors.Inspectors { | ||
public class ConditionSortableList : SortableListBase { | ||
private static TypesToMenu<ConditionDataBase> _conditionTypes; | ||
|
||
private ScriptableObjectListPrinter _soPrinter; | ||
private readonly NestedDataCrud<ConditionDataBase> _conditionCrud; | ||
|
||
private static TypesToMenu<ConditionDataBase> ConditionTypes => | ||
_conditionTypes ?? (_conditionTypes = new TypesToMenu<ConditionDataBase>()); | ||
|
||
public ConditionSortableList (Editor editor, string property, NodeDataBase node, List<ConditionDataBase> conditions) | ||
: base(editor, property) { | ||
_soPrinter = new ScriptableObjectListPrinter(_serializedProp); | ||
_conditionCrud = new NestedDataCrud<ConditionDataBase>(node, conditions, ConditionTypes); | ||
|
||
_list.drawElementCallback = _soPrinter.DrawScriptableObject; | ||
_list.elementHeightCallback = _soPrinter.GetHeight; | ||
|
||
_list.onAddDropdownCallback = _conditionCrud.ShowMenu; | ||
_list.onRemoveCallback = _conditionCrud.DeleteItem; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.