From ed588eefd1d2fefcc8ab1d8395b94756720e4953 Mon Sep 17 00:00:00 2001 From: recepilhanli Date: Fri, 28 Jun 2024 00:37:49 +0300 Subject: [PATCH] Making Tidy Some Stuffs & Fix Build Problem --- Assets/DialogSystem.meta | 8 ++ .../DialogGraphs/DialogSwitchGraph.asset | 3 +- Assets/DialogSystem/Scenes/DialogTest.unity | 49 +++++++- Assets/DialogSystem/Scripts/DialogEvent.cs | 69 +++++++---- Assets/DialogSystem/Scripts/DialogGraph.cs | 12 +- Assets/DialogSystem/Scripts/DialogNode.cs | 111 ++++++++++-------- Assets/DialogSystem/Scripts/DialogSwitcher.cs | 84 +++++++------ Assets/DialogSystem/Scripts/DialogUI.cs | 39 ++++-- Assets/DialogSystem/Scripts/EventTesting.cs | 6 + Assets/xNode.meta | 8 ++ 10 files changed, 259 insertions(+), 130 deletions(-) create mode 100644 Assets/DialogSystem.meta create mode 100644 Assets/xNode.meta diff --git a/Assets/DialogSystem.meta b/Assets/DialogSystem.meta new file mode 100644 index 0000000..58da93d --- /dev/null +++ b/Assets/DialogSystem.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a6bf78640c1f23f489ad7f76105d854b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/DialogSystem/DialogGraphs/DialogSwitchGraph.asset b/Assets/DialogSystem/DialogGraphs/DialogSwitchGraph.asset index 86b5f43..49cb9d1 100644 --- a/Assets/DialogSystem/DialogGraphs/DialogSwitchGraph.asset +++ b/Assets/DialogSystem/DialogGraphs/DialogSwitchGraph.asset @@ -123,8 +123,7 @@ MonoBehaviour: Event: m_PersistentCalls: m_Calls: - - m_Target: {fileID: -8642161715027127687, guid: ddf806041374b3d47b5f4b11f9505ced, - type: 3} + - m_Target: {fileID: -8642161715027127687, guid: ddf806041374b3d47b5f4b11f9505ced, type: 3} m_TargetAssemblyTypeName: EventTesting, Assembly-CSharp m_MethodName: TestEvent m_Mode: 1 diff --git a/Assets/DialogSystem/Scenes/DialogTest.unity b/Assets/DialogSystem/Scenes/DialogTest.unity index c5956ab..4825ac3 100644 --- a/Assets/DialogSystem/Scenes/DialogTest.unity +++ b/Assets/DialogSystem/Scenes/DialogTest.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.18028352, g: 0.22571376, b: 0.3069224, a: 1} + m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641275, b: 0.5748171, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -1285,7 +1285,7 @@ MonoBehaviour: m_EditorClassIdentifier: dialogGraph: {fileID: 11400000, guid: 10a808161346eca49aa716fcd5fe4f97, type: 2} currentNode: {fileID: 0} - _DialogCanvas: {fileID: 1394771758} + _dialogCanvas: {fileID: 1394771758} headlineTMP: {fileID: 2076104245} descriptionTMP: {fileID: 1270832993} option1TMP: {fileID: 891606019} @@ -1928,6 +1928,7 @@ GameObject: - component: {fileID: 2124641954} - component: {fileID: 2124641953} - component: {fileID: 2124641952} + - component: {fileID: 2124641955} m_Layer: 0 m_Name: Main Camera m_TagString: MainCamera @@ -2009,6 +2010,50 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2124641955 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2124641951} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a79441f348de89743a2939f4d699eac1, type: 3} + m_Name: + m_EditorClassIdentifier: + m_RenderShadows: 1 + m_RequiresDepthTextureOption: 2 + m_RequiresOpaqueTextureOption: 2 + m_CameraType: 0 + m_Cameras: [] + m_RendererIndex: -1 + m_VolumeLayerMask: + serializedVersion: 2 + m_Bits: 1 + m_VolumeTrigger: {fileID: 0} + m_VolumeFrameworkUpdateModeOption: 2 + m_RenderPostProcessing: 0 + m_Antialiasing: 0 + m_AntialiasingQuality: 2 + m_StopNaN: 0 + m_Dithering: 0 + m_ClearDepth: 1 + m_AllowXRRendering: 1 + m_AllowHDROutput: 1 + m_UseScreenCoordOverride: 0 + m_ScreenSizeOverride: {x: 0, y: 0, z: 0, w: 0} + m_ScreenCoordScaleBias: {x: 0, y: 0, z: 0, w: 0} + m_RequiresDepthTexture: 0 + m_RequiresColorTexture: 0 + m_Version: 2 + m_TaaSettings: + quality: 3 + frameInfluence: 0.1 + jitterScale: 1 + mipBias: 0 + varianceClampScale: 0.9 + contrastAdaptiveSharpening: 0 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 diff --git a/Assets/DialogSystem/Scripts/DialogEvent.cs b/Assets/DialogSystem/Scripts/DialogEvent.cs index 65c2498..45d50a6 100644 --- a/Assets/DialogSystem/Scripts/DialogEvent.cs +++ b/Assets/DialogSystem/Scripts/DialogEvent.cs @@ -1,36 +1,16 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEditor; -using UnityEngine; +using UnityEngine; using UnityEngine.Events; using XNode; -using XNodeEditor; namespace DialogSystem { - /// - /// - /// - - [NodeWidth(350), NodeTint("#ff7f50")] - public class DialogEvent : Node - { - [Input] public Node Input; - - [Output] public Node Output; - - public UnityEvent Event = new UnityEvent(); - - public void InvokeEvent() - { - Event?.Invoke(); - } - - - - } + #region Editor +#if UNITY_EDITOR + using UnityEditor; + using XNodeEditor; + //Dialogue Event Node Editor [CustomNodeEditor(typeof(DialogEvent))] public class DialogEventEditor : NodeEditor { @@ -58,4 +38,41 @@ public override void OnBodyGUI() serializedObject.ApplyModifiedProperties(); } } +#endif + #endregion + + + /// + /// This node is used to invoke a UnityEvent + /// + [NodeWidth(350), NodeTint("#ff7f50")] + public class DialogEvent : Node + { + /// + /// The input node + /// + [Input] public Node Input; + + /// + /// The output node + /// + [Output] public Node Output; + + /// + /// The event that will be invoked + /// + public UnityEvent Event = new UnityEvent(); + + /// + /// This method is used to invoke the event + /// + public void InvokeEvent() + { + Event?.Invoke(); + } + + + + } + } \ No newline at end of file diff --git a/Assets/DialogSystem/Scripts/DialogGraph.cs b/Assets/DialogSystem/Scripts/DialogGraph.cs index 2239367..d423a6b 100644 --- a/Assets/DialogSystem/Scripts/DialogGraph.cs +++ b/Assets/DialogSystem/Scripts/DialogGraph.cs @@ -5,10 +5,16 @@ namespace DialogSystem { + /// + /// This class is used to create a dialog graph + /// [CreateAssetMenu(fileName = "New Dialog Graph", menuName = "Dialog/Dialog Graph")] public class DialogGraph : NodeGraph { - + /// + /// The nodes of the graph + /// + /// The first node of the graph public Node GetFirstNode() { Node FirstNode = null; @@ -23,12 +29,8 @@ public Node GetFirstNode() FirstNode = node; } } - return FirstNode; } - - - } } \ No newline at end of file diff --git a/Assets/DialogSystem/Scripts/DialogNode.cs b/Assets/DialogSystem/Scripts/DialogNode.cs index d900979..52d8f66 100644 --- a/Assets/DialogSystem/Scripts/DialogNode.cs +++ b/Assets/DialogSystem/Scripts/DialogNode.cs @@ -1,53 +1,17 @@ -using System.Collections; -using System.Collections.Generic; using UnityEditor; using UnityEngine; -using XNode; -using XNodeEditor; -using static XNode.Node; -namespace DialogSystem -{ - /// - /// This node is used to create a dialog sequence - /// - [NodeWidth(300), NodeTint("#506f7f")] - public class DialogNode : Node - { - - [Input] public Node Input; - - public string Headline; - public string Description; - - public string Option1; - [Output] public Node Option1Output; - - public string Option2; - [Output] public Node Option2Output; - - public string Option3; - [Output] public Node Option3Output; - - public string Option4; - [Output] public Node Option4Output; - - public bool Hide = false; - - protected override void Init() - { - base.Init(); - - name = "Dialog Node"; - - } - - - } +namespace DialogSystem +{ +#region Editor +#if UNITY_EDITOR + using XNode; + using XNodeEditor; + //Dialogue Node Editor [CustomNodeEditor(typeof(DialogNode))] public class DialogNodeEditor : NodeEditor { @@ -109,10 +73,10 @@ public override void OnBodyGUI() node.Hide = true; } - var dgraph = node.graph as DialogGraph; - if (dgraph != null) + var dGraph = node.graph as DialogGraph; + if (dGraph != null) { - var firstNode = dgraph.GetFirstNode(); + var firstNode = dGraph.GetFirstNode(); if (firstNode == node) { GUI.color = Color.red; @@ -135,10 +99,10 @@ public override void OnBodyGUI() node.Hide = false; } - var dgraph = node.graph as DialogGraph; - if (dgraph != null) + var dGraph = node.graph as DialogGraph; + if (dGraph != null) { - var firstNode = dgraph.GetFirstNode(); + var firstNode = dGraph.GetFirstNode(); if (firstNode == node) { GUI.color = Color.yellow; @@ -154,6 +118,55 @@ public override void OnBodyGUI() } +#endif +#endregion + + /// + /// This node is used to create a dialog sequence + /// + [NodeWidth(300), NodeTint("#506f7f")] + public class DialogNode : Node + { + + [Input] public Node Input; // The input node + + public string Headline; // The headline of the dialog + public string Description; // The description of the dialog + + #region Options + public string Option1; + [Output] public Node Option1Output; + + public string Option2; + [Output] public Node Option2Output; + + public string Option3; + [Output] public Node Option3Output; + + public string Option4; + [Output] public Node Option4Output; + #endregion + + public bool Hide = false; // Hide the options + + /// + /// Initialize the node + /// + protected override void Init() + { + base.Init(); + + name = "Dialog Node"; + + } + + + } + + + + + } \ No newline at end of file diff --git a/Assets/DialogSystem/Scripts/DialogSwitcher.cs b/Assets/DialogSystem/Scripts/DialogSwitcher.cs index 2b7c0af..ee4a632 100644 --- a/Assets/DialogSystem/Scripts/DialogSwitcher.cs +++ b/Assets/DialogSystem/Scripts/DialogSwitcher.cs @@ -1,54 +1,64 @@ -using System.Collections; -using System.Collections.Generic; -using DialogSystem; -using UnityEditor; +using UnityEditor; using UnityEngine; -using XNode; -using XNodeEditor; + + namespace DialogSystem { + +#region Editor +#if UNITY_EDITOR + using XNode; + using XNodeEditor; + //Dialogue Node Editor + [CustomNodeEditor(typeof(DialogSwitcher))] + public class DialogSwitcherEditor : NodeEditor + { + public override void OnHeaderGUI() + { + GUI.color = Color.white; + string title = target.name; + GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); + } + + public override void OnBodyGUI() + { + serializedObject.Update(); + + var node = target as DialogSwitcher; + + NodeEditorGUILayout.AddPortField(node.GetInputPort("Input")); + node.Input = node.GetInputPort("Input").Connection?.node; + + DialogGraph newDialogGraph = EditorGUILayout.ObjectField("Next Dialog Graph", node.NextDialogGraph, typeof(DialogGraph), false) as DialogGraph; + if (newDialogGraph != node.NextDialogGraph) + { + node.NextDialogGraph = newDialogGraph; + serializedObject.ApplyModifiedProperties(); + } + + serializedObject.ApplyModifiedProperties(); + } + } +#endif +#endregion + /// /// This node is used to switch between different dialog graphs /// [NodeWidth(300), NodeTint("#ff0f0f")] public class DialogSwitcher : Node { + /// + /// The input node + /// [Input] public Node Input; + /// + /// The next dialog graph + /// public DialogGraph NextDialogGraph; } } -[CustomNodeEditor(typeof(DialogSwitcher))] -public class DialogSwitcherEditor : NodeEditor -{ - public override void OnHeaderGUI() - { - GUI.color = Color.white; - string title = target.name; - GUILayout.Label(title, NodeEditorResources.styles.nodeHeader, GUILayout.Height(30)); - } - - public override void OnBodyGUI() - { - serializedObject.Update(); - - var node = target as DialogSwitcher; - - NodeEditorGUILayout.AddPortField(node.GetInputPort("Input")); - node.Input = node.GetInputPort("Input").Connection?.node; - - DialogGraph newDialogGraph = EditorGUILayout.ObjectField("Next Dialog Graph", node.NextDialogGraph, typeof(DialogGraph), false) as DialogGraph; - if (newDialogGraph != node.NextDialogGraph) - { - node.NextDialogGraph = newDialogGraph; - serializedObject.ApplyModifiedProperties(); - } - - - - serializedObject.ApplyModifiedProperties(); - } -} \ No newline at end of file diff --git a/Assets/DialogSystem/Scripts/DialogUI.cs b/Assets/DialogSystem/Scripts/DialogUI.cs index 0774d57..c9a6d70 100644 --- a/Assets/DialogSystem/Scripts/DialogUI.cs +++ b/Assets/DialogSystem/Scripts/DialogUI.cs @@ -1,16 +1,15 @@ -using System.Collections; -using System.Collections.Generic; using UnityEngine; using DialogSystem; using XNode; using TMPro; + public class DialogUI : MonoBehaviour { public DialogGraph dialogGraph; [HideInInspector] public Node currentNode; - [SerializeField] private GameObject _DialogCanvas; + [SerializeField] private GameObject _dialogCanvas; [SerializeField] private TextMeshProUGUI headlineTMP; [SerializeField] private TextMeshProUGUI descriptionTMP; @@ -19,13 +18,15 @@ public class DialogUI : MonoBehaviour [SerializeField] private TextMeshProUGUI option3TMP; [SerializeField] private TextMeshProUGUI option4TMP; - private void Awake() { currentNode = dialogGraph.GetFirstNode(); UpdateUI(); } + /// + /// This method is used to update the buttons + /// void UpdateButtons() { if (option1TMP.text == string.Empty) @@ -65,7 +66,9 @@ void UpdateButtons() } } - + /// + /// This method is used to update the UI + /// private void UpdateUI() { DialogNode dialogNode = currentNode as DialogNode; @@ -83,12 +86,18 @@ private void UpdateUI() } } + /// + /// This method is used to open the dialog + /// void CloseDialog() { - _DialogCanvas.SetActive(false); + _dialogCanvas.SetActive(false); } - + /// + /// This method is used to open the dialog + /// + /// The option that was selected public void SelectOption(int option) { Node node = GetNextNodeOfDialogOption(option); @@ -135,7 +144,11 @@ public void SelectOption(int option) CloseDialog(); } - + + /// + /// This method is used to switch to a new dialog graph + /// + /// The new dialog graph void SwitchNewDialogGraph(DialogGraph graph) { dialogGraph = graph; @@ -143,6 +156,10 @@ void SwitchNewDialogGraph(DialogGraph graph) UpdateUI(); } + /// + /// This method is used to initialize the next dialog node + /// + /// The next dialog node void InitNextDialogNode(DialogNode node) { currentNode = node; @@ -150,7 +167,11 @@ void InitNextDialogNode(DialogNode node) } - + /// + /// This method is used to get the next node of a dialog option + /// + /// The option that was selected + /// < The next node of the dialog option public Node GetNextNodeOfDialogOption(int option) { DialogNode dialogNode = currentNode as DialogNode; diff --git a/Assets/DialogSystem/Scripts/EventTesting.cs b/Assets/DialogSystem/Scripts/EventTesting.cs index bfd4aeb..7be6bfe 100644 --- a/Assets/DialogSystem/Scripts/EventTesting.cs +++ b/Assets/DialogSystem/Scripts/EventTesting.cs @@ -2,8 +2,14 @@ using System.Collections.Generic; using UnityEngine; +/// +/// This class is used to test the DialogEvent node +/// public class EventTesting : MonoBehaviour { + /// + /// This method is used to test the DialogEvent node + /// public void TestEvent() { Debug.Log("Event has been triggered"); diff --git a/Assets/xNode.meta b/Assets/xNode.meta new file mode 100644 index 0000000..359b6d9 --- /dev/null +++ b/Assets/xNode.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 174a8183a0893e049b49620262d1a75c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: