From e1cf151f0cd0a79451af7bf6cdf12e9aa9819288 Mon Sep 17 00:00:00 2001 From: Justin Abbott Date: Tue, 1 Dec 2020 14:09:57 -0800 Subject: [PATCH 01/10] Once more, with feeling. --- Assets/DialogueSystem/Demo/SampleScene.unity | 34 +- .../Scripts/DialogueCondition.cs | 35 -- .../Scripts/DialogueCondition.cs.meta | 11 - .../Scripts/DialogueContainer.cs | 45 --- .../Scripts/DialogueContainer.cs.meta | 3 - .../DialogueSystem/Scripts/DialoguePlayer.cs | 171 --------- .../Scripts/DialoguePlayer.cs.meta | 3 - Assets/DialogueSystem/Scripts/Editor.meta | 3 - .../Scripts/Editor/DialogueContainerEditor.cs | 26 -- .../Editor/DialogueContainerEditor.cs.meta | 3 - .../Scripts/Editor/DialogueGraphEditor.meta | 8 - .../DialogueGraphEditor/BlackboardProvider.cs | 120 ------ .../BlackboardProvider.cs.meta | 3 - .../DialogueGraphEditor/DialogueGraph.cs | 214 ----------- .../DialogueGraphEditor/DialogueGraph.cs.meta | 3 - .../DialogueGraphDataUtility.cs | 350 ------------------ .../DialogueGraphDataUtility.cs.meta | 3 - .../DialogueGraphEditor/DialogueGraphView.cs | 198 ---------- .../DialogueGraphView.cs.meta | 11 - .../Editor/DialogueGraphEditor/Nodes.meta | 8 - .../DialogueGraphEditor/Nodes/BaseNode.cs | 100 ----- .../Nodes/BaseNode.cs.meta | 11 - .../Nodes/ConditionNode.cs | 203 ---------- .../Nodes/ConditionNode.cs.meta | 3 - .../DialogueGraphEditor/Nodes/DialogueNode.cs | 172 --------- .../Nodes/DialogueNode.cs.meta | 3 - .../Nodes/DialogueNodePort.cs | 107 ------ .../Nodes/DialogueNodePort.cs.meta | 3 - .../DialogueGraphEditor/Nodes/EntryNode.cs | 17 - .../Nodes/EntryNode.cs.meta | 3 - .../Editor/DialogueGraphEditor/Resources.meta | 3 - .../Resources/DialogueGraph.uss | 10 - .../Resources/DialogueGraph.uss.meta | 3 - .../DialogueGraphEditor/Resources/Node.uss | 55 --- .../Resources/Node.uss.meta | 3 - .../DialogueGraphEditor/Resources/Toolbar.uss | 19 - .../Resources/Toolbar.uss.meta | 3 - .../SearchWindowProvider.cs | 71 ---- .../SearchWindowProvider.cs.meta | 3 - .../DialogueSystem/Scripts/IDialoguePlayer.cs | 7 - .../Scripts/IDialoguePlayer.cs.meta | 3 - Assets/DialogueSystem/Scripts/NodeData.meta | 3 - .../Scripts/NodeData/BaseNodeData.cs | 16 - .../Scripts/NodeData/BaseNodeData.cs.meta | 3 - .../Scripts/NodeData/ConditionNodeData.cs | 13 - .../NodeData/ConditionNodeData.cs.meta | 3 - .../Scripts/NodeData/DialogueNodeData.cs | 32 -- .../Scripts/NodeData/DialogueNodeData.cs.meta | 3 - .../Scripts/NodeData/ExposedProperty.cs | 11 - .../Scripts/NodeData/ExposedProperty.cs.meta | 3 - .../Scripts/NodeData/NodeLinkData.cs | 31 -- .../Scripts/NodeData/NodeLinkData.cs.meta | 3 - .../Scripts/NodeData/NodeType.cs | 13 - .../Scripts/NodeData/NodeType.cs.meta | 3 - 54 files changed, 5 insertions(+), 2186 deletions(-) delete mode 100644 Assets/DialogueSystem/Scripts/DialogueCondition.cs delete mode 100644 Assets/DialogueSystem/Scripts/DialogueCondition.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/DialogueContainer.cs delete mode 100644 Assets/DialogueSystem/Scripts/DialogueContainer.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/DialoguePlayer.cs delete mode 100644 Assets/DialogueSystem/Scripts/DialoguePlayer.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss.meta delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs delete mode 100644 Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/IDialoguePlayer.cs delete mode 100644 Assets/DialogueSystem/Scripts/IDialoguePlayer.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs.meta delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/NodeType.cs delete mode 100644 Assets/DialogueSystem/Scripts/NodeData/NodeType.cs.meta diff --git a/Assets/DialogueSystem/Demo/SampleScene.unity b/Assets/DialogueSystem/Demo/SampleScene.unity index 3355275..6428c5a 100644 --- a/Assets/DialogueSystem/Demo/SampleScene.unity +++ b/Assets/DialogueSystem/Demo/SampleScene.unity @@ -294,20 +294,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 922203892} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 8786771133028197972} - m_MethodName: PlayDialogue - m_Mode: 2 - m_Arguments: - m_ObjectArgument: {fileID: 11400000, guid: dd801a633ca8cda42b8ae8d25e17e64a, - type: 2} - m_ObjectArgumentAssemblyTypeName: lastmilegames.DialogueSystem.DialogueContainer, - Assembly-CSharp - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] --- !u!114 &922203892 MonoBehaviour: m_ObjectHideFlags: 0 @@ -741,7 +728,7 @@ PrefabInstance: - target: {fileID: 8786771132893712695, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} propertyPath: m_AnchoredPosition.y - value: 0.000018605962 + value: -0.00008284766 objectReference: {fileID: 0} - target: {fileID: 8786771132936344443, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} @@ -751,7 +738,7 @@ PrefabInstance: - target: {fileID: 8786771132936344443, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} propertyPath: m_AnchoredPosition.y - value: -0.00009074141 + value: -0.00003786637 objectReference: {fileID: 0} - target: {fileID: 8786771132947378257, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} @@ -1023,17 +1010,6 @@ PrefabInstance: propertyPath: m_SizeDelta.x value: 0 objectReference: {fileID: 0} - m_RemovedComponents: [] + m_RemovedComponents: + - {fileID: 7560019262726077265, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} ---- !u!114 &8786771133028197972 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 7560019262726077265, guid: 4d8914cb6b33dc34e86ba2b8caea414c, - type: 3} - m_PrefabInstance: {fileID: 8786771133028197971} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 661418d3488d423caf0369b884804cd9, type: 3} - m_Name: - m_EditorClassIdentifier: diff --git a/Assets/DialogueSystem/Scripts/DialogueCondition.cs b/Assets/DialogueSystem/Scripts/DialogueCondition.cs deleted file mode 100644 index 38b7c5e..0000000 --- a/Assets/DialogueSystem/Scripts/DialogueCondition.cs +++ /dev/null @@ -1,35 +0,0 @@ -using UnityEngine; - -namespace lastmilegames.DialogueSystem -{ - /// - /// A serializable bool that con be used to branch dialogue. - /// - [CreateAssetMenu(fileName = "Condition", menuName = "Dialogue System/New Condition", order = 0)] - public class DialogueCondition : ScriptableObject - { - /// - /// The value of the condition. - /// - /// Is automatically set by OnEnable so that value can be changed in play mode without persisting to the object. - public bool Value { get; private set; } - /// - /// The initial value of the - /// - // ReSharper disable once RedundantDefaultMemberInitializer - [SerializeField] private bool initialValue = false; - - private void OnEnable() - { - Value = initialValue; - } - - /// - /// Toggle the runtime value of the condition without affecting the initial value. - /// - public void ToggleValue() - { - Value = !Value; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/DialogueCondition.cs.meta b/Assets/DialogueSystem/Scripts/DialogueCondition.cs.meta deleted file mode 100644 index 28f5335..0000000 --- a/Assets/DialogueSystem/Scripts/DialogueCondition.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 05d1c53c2c64b3a4f92f88b39401c7e6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/DialogueContainer.cs b/Assets/DialogueSystem/Scripts/DialogueContainer.cs deleted file mode 100644 index f914cfe..0000000 --- a/Assets/DialogueSystem/Scripts/DialogueContainer.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEngine; - -namespace lastmilegames.DialogueSystem -{ - /// - /// Represents a conversation dialogue. - /// - [CreateAssetMenu(fileName = "DialogueContainer", menuName = "Dialogue System/New Container", order = 0)] - public class DialogueContainer : ScriptableObject - { - /// - /// The entry node for the conversation. - /// - public BaseNodeData entryNode = new BaseNodeData - { - guid = Guid.NewGuid().ToString(), - position = new Vector2(100, 200), - type = NodeType.Entry - }; - - /// - /// A list of the links between nodes. - /// - public List nodeLinkData = new List(); - - /// - /// A list of dialogues which contain who is speaking, what they're saying, and available responses. - /// - public List dialogueNodeData = new List(); - - /// - /// A list of conditions that can alter the flow of the conversation. - /// - public List conditionNodeData = new List(); - - /// - /// A list of exposed properties that can be used to dynamically update dialogue text. - /// - public List exposedProperties = new List(); - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/DialogueContainer.cs.meta b/Assets/DialogueSystem/Scripts/DialogueContainer.cs.meta deleted file mode 100644 index 16d9913..0000000 --- a/Assets/DialogueSystem/Scripts/DialogueContainer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: a08108e497d646b08215f88b69e361f0 -timeCreated: 1582678137 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/DialoguePlayer.cs b/Assets/DialogueSystem/Scripts/DialoguePlayer.cs deleted file mode 100644 index 83f999b..0000000 --- a/Assets/DialogueSystem/Scripts/DialoguePlayer.cs +++ /dev/null @@ -1,171 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using lastmilegames.DialogueSystem.NodeData; -using TMPro; -using UnityEngine; -using UnityEngine.UI; - -namespace lastmilegames.DialogueSystem -{ - public class DialoguePlayer : MonoBehaviour, IDialoguePlayer - { - // ReSharper disable RedundantDefaultMemberInitializer - [SerializeField] private Transform dialoguePanel = default; - [SerializeField] private TMP_Text speakerNameLabel = default; - [SerializeField] private TMP_Text dialogueLabel = default; - [SerializeField] private Transform choicesContentAreaTransform = default; - [SerializeField] private Button choiceButtonPrefab = default; - - [SerializeField] private string closeConversationLabelText = "[End Conversation]"; - // ReSharper restore RedundantDefaultMemberInitializer - - private DialogueContainer dialogueContainer; - - private void Awake() - { - dialoguePanel.gameObject.SetActive(false); - } - - public void PlayDialogue(DialogueContainer container) - { - if (container == null) - { - Debug.LogError("No dialogue provided by trigger. Aborting conversation."); - return; - } - - dialogueContainer = container; - - BaseNodeData startingNode = GetTargetNode(dialogueContainer.nodeLinkData.Find(data => - data.baseNodeGuid == dialogueContainer.entryNode.guid)); - - PlayNode(startingNode); - dialoguePanel.gameObject.SetActive(true); - } - - private BaseNodeData GetTargetNode(NodeLinkData nodeLink) - { - switch (nodeLink.targetNodeType) - { - case NodeType.NotSet: - return null; - case NodeType.Entry: - return null; - case NodeType.Condition: - return dialogueContainer.conditionNodeData.Find( - node => node.guid == nodeLink.targetNodeGuid); - case NodeType.Dialogue: - return dialogueContainer.dialogueNodeData.Find(node => - node.guid == nodeLink.targetNodeGuid); - default: - throw new ArgumentOutOfRangeException(); - } - } - - private void PlayNode(BaseNodeData node) - { - switch (node.type) - { - case NodeType.NotSet: - break; - case NodeType.Entry: - break; - case NodeType.Condition: - EvaluateConditionNode(node as ConditionNodeData); - break; - case NodeType.Dialogue: - DisplayDialogueNode(node as DialogueNodeData); - break; - default: - throw new ArgumentOutOfRangeException(); - } - } - - private void DisplayDialogueNode(DialogueNodeData node) - { - speakerNameLabel.text = ProcessExposedProperties(node.speakerName); - dialogueLabel.text = ProcessExposedProperties(node.dialogueText); - - ClearChoiceButtons(); - - if (node.responses.Count == 0) - { - Button endButton = Instantiate(choiceButtonPrefab, choicesContentAreaTransform); - endButton.GetComponentInChildren().text = closeConversationLabelText; - endButton.onClick.AddListener(() => dialoguePanel.gameObject.SetActive(false)); - } - else - { - GenerateChoiceButtons(node); - } - - } - - private string ProcessExposedProperties(string nodeDialogueText) - { - string processedText = nodeDialogueText; - - foreach (ExposedProperty property in dialogueContainer.exposedProperties) - { - processedText = processedText.Replace(property.propertyName, property.propertyValue); - } - - return processedText; - } - - private void ClearChoiceButtons() - { - foreach (Transform child in choicesContentAreaTransform) - { - Destroy(child.gameObject); - } - } - - private void GenerateChoiceButtons(DialogueNodeData node) - { - List nodeLinks = GetLinks(node.guid); - - if (nodeLinks.Count != node.responses.Count) - { - Debug.LogError( - $"Dialogue Node {node.guid} has mismatched number of links and responses. Aborting conversation."); - dialoguePanel.gameObject.SetActive(false); - return; - } - - for (var i = 0; i < node.responses.Count; i++) - { - NodeLinkData link = nodeLinks[i]; - string currentResponse = node.responses[i]; - DialogueCondition conditionToToggle = node.conditionsToToggle[i]; - Button button = Instantiate(choiceButtonPrefab, choicesContentAreaTransform); - button.GetComponentInChildren().text = currentResponse; - button.onClick.AddListener(() => OnButtonClick(link, conditionToToggle)); - } - } - - private void OnButtonClick(NodeLinkData linkData, DialogueCondition conditionToToggle) - { - if (conditionToToggle != null) conditionToToggle.ToggleValue(); - - BaseNodeData nextNode = GetTargetNode(linkData); - - PlayNode(nextNode); - } - - private void EvaluateConditionNode(ConditionNodeData node) - { - List nextNodes = GetLinks(node.guid); - - BaseNodeData nextNode = GetTargetNode(node.conditionToTest.Value ? nextNodes[0] : nextNodes[1]); - - PlayNode(nextNode); - } - - private List GetLinks(string guid) - { - return dialogueContainer.nodeLinkData.FindAll(link => link.baseNodeGuid == guid); - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/DialoguePlayer.cs.meta b/Assets/DialogueSystem/Scripts/DialoguePlayer.cs.meta deleted file mode 100644 index e83f064..0000000 --- a/Assets/DialogueSystem/Scripts/DialoguePlayer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 661418d3488d423caf0369b884804cd9 -timeCreated: 1604013598 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor.meta b/Assets/DialogueSystem/Scripts/Editor.meta deleted file mode 100644 index a4afed4..0000000 --- a/Assets/DialogueSystem/Scripts/Editor.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 020840a2c6564bb7b3cd9e7fd18dc9ae -timeCreated: 1604008823 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs deleted file mode 100644 index 3b9d0da..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs +++ /dev/null @@ -1,26 +0,0 @@ -using lastmilegames.DialogueSystem.DialogueGraphEditor; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEngine; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem -{ - [CustomEditor(typeof(DialogueContainer))] - public class DialogueContainerEditor : Editor - { - public override void OnInspectorGUI() - { - DialogueContainer dialogueContainer = target as DialogueContainer; - EditorGUILayout.BeginVertical(); - - if (GUILayout.Button("Open Visual Editor")) - { - DialogueGraph.ShowWindow(dialogueContainer); - } - - DrawDefaultInspector(); - EditorGUILayout.EndVertical(); - } - } -} diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs.meta deleted file mode 100644 index 4301214..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueContainerEditor.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8ec86cfebab04a3aaff7056f9039dbdd -timeCreated: 1584910605 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor.meta deleted file mode 100644 index 03cfd6e..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: c05fd86c27504e46b184e91f7f07d7ca -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs deleted file mode 100644 index dfb40a1..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using System.Linq; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Experimental.GraphView; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor -{ - public class BlackboardProvider - { - private readonly DialogueGraphView graphView; - - public BlackboardProvider(DialogueGraphView graphView) - { - this.graphView = graphView; - - Blackboard = new Blackboard - { - scrollable = true, - addItemRequested = AddItemRequested, - editTextRequested = EditTextRequested - }; - } - - public Blackboard Blackboard { get; private set; } - - public void RefreshProperties() - { - Blackboard.contentContainer.Clear(); - foreach (ExposedProperty property in graphView.exposedProperties) - { - Blackboard.Add(GenerateBlackboardField(property)); - } - } - - private void EditTextRequested(Blackboard blackboard, VisualElement element, string value) - { - string currentName = ((BlackboardField) element).text; - string nextName = ValidateName(value); - - if (graphView.exposedProperties.Any(property => property.propertyName == nextName)) - { - EditorUtility.DisplayDialog( - "Error", - $"A property with the name \"{nextName}\" already exists.", - "OK" - ); - return; - } - - int propertyIndex = graphView.exposedProperties.FindIndex(x => x.propertyName == currentName); - graphView.exposedProperties[propertyIndex].propertyName = nextName; - ((BlackboardField) element).text = nextName; - } - - private void AddItemRequested(Blackboard blackboard) - { - var property = new ExposedProperty(); - property.propertyName = ValidateName(property.propertyName); - graphView.exposedProperties.Add(property); - - blackboard.Add(GenerateBlackboardField(property)); - } - - private VisualElement GenerateBlackboardField(ExposedProperty property) - { - var container = new VisualElement(); - var blackboardField = new BlackboardField - { - text = property.propertyName, - typeText = "String", - }; - container.Add(blackboardField); - - var propertyValueTextField = new TextField("Value:"); - propertyValueTextField.Q(className: "unity-label").style.minWidth = 50; - propertyValueTextField.value = property.propertyValue; - propertyValueTextField.RegisterValueChangedCallback(evt => - { - int changingPropertyIndex = graphView.exposedProperties.FindIndex( - exposedProperty => exposedProperty.propertyName == property.propertyName); - graphView.exposedProperties[changingPropertyIndex].propertyValue = evt.newValue; - }); - - var blackboardValueRow = new BlackboardRow(propertyValueTextField, propertyValueTextField); - container.Add(blackboardValueRow); - - return container; - } - - private string ValidateName(string name) - { - if (string.IsNullOrWhiteSpace(name)) return null; - - var newName = ""; - string[] nameArray = name.Split(new[] {"@@"}, StringSplitOptions.None); - - foreach (string s in nameArray) - { - if (s.Trim() == "@@") continue; - - newName += s.Trim().Normalize().ToUpper(); - } - - var nextName = $@"@@{newName}@@"; - - int matchCount = graphView.exposedProperties.FindAll(property => property.propertyName == nextName).Count; - - if (matchCount > 0) - { - return $@"@@{newName}{matchCount}@@"; - } - else - { - return nextName; - } - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs.meta deleted file mode 100644 index b3778c8..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/BlackboardProvider.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f584819ee1804ab6a93f96572240bd1d -timeCreated: 1604443943 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs deleted file mode 100644 index 3edd3cf..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System.Linq; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEditor.Experimental.GraphView; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor -{ - /// - /// Represents the parent EditorWindow for the dialogue visual editor. - /// - public class DialogueGraph : EditorWindow - { - /// - /// The data utility for saving/loading graphs. - /// - private static DialogueGraphDataUtility dialogueGraphDataUtility; - - private static DialogueContainer dialogueContainer; - - /// - /// The GraphView instance. - /// - private DialogueGraphView _graphView; - - /// - /// The GraphView.MiniMap instance. - /// - private MiniMap _miniMap; - - private BlackboardProvider blackboardProvider; - - /// - /// Mini map visibility. - /// - private bool _miniMapEnabled; - - /// - /// Opens the DialogueGraph editor window. - /// - public static void ShowWindow(DialogueContainer container) - { - dialogueContainer = container; - - var window = GetWindow(); - window.titleContent = new GUIContent(dialogueContainer.name); - window.Show(); - } - - [MenuItem("Dialogue Editor/Open Editor Window")] - [MenuItem("Assets/DialogueEditor/Open Editor Window")] - public static bool ShowEditor() - { - dialogueContainer = Selection.activeObject as DialogueContainer; - - if (dialogueContainer) - { - ShowWindow(dialogueContainer); - return true; - } - - return false; - } - - [MenuItem("Dialogue Editor/Open Editor Window", true)] - [MenuItem("Assets/DialogueEditor/Open Editor Window", true)] - public static bool ValidateValidObjectSelected() - { - return Selection.activeObject is DialogueContainer; - } - - [MenuItem("Dialogue Editor/New Dialogue Container")] - public static void NewDialogue() - { - var container = CreateInstance(); - string path = EditorUtility.SaveFilePanel( - "New Dialogue Container", - "Assets/", - "New Dialogue Container.asset", - "asset" - ); - - if (path.Length == 0) return; - - if (dialogueGraphDataUtility == null) - { - dialogueGraphDataUtility = new DialogueGraphDataUtility(); - } - - dialogueGraphDataUtility.SaveGraph(path, container); - - bool openDialogueEditor = EditorUtility.DisplayDialog( - "Open Dialogue Editor Now?", - "Would you like to open the Dialogue Editor and edit this conversation now?", - "Yes", - "No" - ); - - if (openDialogueEditor) - { - ShowWindow(container); - } - } - - [OnOpenAsset] - public static bool OnOpenAsset(int instanceId, int line) - { - string assetPath = AssetDatabase.GetAssetPath(instanceId); - var container = AssetDatabase.LoadAssetAtPath(assetPath); - - if (container) - { - ShowWindow(container); - return true; - } - - return false; - } - - private void OnEnable() - { - InitializeGraphView(); - } - - private void OnGUI() - { - // Enable mini map if visible. - if (_miniMap != null) _miniMap.visible = _miniMapEnabled; - } - - /// - /// Prepares the window elements. - /// - private void InitializeGraphView() - { - // Set the root elements flex direction - rootVisualElement.style.flexDirection = FlexDirection.Column; - - // Create the window elements - rootVisualElement.Add(GenerateToolbar()); - - _graphView = GenerateGraphView(); - rootVisualElement.Add(_graphView); - - _miniMap = GenerateMiniMap(); - _graphView.Add(_miniMap); - - blackboardProvider = new BlackboardProvider(_graphView); - _graphView.Add(blackboardProvider.Blackboard); - - // Get the data utility so we can save and load. - dialogueGraphDataUtility = new DialogueGraphDataUtility(_graphView); - - if (dialogueContainer != null) dialogueGraphDataUtility.LoadGraph(dialogueContainer, blackboardProvider); - } - - /// - /// Creates and populates a UIElements.Toolbar - /// - /// Returns the UIElements.Toolbar with controls. - private Toolbar GenerateToolbar() - { - // Create the toolbar and load the stylesheet. - Toolbar toolbar = new Toolbar(); - toolbar.styleSheets.Add(Resources.Load("Toolbar")); - - // Button to save the asset - toolbar.Add(new ToolbarButton(() => { dialogueGraphDataUtility.SaveGraph(dialogueContainer); }) - { - text = "Save Asset" - }); - - // Flexible spacer. - toolbar.Add(new ToolbarSpacer() {flex = true}); - - // Button to toggle the mini map visibility. - ToolbarToggle toggleMiniMap = new ToolbarToggle {text = "Toggle MiniMap"}; - toggleMiniMap.RegisterValueChangedCallback(evt => { _miniMapEnabled = evt.newValue; }); - toolbar.Add(toggleMiniMap); - - return toolbar; - } - - /// - /// Creates the default instance of DialogueGraphView. - /// - /// Returns a default DialogueGraphView. - private DialogueGraphView GenerateGraphView() - { - DialogueGraphView graphView = new DialogueGraphView(this) - { - name = "Dialogue Graph" - }; - graphView.style.flexGrow = 1; - - return graphView; - } - - /// - /// Creates a default mini map. - /// - /// Returns a default mini map to add to the DialogueGraphView. - private MiniMap GenerateMiniMap() - { - var miniMap = new MiniMap {visible = _miniMapEnabled}; - Vector2 coords = _graphView.contentViewContainer.WorldToLocal(new Vector2(this.maxSize.x - 10, 30)); - miniMap.SetPosition(new Rect(coords.x, coords.y, 200, 140)); - return miniMap; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs.meta deleted file mode 100644 index f646a68..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraph.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cedf0977d78b4b8d8cb0f6ed287ce566 -timeCreated: 1582072504 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs deleted file mode 100644 index 0af132d..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs +++ /dev/null @@ -1,350 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; -using Object = UnityEngine.Object; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor -{ - /// - /// A utility class for saving and loading DialogueGraphs - /// - public class DialogueGraphDataUtility - { - private readonly DialogueGraphView targetGraphView; - private IEnumerable Edges => targetGraphView == null ? new List() : targetGraphView.edges.ToList(); - private List dialogueNodes; - private List conditionNodes; - private List exposedProperties; - private EntryNode entryNode; - - public DialogueGraphDataUtility() - { - // Default constructor to just save container. Doesn't target a graph; - targetGraphView = null; - } - - public DialogueGraphDataUtility(DialogueGraphView targetGraphView) - { - this.targetGraphView = targetGraphView; - } - - /// - /// Saves the currently loaded graph to a DialogueContainer asset file. - /// - /// The existing DialogueContainer to save to. - public void SaveGraph(DialogueContainer container) - { - CacheGraphData(); - SaveNodes(container); - SaveNodeLinks(container); - - AssetDatabase.SaveAssets(); - } - - /// - /// Creates a new DialogueContainer asset at the provided location and then saves the current graph to the asset. - /// - /// The path for the DialogueContainer. This can be relative to the project root or absolute. - /// The DialogueContainer to save to the asset. - public void SaveGraph(string path, DialogueContainer container) - { - WriteAssetFile(container, path); - - SaveGraph(container); - } - - public void LoadGraph(DialogueContainer container, BlackboardProvider blackboardProvider) - { - ClearGraph(container); - CreateNodes(container); - ConnectNodes(container); - LoadExposedProperties(container, blackboardProvider); - } - - private void ClearGraph(DialogueContainer container) - { - foreach (Node node in targetGraphView.nodes.ToList()) - { - // If the entry node, reset the GUID and continue. - if (node is EntryNode entry) - { - entry.Guid = container.entryNode.guid; - entry.SetPosition(new Rect(container.entryNode.position, BaseNode.DefaultNodeSize)); - } - else // disconnect the node, then remove the node. - { - Edges.Where(edge => edge.input.node == node).ToList() - .ForEach(edge => targetGraphView.RemoveElement(edge)); - - targetGraphView.RemoveElement(node); - } - } - } - - /// - /// Cache the nodes by looping though them and sorting them based on type - /// - private void CacheGraphData() - { - entryNode = new EntryNode(); - dialogueNodes = new List(); - conditionNodes = new List(); - exposedProperties = new List(); - - if (targetGraphView == null) return; - foreach (Node node in targetGraphView.nodes.ToList()) - { - Type nodeType = node.GetType(); - - // Sort the nodes into their respective objects. - if (nodeType == typeof(EntryNode)) - { - entryNode = node as EntryNode; - } - else if (nodeType == typeof(DialogueNode)) - { - dialogueNodes.Add(node as DialogueNode); - } - else if (nodeType == typeof(ConditionNode)) - { - conditionNodes.Add(node as ConditionNode); - } - } - - exposedProperties = targetGraphView.exposedProperties; - } - - private void SaveNodes(DialogueContainer container) - { - CreateEntryNodeData(container); - CreateDialogueNodeData(container); - CreateConditionNodeData(container); - } - - private void CreateEntryNodeData(DialogueContainer container) - { - container.entryNode = new BaseNodeData - { - guid = entryNode.Guid, - position = entryNode.GetPosition().position, - type = entryNode.type - }; - } - - private void CreateDialogueNodeData(DialogueContainer container) - { - container.dialogueNodeData.Clear(); - // Create DialogueNodeData - foreach (DialogueNode dialogueNode in dialogueNodes) - { - List responses = new List(); - List conditionsToToggle = new List(); - - foreach (DialogueNodePort dialogueNodePort in dialogueNode.DialogueNodePorts) - { - responses.Add(dialogueNodePort.ResponseText); - conditionsToToggle.Add(dialogueNodePort.ConditionToToggle); - } - - container.dialogueNodeData.Add(new DialogueNodeData - { - guid = dialogueNode.Guid, - type = dialogueNode.type, - position = dialogueNode.GetPosition().position, - dialogueText = dialogueNode.DialogueText, - speakerName = dialogueNode.SpeakerName, - responses = responses, - conditionsToToggle = conditionsToToggle - }); - } - } - - private void CreateConditionNodeData(DialogueContainer container) - { - container.conditionNodeData.Clear(); - foreach (ConditionNode conditionNode in conditionNodes) - { - container.conditionNodeData.Add(new ConditionNodeData - { - guid = conditionNode.Guid, - position = conditionNode.GetPosition().position, - conditionToTest = conditionNode.ConditionToTest, - type = conditionNode.type - }); - } - } - - private void SaveNodeLinks(DialogueContainer container) - { - if (!Edges.Any()) return; // Skip if there are no connections between nodes. - - container.nodeLinkData.Clear(); - - // Find all connected nodes - Edge[] connectedPorts = Edges.Where(port => port.input.node != null).ToArray(); - - // Iterate through each connection - foreach (Edge port in connectedPorts) - { - var outputNode = (BaseNode) port.output.node; - var inputNode = (BaseNode) port.input.node; - - // Add data to list - container.nodeLinkData.Add(new NodeLinkData - { - baseNodeGuid = outputNode.Guid, - baseNodeType = outputNode.type, - targetNodeGuid = inputNode.Guid, - targetNodeType = inputNode.type - }); - - Debug.Break(); - } - } - - /// - /// Write the asset file to the top level resources folder. - /// - /// The DialogueContainer to write to the asset file. - /// The name to give the asset file. - private static void WriteAssetFile(Object container, string path = "Assets/Resources") - { - string[] pathArray = path.Split('/'); - string assetName = pathArray[pathArray.Length - 1]; - var inAssetDirectory = false; - var assetPath = ""; - - // Build the absolute path relative to the project root. - for (var i = 0; i < pathArray.Length - 1; i++) - { - if (pathArray[i] == "Assets") - { - inAssetDirectory = true; - continue; - } - - if (!inAssetDirectory) continue; - assetPath += $"/{pathArray[i]}"; - } - - bool validFolder = AssetDatabase.IsValidFolder("Assets" + assetPath); - - if (!validFolder) - { - string[] assetPathArray = assetPath.Split('/'); - for (var i = 1; i < assetPathArray.Length; i++) - { - string parent = i == 1 ? "Assets/" : assetPathArray[i - 1]; - AssetDatabase.CreateFolder(parent, assetPathArray[i]); - } - } - - AssetDatabase.CreateAsset(container, $"Assets/{assetPath}/{assetName}"); - AssetDatabase.SaveAssets(); - } - - - private void CreateNodes(DialogueContainer container) - { - foreach (DialogueNodeData nodeData in container.dialogueNodeData) - { - DialogueNode tempNode = targetGraphView.CreateDialogueNode(nodeData); - tempNode.Guid = nodeData.guid; - tempNode.SetPosition(new Rect(nodeData.position, BaseNode.DefaultNodeSize)); - targetGraphView.AddElement(tempNode); - } - - foreach (ConditionNodeData nodeData in container.conditionNodeData) - { - ConditionNode tempNode = targetGraphView.CreateConditionNode(nodeData); - tempNode.Guid = nodeData.guid; - tempNode.SetPosition(new Rect(nodeData.position, BaseNode.DefaultNodeSize)); - targetGraphView.AddElement(tempNode); - } - } - - private void ConnectNodes(DialogueContainer container) - { - if (!container.nodeLinkData.Any()) return; - - List nodes = targetGraphView.nodes.ToList().Cast().ToList(); - foreach (BaseNode node in nodes) - { - switch (node) - { - // Connect entry node to targets - case EntryNode entry: - { - string targetNodeGuid = container.nodeLinkData.First(data => - data.baseNodeGuid == entry.Guid).targetNodeGuid; - BaseNode targetNode = nodes.First(x => x.Guid == targetNodeGuid); - LinkNodes( - (Port) entry.outputContainer[0], - (Port) targetNode.inputContainer[0] - ); - break; - } - // Connect dialogue nodes to targets - case DialogueNode dialogue: - { - List dialogueNodeConnections = - container.nodeLinkData.Where(data => data.baseNodeGuid == node.Guid).ToList(); - for (var i = 0; i < dialogueNodeConnections.Count; i++) - { - string targetNodeGuid = dialogueNodeConnections[i].targetNodeGuid; - BaseNode targetNode = nodes.First(n => n.Guid == targetNodeGuid); - LinkNodes( - dialogue.DialogueNodePorts[i].Port, - (Port) targetNode.inputContainer[0] - ); - } - - break; - } - // Connect the rest of the nodes to their targets - // Works for anything that doesn't add a special way of handling ports. - default: - { - List connections = - container.nodeLinkData.Where(data => data.baseNodeGuid == node.Guid).ToList(); - for (var i = 0; i < connections.Count; i++) - { - string targetNodeGuid = connections[i].targetNodeGuid; - BaseNode targetNode = nodes.First(n => n.Guid == targetNodeGuid); - LinkNodes(node.outputContainer[i].Q(), (Port) targetNode.inputContainer[0]); - } - - break; - } - } - } - } - - private void LinkNodes(Port output, Port input) - { - var tempEdge = new Edge - { - output = output, - input = input - }; - - tempEdge.input.Connect(tempEdge); - tempEdge.output.Connect(tempEdge); - - targetGraphView.Add(tempEdge); - } - - private void LoadExposedProperties(DialogueContainer container, BlackboardProvider blackboardProvider) - { - targetGraphView.exposedProperties.Clear(); - targetGraphView.exposedProperties = container.exposedProperties; - blackboardProvider.RefreshProperties(); - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs.meta deleted file mode 100644 index e5964f4..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphDataUtility.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: efae80c882ff4c3894453883d2c17582 -timeCreated: 1582742988 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs deleted file mode 100644 index e0316f1..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs +++ /dev/null @@ -1,198 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor -{ - /// - /// Represents the main GraphView for Dialogues - /// - public class DialogueGraphView : GraphView - { - public List exposedProperties; - public Blackboard blackboard; - - private SearchWindowProvider _searchWindow; - - /// - /// Sets the initial settings for the DialogueGraphView instance. - /// - public DialogueGraphView(EditorWindow editorWindow) - { - if (exposedProperties == null) exposedProperties = new List(); - - // Load the stylesheet. - styleSheets.Add(Resources.Load("DialogueGraph")); - - // Setup features for zooming, dragging, and selecting. - SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); - this.AddManipulator(new ContentDragger()); - this.AddManipulator(new SelectionDragger()); - this.AddManipulator(new RectangleSelector()); - - // Draw the grid. - GridBackground grid = new GridBackground(); - Insert(0, grid); - grid.StretchToParentSize(); - - // Create the start node. - AddElement(GenerateEntryPointNode()); - - AddSearchWindow(editorWindow); - } - - private void AddSearchWindow(EditorWindow editorWindow) - { - _searchWindow = ScriptableObject.CreateInstance(); - _searchWindow.Init(editorWindow, this); - nodeCreationRequest = context => - SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), _searchWindow); - } - - /// - /// Get all ports compatible with a given port. - /// - /// Start port to validate against. - /// Node adapter - /// List of compatible ports. - public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) - { - List compatiblePorts = new List(); - ports.ForEach(port => - { - if (startPort != port // The target port is not itself - && startPort.node != port.node // The target port is not on the same node. - && startPort.direction != port.direction // The target port is not the same direction. - ) - { - compatiblePorts.Add(port); - } - }); - - return compatiblePorts; - } - - /// - /// Creates a basic node to serve as an entry point. - /// - /// Returns a node with a single output port. - private static EntryNode GenerateEntryPointNode() - { - EntryNode node = new EntryNode {title = "Start"}; - - // Remove the entry port - node.inputContainer.RemoveAt(0); - - // Create the output port. - node.GeneratePort(node, "Next", Direction.Output); - - // Prevent the deletion of the node. - node.capabilities &= ~Capabilities.Deletable; - - // Set the default position of the node. - node.SetPosition(new Rect(100, 200, 100, 150)); - - return node; - } - - /// - /// Creates a node of the given type. - /// - /// The type of node to create. - /// The position to create the node at. - /// Thrown when the provided nodeType is invalid. - public void CreateNode(NodeType nodeType, Vector2 position) - { - switch (nodeType) - { - case NodeType.Condition: - AddElement(CreateConditionNode(position)); - break; - case NodeType.Dialogue: - AddElement(CreateDialogueNode(position)); - break; - default: - throw new ArgumentOutOfRangeException(nameof(nodeType), nodeType, null); - } - } - - /// - /// Creates a new default ConditionNode at the given location. - /// - /// - /// A condition node with default values. - private ConditionNode CreateConditionNode(Vector2 position) - { - ConditionNode node = new ConditionNode {title = "Condition"}; - node.SetPosition(new Rect(position, BaseNode.DefaultNodeSize)); - return node; - } - - /// - /// Creates a new Condition node with given values. - /// - /// The values to initialize the node with. - /// A condition node with the initialized values. - public ConditionNode CreateConditionNode(ConditionNodeData nodeData) - { - return new ConditionNode(nodeData); - } - - /// - /// Creates a new DialogueNode with default values at a given position - /// - /// The position to create the node at. - /// A new dialogue node with default values. - private DialogueNode CreateDialogueNode(Vector2 position) - { - DialogueNode node = new DialogueNode(OnClickRemoveOutputPort); - node.SetPosition(new Rect(position, BaseNode.DefaultNodeSize)); - return node; - } - - /// - /// Creates a new DialogueNode with given values. - /// - /// The values to initialize the node with. - /// A dialogue node initialized with the given values. - public DialogueNode CreateDialogueNode(DialogueNodeData nodeData) - { - return new DialogueNode(OnClickRemoveOutputPort, nodeData); - } - - - private void OnClickRemoveOutputPort(Node node, Port port) - { - // Find all the edges (connections) this port makes to others. - IEnumerable targetEdges = edges.ToList() - .Where(x => x.output == port && x.output.node == port.node) - .ToList(); - - // If any edges were found, remove them. - if (targetEdges.Any()) - { - Edge edge = targetEdges.First(); - edge.input.Disconnect(edge); - RemoveElement(targetEdges.First()); - } - - // If the node is a dialogueNode, we need to remove the DialogueNodePort element. - if (node is DialogueNode dialogueNode) - { - List choicePorts = dialogueNode.DialogueNodePorts; - choicePorts.Remove(choicePorts.Find(x => x.Port == port)); - } - - // Finally, remove the port and refresh the UI. - node.outputContainer.Remove(port); - node.RefreshExpandedState(); - node.RefreshPorts(); - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs.meta deleted file mode 100644 index 5c23828..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/DialogueGraphView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 3e41570acd26438eb5e94c7117048dda -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes.meta deleted file mode 100644 index ba83f90..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: b083094664f84e65805d8cd8f8d1f0c7 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs deleted file mode 100644 index a594a0c..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes -{ - /// - /// The base class all DialogueGraphEditor nodes inherit from. - /// - public abstract class BaseNode : Node - { - /// - /// The default minimum size of a node. - /// Nodes will expand based on USS rules. - /// - public static readonly Vector2 DefaultNodeSize = new Vector2(150, 200); - - /// - /// The node's unique identifier. - /// - public string Guid { get; set; } - - /// - /// Represents the type of node. - /// - public NodeType type; - - /// - /// The action delegate to call when the remove port button is clicked. - /// - protected readonly Action onClickRemovePort; - - /// - /// Creates a default node with an input port. - /// - protected BaseNode() - { - Guid = System.Guid.NewGuid().ToString(); - type = NodeType.NotSet; - - GeneratePort(this, "Input", Direction.Input, Port.Capacity.Multi); - inputContainer.Q().portColor = Color.cyan; - onClickRemovePort = (node, port) => - { - Debug.LogWarningFormat( - "No remove port action set on node {0} port {1}", - port.parent.IndexOf(port), - Guid - ); - }; - } - - /// - /// Generates a node with an onClickRemovePort event. - /// - /// Event that fires when remove port button is clicked. - protected BaseNode(Action onClickRemovePort) - { - Guid = System.Guid.NewGuid().ToString(); - this.onClickRemovePort = onClickRemovePort; - - // Create input port - GeneratePort(this, "Input", Direction.Input, Port.Capacity.Multi); - inputContainer.Q().portColor = Color.cyan; - } - - /// - /// Generates a new standard GraphView.Port - /// - /// Node to add port to. - /// Name of the port. - /// Whether the port is an input or output port. - /// Whether the port can only accept one connection or multiple. - /// The value type of the port. - /// Return the generated port, - /// Thrown when an invalid direction is provided. - public Port GeneratePort(Node node, string portName, Direction portDirection, Port.Capacity capacity - = Port.Capacity.Single, Type type = null) - { - Port port = node.InstantiatePort(Orientation.Horizontal, portDirection, capacity, type); - port.portName = portName; - - switch (portDirection) - { - case Direction.Input: - node.inputContainer.Add(port); - break; - case Direction.Output: - node.outputContainer.Add(port); - break; - default: - throw new ArgumentOutOfRangeException(nameof(portDirection), portDirection, null); - } - - return port; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs.meta deleted file mode 100644 index a01926a..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/BaseNode.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f3a83de00de477dac54fffe0f3c08d6 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs deleted file mode 100644 index ad987a7..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs +++ /dev/null @@ -1,203 +0,0 @@ -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Experimental.GraphView; -using UnityEditor.UIElements; -using UnityEngine; -using UnityEngine.UIElements; -using UnityEngine.Windows; -using static UnityEngine.ScriptableObject; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes -{ - /// - /// Represents a conditional branch in the dialogue. - /// - public class ConditionNode : BaseNode - { - /// - /// The UIElements.TextField for new condition names. - /// - private TextField _conditionNameTextField; - - /// - /// The UIElements.ObjectField that selects the ConditionToTest. - /// - private ObjectField _conditionObjectField; - - /// - /// A UIElements.Toggle that binds and controls the initialValue of the _conditionObjectField's DialogueCondition. - /// - private Toggle _conditionObjectToggle; - - /// - /// The UIElements.Foldout that contains all the controls. - /// - private Foldout _contentFoldout; - - /// - /// The UIElements.Button for creating a new DialogueCondition asset. - /// - private Button _createConditionAssetButton; - - /// - /// The DialogueCondition to test against and determine the next DialogueNode. - /// - public DialogueCondition ConditionToTest; - - /// - /// Generates a new, default ConditionNode - /// - public ConditionNode() - { - type = NodeType.Condition; - - styleSheets.Add(Resources.Load("Node")); - - GenerateOutputPorts(); - BuildNodeControls(); - UpdateNodeFields(); - } - - /// - /// Generates a new ConditionNode with existing data. - /// - /// - public ConditionNode(ConditionNodeData nodeData) - { - Guid = nodeData.guid; - type = NodeType.Condition; - ConditionToTest = nodeData.conditionToTest; - - styleSheets.Add(Resources.Load("Node")); - - GenerateOutputPorts(); - BuildNodeControls(); - UpdateNodeFields(); - } - - /// - /// Creates the true/false ports that branch the dialogue. - /// - private void GenerateOutputPorts() - { - Port ifTruePort = GeneratePort(this, "If True", Direction.Output); - ifTruePort.name = "ifTruePort"; - ifTruePort.portColor = Color.green; - - Port ifFalsePort = GeneratePort(this, "If False", Direction.Output); - ifFalsePort.name = "ifFalsePort"; - ifFalsePort.portColor = Color.red; - } - - /// - /// Builds the controls. - /// - private void BuildNodeControls() - { - // Create the containing foldout. - _contentFoldout = new Foldout {text = "Condition Properties", name = "condition-properties-foldout"}; - contentContainer.Add(_contentFoldout); - - // Create the UIElements.Object field to select the DialogueCondition to test against. - _conditionObjectField = new ObjectField("Condition Object") - {objectType = typeof(DialogueCondition), allowSceneObjects = false, value = ConditionToTest}; - - // Create the UIElements.Toggle that controls ConditionToTest.initialValue - _conditionObjectToggle = new Toggle("Initial Value") {bindingPath = "initialValue"}; - _conditionObjectField.RegisterValueChangedCallback(evt => - { - ConditionToTest = evt.newValue as DialogueCondition; - _conditionObjectToggle.Unbind(); - - if (ConditionToTest != null) - { - SerializedObject so = new SerializedObject(ConditionToTest); - _conditionObjectToggle.Bind(so); - } - - UpdateNodeFields(); - }); - - // Create the UIElements.TextField that names a new DialogueCondition asset. - _conditionNameTextField = new TextField - { - name = "conditionNameTextField", - value = "New Condition" - }; - - // Create the UIElements.Button that will create a new DialogueCondition asset with the name in _conditionNameTextField - _createConditionAssetButton = new Button(() => CreateConditionAsset(_conditionNameTextField.value)) - {text = "New Condition"}; - } - - /// - /// Updates the form state based on a selected ConditionToTest. - /// - private void UpdateNodeFields() - { - VisualElement contentFoldoutContentContainer = _contentFoldout.contentContainer; - - // Update the title - title = ConditionToTest == null ? "Condition" : ConditionToTest.name; - - // Remove all children from the foldout in preparation for new state. - for (int i = contentFoldoutContentContainer.childCount - 1; i >= 0; i--) - { - contentFoldoutContentContainer.RemoveAt(i); - } - - // Add the object field - contentFoldoutContentContainer.Add(_conditionObjectField); - - // If there is no condition object set... - if (ConditionToTest == null) - { - // ... add the fields to create one, or... - contentFoldoutContentContainer.Add(_conditionNameTextField); - contentFoldoutContentContainer.Add(_createConditionAssetButton); - } - else - { - // ...add the field to toggle the condition's initial value. - contentFoldoutContentContainer.Add(_conditionObjectToggle); - } - - // Refresh the node. - RefreshPorts(); - RefreshExpandedState(); - } - - /// - /// Creates a new DialogueCondition in the Assets folder. - /// - /// The file name for the new asset. - private void CreateConditionAsset(string assetName) - { - string assetPath = $"Assets/{assetName}.asset"; - bool writeFile = true; - - // Check if the file already exists. - if (File.Exists(assetPath)) - { - writeFile = EditorUtility.DisplayDialog( - "Existing File Found", - "A file with the same name already exists.Overwrite?", - "Overwrite", - "Cancel" - ); - } - - // If it isn't okay to write the file, exit early. - if (!writeFile) return; - - // Create the DialogueCondition asset. - DialogueCondition condition = CreateInstance(); - // Save the asset file. - AssetDatabase.CreateAsset(condition, assetPath); - - // Reset the text field and select the new DialogueCondition. - _conditionNameTextField.value = "New Condition"; - _conditionObjectField.value = condition; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs.meta deleted file mode 100644 index feedb56..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/ConditionNode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: aa28bbe0c2fd469eb1f64664a1fe274d -timeCreated: 1582158037 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs deleted file mode 100644 index 5afd16b..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs +++ /dev/null @@ -1,172 +0,0 @@ -using System; -using System.Collections.Generic; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; - -/* - * TODO: Note for building UI - * If a DialogueNode has no ports OR if the port has no edges, display option to end conversation. - */ -namespace lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes -{ - /// - /// Represents a DialogueNode based off BaseNode. - /// - public class DialogueNode : BaseNode - { - /// - /// The text to display in the dialogue UI - /// - public string DialogueText { get; private set; } - - /// - /// The name of the speaker to display in the dialogue UI - /// - public string SpeakerName { get; private set; } - - /// - /// The DialogueNodePorts that represent possible responses. - /// - public List DialogueNodePorts { get; } = new List(); - - /// - /// Generates a new, default DialogueNode. - /// - /// An action delegate called when the remove port button is clicked. - public DialogueNode(Action onClickRemovePort) : base(onClickRemovePort) - { - type = NodeType.Dialogue; - - // Associate stylesheet - styleSheets.Add(Resources.Load("Node")); - - // Add node fields - BuildNodeControls(); - UpdateTitle(); - } - - /// - /// Generates a new DialogueNode with pre-existing data. - /// - /// An action delegate called when the remove port button is clicked. - /// The node data to populate the node with. - public DialogueNode(Action onClickRemovePort, DialogueNodeData nodeData) : base(onClickRemovePort) - { - type = NodeType.Dialogue; - - // Associate stylesheet - styleSheets.Add(Resources.Load("Node")); - - // Set the properties from the passed in data. - Guid = nodeData.guid; - DialogueText = nodeData.dialogueText; - SpeakerName = nodeData.speakerName; - - for (int i = 0; i < nodeData.responses.Count; i++) - { - AddDialogueNodePorts(nodeData.responses[i], nodeData.conditionsToToggle[i]); - } - - // Add node fields - BuildNodeControls(); - UpdateTitle(); - } - - /// - /// Builds the node UI. - /// - private void BuildNodeControls() - { - // An UIElements.Button that adds new DialogueNodePorts to the output container. - Button addChoiceButton = new Button(() => AddDialogueNodePorts()) {text = "Add Choice"}; - titleButtonContainer.Add(addChoiceButton); - - // The UIElements.Foldout that contains the main controls. - Foldout contentFoldout = new Foldout - { - text = "Dialogue Properties" - }; - contentContainer.Add(contentFoldout); - - // The UIElements.TextField that sets the speaker's name. - TextField speakerNameField = new TextField("Speaker Name") - { - value = SpeakerName - }; - speakerNameField.RegisterValueChangedCallback(evt => - { - SpeakerName = evt.newValue; - UpdateTitle(); - }); - contentFoldout.contentContainer.Add(speakerNameField); - - contentFoldout.contentContainer.Add(new VisualElement {name = "divider"}); - - // The UIElements.TextField that contains the speaker's dialogue - TextField dialogueTextField = new TextField("Dialogue Text") {value = DialogueText}; - dialogueTextField.RegisterValueChangedCallback(evt => - { - DialogueText = evt.newValue; - UpdateTitle(); - }); - dialogueTextField.multiline = true; - dialogueTextField.AddToClassList("dialogueTextField"); - contentFoldout.contentContainer.Add(dialogueTextField); - - contentFoldout.contentContainer.Add(new VisualElement {name = "divider"}); - - RefreshExpandedState(); - RefreshPorts(); - SetPosition(new Rect(Vector2.zero, DefaultNodeSize)); - } - - // Adds an empty DialogueNodePort to the node's output container. - private void AddDialogueNodePorts(string responseText = "", DialogueCondition condition = null) - { - DialogueNodePort dialogueNodePort = new DialogueNodePort( - GeneratePort(this, "Out", Direction.Output, type: typeof(string)), - onClickRemovePort, - responseText, - condition); - - DialogueNodePorts.Add(dialogueNodePort); - outputContainer.Add(dialogueNodePort.Port); - RefreshExpandedState(); - RefreshPorts(); - } - - /// - /// Updates the node's title when the form's state changes. - /// - public void UpdateTitle() - { - string speakerName; - if (string.IsNullOrWhiteSpace(SpeakerName)) - { - speakerName = "NO-SPK"; - } - else - { - speakerName = SpeakerName.Length <= 10 - ? SpeakerName - : SpeakerName.Substring(0, 10) + "..."; - } - - string dialogueText; - if (string.IsNullOrWhiteSpace(DialogueText)) - { - dialogueText = "NO-DLG"; - } - else - { - dialogueText = DialogueText.Length <= 12 - ? DialogueText - : DialogueText.Substring(0, 12) + "..."; - } - - title = $"{speakerName} : {dialogueText}"; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs.meta deleted file mode 100644 index eeaa2f9..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4a0cce3773994928987b5f03cacd9910 -timeCreated: 1582157944 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs deleted file mode 100644 index f4aa24e..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs +++ /dev/null @@ -1,107 +0,0 @@ -using System; -using UnityEditor.Experimental.GraphView; -using UnityEditor.UIElements; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes -{ - /// - /// A foldout that contains a TextField, ObjectField and GraphView.Port - /// - public class DialogueNodePort - { - /// - /// A reference to the output GraphView.Port - /// - public Port Port { get; } - - /// - /// The ResponseText to display on the response buttons. - /// - public string ResponseText { get; set; } - - /// - /// The dialogue condition to toggle the value of when the choice is selected. - /// - public DialogueCondition ConditionToToggle { get; set; } - - /// - /// Generates a default dialogue node port. - /// - /// A GraphView.Port to reference. - /// An action delegate that is called when the remove port button is clicked - public DialogueNodePort(Port port, Action onClickRemovePort) - { - Port = port; - - port.contentContainer.Add(GenerateDeleteButton(onClickRemovePort)); - port.contentContainer.Add(GenerateFoldout()); - } - - public DialogueNodePort(Port port, Action onClickRemovePort, string responseText = "", - DialogueCondition condition = null) - { - Port = port; - ResponseText = responseText; - ConditionToToggle = condition; - - port.contentContainer.Add(GenerateDeleteButton(onClickRemovePort)); - port.contentContainer.Add(GenerateFoldout()); - } - - /// - /// Creates a new UIElements.Button for deleting a story choice. - /// - /// The action delegate to be called when the delete button is pressed. - /// Returns a UIElement.Button - private Button GenerateDeleteButton(Action onClickRemovePort) - { - return new Button(() => onClickRemovePort(Port.node, Port)) - { - text = "X", - tooltip = "Delete Choice" - }; - } - - /// - /// Creates a UIElements.Foldout and adds the DialogueNodePort elements. - /// - /// Returns a UIElements.Foldout with the DialogueNodePort fields. - private Foldout GenerateFoldout() - { - // The containing foldout - Foldout foldout = new Foldout - { - text = "Port Options", - name = "DialogueNodePort", - value = false - }; - - // The text to display on the response buttons in the game UI. - TextField choiceTextField = new TextField - { - name = "Response Text", - value = ResponseText - }; - // Sets the ResponseText property to the value entered in the TextField. - choiceTextField.RegisterValueChangedCallback(evt => { ResponseText = evt.newValue; }); - foldout.contentContainer.Add(choiceTextField); - - // Sets the dialogue that needs to be toggled when the StoryChoice is chosen in the UI. - ObjectField dialogueToToggle = new ObjectField("Condition to Toggle") - { - name = "ConditionToToggle", - objectType = typeof(DialogueCondition), - value = ConditionToToggle, - allowSceneObjects = false - }; - dialogueToToggle.RegisterValueChangedCallback(evt => - { - ConditionToToggle = evt.newValue as DialogueCondition; - }); - foldout.contentContainer.Add(dialogueToToggle); - - return foldout; - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs.meta deleted file mode 100644 index 9823606..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/DialogueNodePort.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b31d09a360a94ac1ba565b790d78af43 -timeCreated: 1582671863 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs deleted file mode 100644 index 1e4f4e8..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs +++ /dev/null @@ -1,17 +0,0 @@ -using lastmilegames.DialogueSystem.NodeData; -using UnityEngine; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor.Nodes -{ - /// - /// Represents the empty starting point for each Dialogue. - /// - public class EntryNode : BaseNode - { - public EntryNode() - { - type = NodeType.Entry; - topContainer.Remove(inputContainer); - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs.meta deleted file mode 100644 index 42154da..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Nodes/EntryNode.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 8aa25270e41c40c29848a37090345ef4 -timeCreated: 1582309983 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources.meta deleted file mode 100644 index bf2f64f..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4d7e9a6594e34e548cba90b92ce27b2e -timeCreated: 1582129998 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss deleted file mode 100644 index b623b3f..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss +++ /dev/null @@ -1,10 +0,0 @@ -DialogueGraphView { - background-color: #202020; -} - -GridBackground { - /*--grid-background-color: #282828;*/ - --line-color: rgba(193, 196, 192, 0.1); - --thick-line-color: rgba(193, 196, 192, 0.1); - --spacing: 10; -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss.meta deleted file mode 100644 index 601ab2a..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/DialogueGraph.uss.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 25253752fe8f4473b092386e7ca019f8 -timeCreated: 1582130022 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss deleted file mode 100644 index 6f6c441..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss +++ /dev/null @@ -1,55 +0,0 @@ -DialogueNode { - min-width: 250px; -} - -DialogueNode #unity-content, -ConditionNode #condition-properties-foldout #unity-content{ - margin-left: 0; -} - -DialogueNode #output Port { - height: auto; -} - -DialogueNode #output Port Foldout { - flex-grow: 1; -} - -DialogueNode #output .unity-base-field{ - max-width: 200px; - max-height: none; - white-space: normal; -} - -DialogueNode .dialogueTextField TextInput{ - max-width: 300px; -} - -ConditionNode ObjectField { - width: 200px; -} - -ConditionNode ObjectField Label { - padding-bottom: 5px; -} - -ConditionNode Toggle Label{ - flex-grow: 1; -} - -TextField, ObjectField { - flex-direction: column; -} - -TextField, ObjectField, Toggle { - background-color: #3a3a3a; - padding: 5px; -} - -#unity-text-input { - white-space: normal; -} - -/*Port.port {*/ -/* height: auto;*/ -/*}*/ \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss.meta deleted file mode 100644 index 61ff47a..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Node.uss.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 2b012a5a7f1540a68493ad4494092493 -timeCreated: 1582130022 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss deleted file mode 100644 index 954b8c8..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss +++ /dev/null @@ -1,19 +0,0 @@ -.unity-toolbar { - background-color: #2a2a2a; -} - -.unity-toolbar-button, .unity-toolbar-toggle { - background-color: rgba(0, 0, 0, 0); - color: #c4c4c4; -} - -.unity-toolbar .unity-base-text-field__input { - border-top-color: #c4c4c4; - border-right-color: #c4c4c4; - border-bottom-color: #c4c4c4; - border-left-color: #c4c4c4; -} - -.unity-toolbar-button:hover, .unity-toolbar-toggle:hover { - background-color: #4d4d4d; -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss.meta deleted file mode 100644 index 01a8914..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/Resources/Toolbar.uss.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: e9549018e95e46909858d617cae5482c -timeCreated: 1582139223 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs deleted file mode 100644 index baa5489..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; -using lastmilegames.DialogueSystem.NodeData; -using UnityEditor; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; - -namespace lastmilegames.DialogueSystem.DialogueGraphEditor -{ - public class SearchWindowProvider : ScriptableObject, ISearchWindowProvider - { - private DialogueGraphView _graphView; - private EditorWindow _editorWindow; - private Texture2D _indentationIcon; // Icon for indentation hack - - public void Init(EditorWindow editorWindow, DialogueGraphView graphView) - { - _graphView = graphView; - _editorWindow = editorWindow; - - // Transparent icon to fix indentation in search window groups - _indentationIcon = new Texture2D(1, 1); - _indentationIcon.SetPixel(0, 0, new Color(0, 0, 0, 0)); - _indentationIcon.Apply(); - } - - public List CreateSearchTree(SearchWindowContext context) - { - List tree = new List - { - new SearchTreeGroupEntry(new GUIContent("Add Nodes")), - // Un-comment the line below to create a group - // new SearchTreeGroupEntry(new GUIContent("Content"), 1), - new SearchTreeEntry(new GUIContent("Dialogue", _indentationIcon)) - { - level = 1, - userData = NodeType.Dialogue - }, - new SearchTreeEntry(new GUIContent("Condition", _indentationIcon)) - { - level = 1, - userData = NodeType.Condition - } - }; - - return tree; - } - - public bool OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context) - { - Vector2 worldMousePosition = _editorWindow.rootVisualElement.ChangeCoordinatesTo( - _editorWindow.rootVisualElement.parent, - context.screenMousePosition - _editorWindow.position.position - ); - - Vector2 localMousePosition = _graphView.contentViewContainer.WorldToLocal(worldMousePosition); - - switch (searchTreeEntry.userData) - { - case NodeType.Dialogue: - _graphView.CreateNode(NodeType.Dialogue, localMousePosition); - return true; - case NodeType.Condition: - _graphView.CreateNode(NodeType.Condition, localMousePosition); - return true; - default: - return false; - } - } - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs.meta b/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs.meta deleted file mode 100644 index 7a2cb13..0000000 --- a/Assets/DialogueSystem/Scripts/Editor/DialogueGraphEditor/SearchWindowProvider.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 36feb5893f1d4d61882826c4b32f1c69 -timeCreated: 1584831253 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs b/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs deleted file mode 100644 index ae4f2e4..0000000 --- a/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace lastmilegames.DialogueSystem -{ - public interface IDialoguePlayer - { - void PlayDialogue(DialogueContainer container); - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs.meta b/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs.meta deleted file mode 100644 index 71f268e..0000000 --- a/Assets/DialogueSystem/Scripts/IDialoguePlayer.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 68ab8c9f7a9a4556891473e53c6dd639 -timeCreated: 1604013675 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData.meta b/Assets/DialogueSystem/Scripts/NodeData.meta deleted file mode 100644 index 5accac6..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6fe4dff7781f4eee988c2c4427c5d7a1 -timeCreated: 1604008777 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs b/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs deleted file mode 100644 index f9c487c..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using UnityEngine; - -namespace lastmilegames.DialogueSystem.NodeData -{ - /// - /// Base class for serializable node data. Represents the data all nodes should track. - /// - [Serializable] - public class BaseNodeData - { - public string guid; - public Vector2 position; - public NodeType type; - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs.meta deleted file mode 100644 index daca11f..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/BaseNodeData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7d52fa10526b4aff9e689bd3d93408ca -timeCreated: 1582908255 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs b/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs deleted file mode 100644 index a9bb394..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace lastmilegames.DialogueSystem.NodeData -{ - /// - /// Represents the data that a ConditionNode should save. - /// - [Serializable] - public class ConditionNodeData : BaseNodeData - { - public DialogueCondition conditionToTest; - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs.meta deleted file mode 100644 index f20a93d..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/ConditionNodeData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: c761ff45aac34fdca503dacc2382e959 -timeCreated: 1582742605 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs b/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs deleted file mode 100644 index 2a0e70f..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace lastmilegames.DialogueSystem.NodeData -{ - /// - /// Represents the data a DialogueNode should track. - /// - [Serializable] - public class DialogueNodeData : BaseNodeData - { - /// - /// The spoken dialogue. - /// - public string dialogueText; - - /// - /// The speaker. - /// - public string speakerName; - - /// - /// A list of the DialogueNodePort responses. - /// - public List responses; - - /// - /// A list of the DialogueNodePort conditions to toggle. - /// - public List conditionsToToggle; - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs.meta deleted file mode 100644 index 65ac3d3..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/DialogueNodeData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 7a70e63dae024bf692c7b288cc706479 -timeCreated: 1582742556 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs b/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs deleted file mode 100644 index 4b16278..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace lastmilegames.DialogueSystem.NodeData -{ - [Serializable] - public class ExposedProperty - { - public string propertyName = "@@NAME@@"; - public string propertyValue = "Value"; - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs.meta deleted file mode 100644 index 1581b4a..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/ExposedProperty.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b38799781c8c46e5a3cd0808a4b8e332 -timeCreated: 1604353132 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs b/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs deleted file mode 100644 index b48069e..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; - -namespace lastmilegames.DialogueSystem.NodeData -{ - /// - /// Represents the links between nodes. - /// - [Serializable] - public class NodeLinkData - { - /// - /// The output node that starts the link. - /// - public string baseNodeGuid; - - /// - /// The type of the output node that starts the link. - /// - public NodeType baseNodeType; - - /// - /// The next node to move to. - /// - public string targetNodeGuid; - - /// - /// The type of the final node in the link. - /// - public NodeType targetNodeType; - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs.meta deleted file mode 100644 index 642fb36..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/NodeLinkData.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: f769806a40a6470cb7355cb17e5a359c -timeCreated: 1582742667 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs b/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs deleted file mode 100644 index 5feb09f..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace lastmilegames.DialogueSystem.NodeData -{ - /// - /// The available types of nodes that can be created. - /// - public enum NodeType - { - NotSet, - Entry, - Condition, - Dialogue - } -} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs.meta b/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs.meta deleted file mode 100644 index 025bdc8..0000000 --- a/Assets/DialogueSystem/Scripts/NodeData/NodeType.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 9b1d5acf821c47d6b46199e15670eb15 -timeCreated: 1582158115 \ No newline at end of file From 7d0fddda10474978960e23ab22d0df79873db394 Mon Sep 17 00:00:00 2001 From: Justin Abbott Date: Fri, 4 Dec 2020 14:05:36 -0800 Subject: [PATCH 02/10] Implement a dialogue `Character` class to use in conversations. A character is a scriptable object that contains the name that should be displayed in the UI, and sprite portraits. --- Assembly-CSharp-Editor.csproj.DotSettings | 2 + Assets/DialogueSystem/Demo/SampleScene.unity | 8 +- .../DialogueSystem/Scripts/AssetCreators.meta | 8 ++ .../Scripts/AssetCreators/Characters.meta | 3 + .../AssetCreators/Characters/Character.cs | 57 ++++++++ .../Characters/Character.cs.meta | 3 + .../Characters/CharacterSprite.cs | 9 ++ .../Characters/CharacterSprite.cs.meta | 3 + .../Scripts/AssetCreators/Editor.meta | 3 + .../AssetCreators/Editor/CharacterEditor.cs | 125 ++++++++++++++++++ .../Editor/CharacterEditor.cs.meta | 11 ++ .../AssetCreators/Editor/CharacterEditor.uss | 35 +++++ .../Editor/CharacterEditor.uss.meta | 11 ++ .../AssetCreators/Editor/CharacterEditor.uxml | 24 ++++ .../Editor/CharacterEditor.uxml.meta | 10 ++ .../Editor/CharacterSpriteElement.cs | 64 +++++++++ .../Editor/CharacterSpriteElement.cs.meta | 11 ++ .../Editor/CharacterSpriteElement.uss | 48 +++++++ .../Editor/CharacterSpriteElement.uss.meta | 11 ++ .../Editor/CharacterSpriteElement.uxml | 24 ++++ .../Editor/CharacterSpriteElement.uxml.meta | 10 ++ .../Scripts/AssetCreators/Editor/Utilities.cs | 30 +++++ .../AssetCreators/Editor/Utilities.cs.meta | 3 + UIElementsSchema/UIElements.xsd | 4 +- .../UnityEditor.PackageManager.UI.xsd | 42 +++--- .../UnityEditor.Rendering.LookDev.xsd | 44 ++++++ .../UnityEditor.ShaderGraph.Drawing.xsd | 25 ++++ .../UnityEditor.UIElements.Debugger.xsd | 4 +- UIElementsSchema/UnityEditor.UIElements.xsd | 2 +- UIElementsSchema/UnityEngine.UIElements.xsd | 2 +- 30 files changed, 606 insertions(+), 30 deletions(-) create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Characters.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.cs create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.cs.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uss create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uss.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uxml create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uxml.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.cs create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.cs.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.uss create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.uss.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.uxml create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterSpriteElement.uxml.meta create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/Utilities.cs create mode 100644 Assets/DialogueSystem/Scripts/AssetCreators/Editor/Utilities.cs.meta create mode 100644 UIElementsSchema/UnityEditor.Rendering.LookDev.xsd create mode 100644 UIElementsSchema/UnityEditor.ShaderGraph.Drawing.xsd diff --git a/Assembly-CSharp-Editor.csproj.DotSettings b/Assembly-CSharp-Editor.csproj.DotSettings index 12ac1b1..7c5c461 100644 --- a/Assembly-CSharp-Editor.csproj.DotSettings +++ b/Assembly-CSharp-Editor.csproj.DotSettings @@ -1,4 +1,6 @@  True True + True + True True \ No newline at end of file diff --git a/Assets/DialogueSystem/Demo/SampleScene.unity b/Assets/DialogueSystem/Demo/SampleScene.unity index 6428c5a..1c4fd85 100644 --- a/Assets/DialogueSystem/Demo/SampleScene.unity +++ b/Assets/DialogueSystem/Demo/SampleScene.unity @@ -38,13 +38,13 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641258, b: 0.574817, a: 1} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: m_ObjectHideFlags: 0 serializedVersion: 11 - m_GIWorkflowMode: 0 + m_GIWorkflowMode: 1 m_GISettings: serializedVersion: 2 m_BounceScale: 1 @@ -728,7 +728,7 @@ PrefabInstance: - target: {fileID: 8786771132893712695, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} propertyPath: m_AnchoredPosition.y - value: -0.00008284766 + value: -0.00007994529 objectReference: {fileID: 0} - target: {fileID: 8786771132936344443, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} @@ -738,7 +738,7 @@ PrefabInstance: - target: {fileID: 8786771132936344443, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} propertyPath: m_AnchoredPosition.y - value: -0.00003786637 + value: -0.000049769158 objectReference: {fileID: 0} - target: {fileID: 8786771132947378257, guid: 4d8914cb6b33dc34e86ba2b8caea414c, type: 3} diff --git a/Assets/DialogueSystem/Scripts/AssetCreators.meta b/Assets/DialogueSystem/Scripts/AssetCreators.meta new file mode 100644 index 0000000..083d8ea --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9ab752929a9d5d64fb727ab1cc39cd10 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Characters.meta b/Assets/DialogueSystem/Scripts/AssetCreators/Characters.meta new file mode 100644 index 0000000..47fe125 --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Characters.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: eec5443e206c479aa625452e0d66e7e1 +timeCreated: 1607017854 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs new file mode 100644 index 0000000..103aa87 --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs @@ -0,0 +1,57 @@ +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace lastmilegames.DialogueSystem.AssetCreators.Characters +{ + [CreateAssetMenu(fileName = "New Character", menuName = "Dialogue System/New Character", order = 0)] + public class Character : ScriptableObject + { + [SerializeField] private List characterSprites = new List(); + + public IEnumerable GetCharacterSprites() + { + return characterSprites; + } + + public void AddSprite(CharacterSprite cSprite) + { + characterSprites.Add(cSprite); + AssetDatabase.AddObjectToAsset(cSprite, this); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + public void RemoveSprite(CharacterSprite cSprite) + { + AssetDatabase.RemoveObjectFromAsset(cSprite); + characterSprites.Remove(cSprite); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + public void RemoveAllSprites() + { + for (int i = characterSprites.Count - 1; i >= 0; i--) + { + AssetDatabase.RemoveObjectFromAsset(characterSprites[i]); + characterSprites.RemoveAt(i); + } + + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + public void RenameSubAsset(CharacterSprite cSprite) + { + // Remove the old object + AssetDatabase.RemoveObjectFromAsset(cSprite); + AssetDatabase.SaveAssets(); + + // Add the new object + AssetDatabase.AddObjectToAsset(cSprite, this); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + } +} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs.meta b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs.meta new file mode 100644 index 0000000..362291b --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/Character.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 27075574afdb479fb0694373243e6c78 +timeCreated: 1606948476 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs new file mode 100644 index 0000000..2bc499c --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace lastmilegames.DialogueSystem.AssetCreators.Characters +{ + public class CharacterSprite : ScriptableObject + { + public Sprite sprite; + } +} \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs.meta b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs.meta new file mode 100644 index 0000000..005d62c --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Characters/CharacterSprite.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 20a78fb41e41499188727b72bb6a083d +timeCreated: 1607017880 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Editor.meta b/Assets/DialogueSystem/Scripts/AssetCreators/Editor.meta new file mode 100644 index 0000000..674e23c --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 8a6161e849a945e8a2f891dd01e8db49 +timeCreated: 1607024177 \ No newline at end of file diff --git a/Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.cs b/Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.cs new file mode 100644 index 0000000..67a69f0 --- /dev/null +++ b/Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.cs @@ -0,0 +1,125 @@ +using System.Linq; +using lastmilegames.DialogueSystem.AssetCreators.Characters; +using UnityEditor; +using UnityEngine; +using UnityEngine.UIElements; + +namespace lastmilegames.DialogueSystem.AssetCreators +{ + [CustomEditor(typeof(Character))] + public class CharacterEditor : Editor + { + private Character character; + private VisualElement cSpriteList; + private VisualElement rootElement; + + private void OnEnable() + { + rootElement = new VisualElement(); + character = (Character) target; + + var visualTree = AssetDatabase.LoadAssetAtPath( + "Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uxml"); + visualTree.CloneTree(rootElement); + + var styleSheet = AssetDatabase.LoadAssetAtPath( + "Assets/DialogueSystem/Scripts/AssetCreators/Editor/CharacterEditor.uss"); + rootElement.styleSheets.Add(styleSheet); + } + + public override VisualElement CreateInspectorGUI() + { + #region Fields + + var characterName = rootElement.Q("characterName"); + characterName.isDelayed = true; + characterName.value = character.name; + characterName.RegisterCallback>(evt => + { + character.name = evt.newValue; + Utilities.RenameAsset(character, evt.newValue); + + + EditorUtility.SetDirty(character); + }); + + #endregion + + #region Diaplay Sprite List + + cSpriteList = rootElement.Q("spriteList"); + UpdateSpriteList(); + + #endregion + + #region Buttons + + var btnAddSprite = rootElement.Q