From 464adca5af9f3840d303a90980506da677037029 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Wed, 13 Jul 2022 12:03:27 +0800 Subject: [PATCH] refactor: Move implementation level to another folder --- Sample/MathGraph/Editor/MathEditor.cs | 2 +- Sample/MathGraph/Editor/MathGraphView.cs | 5 +- TNode/Attribute/Ports/InputAttribute.cs | 4 +- TNode/Attribute/Ports/PortAttribute.cs | 3 +- TNode/Editor/BaseViews.meta | 3 - TNode/Editor/Cache/NodeEditorExtensions.cs | 28 ++-- .../Editor/GraphBlackboard/BlackboardField.cs | 12 -- TNode/Editor/GraphEditor.cs | 15 +- .../Inspector/InspectorImplementation.meta | 3 - .../InspectorImplementation/EnumFieldItem.cs | 21 --- .../EnumFieldItem.cs.meta | 3 - .../InspectorImplementation/FloatFieldItem.cs | 13 -- .../FloatFieldItem.cs.meta | 3 - .../PropertyFieldItem.cs | 25 ---- .../PropertyFieldItem.cs.meta | 3 - .../StringFieldItem.cs | 16 --- .../StringFieldItem.cs.meta | 3 - .../ToggleFieldItem.cs | 14 -- .../ToggleFieldItem.cs.meta | 3 - TNode/Editor/Inspector/InspectorItem.cs | 105 -------------- TNode/Editor/Inspector/InspectorItem.cs.meta | 3 - .../Editor/Inspector/InspectorItemFactory.cs | 45 ------ .../Inspector/InspectorItemFactory.cs.meta | 3 - TNode/Editor/Inspector/MonoScriptInspector.cs | 16 --- .../Inspector/MonoScriptInspector.cs.meta | 3 - TNode/Editor/Inspector/PropertyDrawer.meta | 3 - TNode/Editor/Manipulators.meta | 3 - TNode/Editor/NodeGraphView.meta | 3 + .../NodeGraphView/IBaseDataGraphView.cs | 11 ++ .../NodeGraphView/IBaseDataGraphView.cs.meta | 3 + TNode/Editor/NodeGraphView/IDataGraphView.cs | 7 + .../NodeGraphView/IDataGraphView.cs.meta | 3 + TNode/Editor/NodeViews/DefaultNodeView.cs | 11 -- TNodeGraphViewImpl.meta | 3 + TNodeGraphViewImpl/Editor.meta | 3 + .../Editor/GraphBlackboard.meta | 0 .../Editor/GraphBlackboard/BlackboardField.cs | 12 ++ .../GraphBlackboard/BlackboardField.cs.meta | 0 .../GraphBlackboard/BlackboardProperty.meta | 0 .../BlackboardProperty/BlackboardProperty.cs | 2 +- .../BlackboardProperty.cs.meta | 0 .../DefaultGraphBlackboardView.cs | 2 +- .../DefaultGraphBlackboardView.cs.meta | 0 .../GraphBlackboard/GraphBlackboardView.cs | 2 +- .../GraphBlackboardView.cs.meta | 0 TNodeGraphViewImpl/Editor/Inspector.meta | 3 + .../Editor/Inspector/NodeInspector.cs | 30 ++-- .../Editor/Inspector/NodeInspector.cs.meta | 0 .../Editor/Inspector/NodeInspectorInNode.cs | 23 --- .../Inspector/NodeInspectorInNode.cs.meta | 0 TNodeGraphViewImpl/Editor/NodeGraphView.meta | 3 + .../Editor/NodeGraphView}/DataGraphView.cs | 131 +++--------------- .../NodeGraphView}/DataGraphView.cs.meta | 0 .../NodeGraphView}/SimpleGraphSubWindow.cs | 2 +- .../SimpleGraphSubWindow.cs.meta | 0 .../Editor/NodeViews.meta | 0 .../Editor/NodeViews/DefaultNodeView.cs | 10 ++ .../Editor/NodeViews/DefaultNodeView.cs.meta | 0 .../Editor/NodeViews/DragNodeView.cs | 5 +- .../Editor/NodeViews/DragNodeView.cs.meta | 0 .../Editor/NodeViews/NodeView.cs | 20 ++- .../Editor/NodeViews/NodeView.cs.meta | 0 .../Editor/Search.meta | 0 .../Search/BlackboardSearchWindowProvider.cs | 6 +- .../BlackboardSearchWindowProvider.cs.meta | 0 .../Editor/Search/NodeSearchWindowProvider.cs | 4 +- .../Search/NodeSearchWindowProvider.cs.meta | 0 67 files changed, 140 insertions(+), 519 deletions(-) delete mode 100644 TNode/Editor/BaseViews.meta delete mode 100644 TNode/Editor/GraphBlackboard/BlackboardField.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation.meta delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorItem.cs delete mode 100644 TNode/Editor/Inspector/InspectorItem.cs.meta delete mode 100644 TNode/Editor/Inspector/InspectorItemFactory.cs delete mode 100644 TNode/Editor/Inspector/InspectorItemFactory.cs.meta delete mode 100644 TNode/Editor/Inspector/MonoScriptInspector.cs delete mode 100644 TNode/Editor/Inspector/MonoScriptInspector.cs.meta delete mode 100644 TNode/Editor/Inspector/PropertyDrawer.meta delete mode 100644 TNode/Editor/Manipulators.meta create mode 100644 TNode/Editor/NodeGraphView.meta create mode 100644 TNode/Editor/NodeGraphView/IBaseDataGraphView.cs create mode 100644 TNode/Editor/NodeGraphView/IBaseDataGraphView.cs.meta create mode 100644 TNode/Editor/NodeGraphView/IDataGraphView.cs create mode 100644 TNode/Editor/NodeGraphView/IDataGraphView.cs.meta delete mode 100644 TNode/Editor/NodeViews/DefaultNodeView.cs create mode 100644 TNodeGraphViewImpl.meta create mode 100644 TNodeGraphViewImpl/Editor.meta rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard.meta (100%) create mode 100644 TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/BlackboardField.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/BlackboardProperty.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs (85%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs (86%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/GraphBlackboardView.cs (87%) rename {TNode => TNodeGraphViewImpl}/Editor/GraphBlackboard/GraphBlackboardView.cs.meta (100%) create mode 100644 TNodeGraphViewImpl/Editor/Inspector.meta rename {TNode => TNodeGraphViewImpl}/Editor/Inspector/NodeInspector.cs (61%) rename {TNode => TNodeGraphViewImpl}/Editor/Inspector/NodeInspector.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/Inspector/NodeInspectorInNode.cs (67%) rename {TNode => TNodeGraphViewImpl}/Editor/Inspector/NodeInspectorInNode.cs.meta (100%) create mode 100644 TNodeGraphViewImpl/Editor/NodeGraphView.meta rename {TNode/Editor/BaseViews => TNodeGraphViewImpl/Editor/NodeGraphView}/DataGraphView.cs (74%) rename {TNode/Editor/BaseViews => TNodeGraphViewImpl/Editor/NodeGraphView}/DataGraphView.cs.meta (100%) rename {TNode/Editor/BaseViews => TNodeGraphViewImpl/Editor/NodeGraphView}/SimpleGraphSubWindow.cs (97%) rename {TNode/Editor/BaseViews => TNodeGraphViewImpl/Editor/NodeGraphView}/SimpleGraphSubWindow.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews.meta (100%) create mode 100644 TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews/DefaultNodeView.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews/DragNodeView.cs (65%) rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews/DragNodeView.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews/NodeView.cs (94%) rename {TNode => TNodeGraphViewImpl}/Editor/NodeViews/NodeView.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/Search.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/Search/BlackboardSearchWindowProvider.cs (93%) rename {TNode => TNodeGraphViewImpl}/Editor/Search/BlackboardSearchWindowProvider.cs.meta (100%) rename {TNode => TNodeGraphViewImpl}/Editor/Search/NodeSearchWindowProvider.cs (93%) rename {TNode => TNodeGraphViewImpl}/Editor/Search/NodeSearchWindowProvider.cs.meta (100%) diff --git a/Sample/MathGraph/Editor/MathEditor.cs b/Sample/MathGraph/Editor/MathEditor.cs index 75ae61d..a5bb700 100644 --- a/Sample/MathGraph/Editor/MathEditor.cs +++ b/Sample/MathGraph/Editor/MathEditor.cs @@ -14,7 +14,7 @@ public class MathEditor : GraphEditor{ var wnd = GetWindow(); wnd.titleContent = new GUIContent("MathGraph Editor"); wnd.CreateGUI(); - wnd._graphView.Data = graph; + wnd.GraphView.Data = graph; return true; } return false; diff --git a/Sample/MathGraph/Editor/MathGraphView.cs b/Sample/MathGraph/Editor/MathGraphView.cs index 8fc1a08..05928c2 100644 --- a/Sample/MathGraph/Editor/MathGraphView.cs +++ b/Sample/MathGraph/Editor/MathGraphView.cs @@ -1,8 +1,9 @@ using TNode.Models; using TNode.Attribute; -using TNode.Editor.BaseViews; +using TNodeGraphViewImpl.Editor.NodeGraphView; + [ViewComponent] -public class MathGraphView : DataGraphView{ +public class MathGraphView : BaseDataGraphView{ diff --git a/TNode/Attribute/Ports/InputAttribute.cs b/TNode/Attribute/Ports/InputAttribute.cs index dd4b855..e0d4b96 100644 --- a/TNode/Attribute/Ports/InputAttribute.cs +++ b/TNode/Attribute/Ports/InputAttribute.cs @@ -1,9 +1,7 @@ using System; using JetBrains.Annotations; -using TNode.Models; -using UnityEditor.Experimental.GraphView; -namespace TNode.Attribute{ +namespace TNode.Attribute.Ports{ [MeansImplicitUse] [AttributeUsage(AttributeTargets.Property, AllowMultiple = true)] public class InputAttribute : PortAttribute{ diff --git a/TNode/Attribute/Ports/PortAttribute.cs b/TNode/Attribute/Ports/PortAttribute.cs index 24feda5..cc3be06 100644 --- a/TNode/Attribute/Ports/PortAttribute.cs +++ b/TNode/Attribute/Ports/PortAttribute.cs @@ -1,8 +1,7 @@ using System; using JetBrains.Annotations; -using UnityEditor.Experimental.GraphView; -namespace TNode.Attribute{ +namespace TNode.Attribute.Ports{ public enum PortNameHandling{ Auto, diff --git a/TNode/Editor/BaseViews.meta b/TNode/Editor/BaseViews.meta deleted file mode 100644 index 54107dd..0000000 --- a/TNode/Editor/BaseViews.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: be6b702224dc40098aadadb3749d8c81 -timeCreated: 1655394343 \ No newline at end of file diff --git a/TNode/Editor/Cache/NodeEditorExtensions.cs b/TNode/Editor/Cache/NodeEditorExtensions.cs index f02c267..4f2de04 100644 --- a/TNode/Editor/Cache/NodeEditorExtensions.cs +++ b/TNode/Editor/Cache/NodeEditorExtensions.cs @@ -2,12 +2,12 @@ using System.Collections.Generic; using System.Linq; using TNode.Attribute; -using TNode.BaseViews; using TNode.Editor; -using TNode.Editor.BaseViews; -using TNode.Editor.GraphBlackboard; using TNode.Editor.Inspector; +using TNode.Editor.NodeViews; using TNode.Models; +using TNodeGraphViewImpl.Editor.GraphBlackboard; +using TNodeGraphViewImpl.Editor.NodeGraphView; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.TestTools.Utils; @@ -99,13 +99,13 @@ namespace TNode.Cache{ } } } - private readonly Type[] _acceptedTypesForGenericToSpecific = new Type[]{typeof(NodeView<>),typeof(DataGraphView<>),typeof(GraphBlackboardView<>)}; - private readonly Type[] _defaultTypes = new []{typeof(DefaultNodeView),typeof(DefaultGraphBlackboardView)}; + private readonly Type[] _acceptedTypesForGenericToSpecific = new Type[]{typeof(BaseNodeView<>),typeof(BaseDataGraphView<>),typeof(GraphBlackboardView<>)}; + private readonly Type[] _defaultTypes = new []{typeof(DefaultBaseNodeView),typeof(DefaultGraphBlackboardView)}; private void SetViewComponentAttribute(Type type){ foreach (var attribute in type.GetCustomAttributes(typeof(ViewComponentAttribute), false)){ //fetch this type 's parent class var parent = type.BaseType; - //Check if this type is a generic type and is a generic type of NodeView or DataGraphView, + //Check if this type is a generic type and is a generic type of BaseNodeView or BaseDataGraphView, //Two level generic definition is now supported by TNode //Deeper nested generic definition is not supported by TNode if (parent is{IsGenericType: true} && @@ -146,8 +146,8 @@ namespace TNode.Cache{ } //check if t is a generic type node view - if (t is{IsGenericType: true} && t.GetGenericTypeDefinition() == typeof(NodeView<>)){ - var instance = Activator.CreateInstance(typeof(NodeView)); + if (t is{IsGenericType: true} && t.GetGenericTypeDefinition() == typeof(BaseNodeView<>)){ + var instance = Activator.CreateInstance(typeof(BaseNodeView)); return instance; } return null; @@ -198,7 +198,7 @@ namespace TNode.Cache{ return null; } public static object CreateNodeViewFromNodeType(Type t){ - //Check the generic type of NodeView by t + //Check the generic type of BaseNodeView by t if (t.IsGenericType){ Debug.Log($"A generic type {t} is detected"); @@ -208,8 +208,8 @@ namespace TNode.Cache{ var genericTypeDefinition = t.GetGenericTypeDefinition(); - //What you want is a NodeView> to be created - var genericViewType = typeof(NodeView<>).MakeGenericType(genericTypeDefinition); + //What you want is a BaseNodeView> to be created + var genericViewType = typeof(BaseNodeView<>).MakeGenericType(genericTypeDefinition); Debug.Log($"The generic view type is {genericViewType}"); //search for the specific type of genericViewType in the dictionary @@ -226,11 +226,11 @@ namespace TNode.Cache{ } else{ - return new DefaultNodeView(); + return new DefaultBaseNodeView(); } } - var type = typeof(NodeView<>).MakeGenericType(t); + var type = typeof(BaseNodeView<>).MakeGenericType(t); if (NodeEditorSingleton.Instance.FromGenericToSpecific.ContainsKey(type)){ var implementedType = NodeEditorSingleton.Instance.FromGenericToSpecific[type]; @@ -239,7 +239,7 @@ namespace TNode.Cache{ } else{ - return new DefaultNodeView(); + return new DefaultBaseNodeView(); } } diff --git a/TNode/Editor/GraphBlackboard/BlackboardField.cs b/TNode/Editor/GraphBlackboard/BlackboardField.cs deleted file mode 100644 index 87f5d9d..0000000 --- a/TNode/Editor/GraphBlackboard/BlackboardField.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEditor.Experimental.GraphView; - -namespace TNode.Editor.GraphBlackboard{ - public class BlackboardPropertyField:BlackboardField{ - public BlackboardProperty BlackboardProperty; - public BlackboardPropertyField(BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){ - BlackboardProperty = blackboardProperty; - } - - - } -} \ No newline at end of file diff --git a/TNode/Editor/GraphEditor.cs b/TNode/Editor/GraphEditor.cs index 7d1b01a..93a272e 100644 --- a/TNode/Editor/GraphEditor.cs +++ b/TNode/Editor/GraphEditor.cs @@ -1,10 +1,9 @@ using Codice.CM.Common; -using TNode.BaseViews; using TNode.Cache; -using TNode.Editor.BaseViews; using TNode.Editor.Inspector; using TNode.Editor.Model; using TNode.Models; +using TNodeGraphViewImpl.Editor.NodeGraphView; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; @@ -15,7 +14,7 @@ namespace TNode.Editor{ public abstract class GraphEditor : EditorWindow where T:GraphData{ - protected DataGraphView _graphView; + protected BaseDataGraphView GraphView; [SerializeField] private VisualTreeAsset mVisualTreeAsset = default; //Persist editor data ,such as node position,node size ,etc ,in this script object @@ -36,9 +35,9 @@ namespace TNode.Editor{ } private void BuildGraphView(){ - _graphView = NodeEditorExtensions.CreateViewComponentFromBaseType>(); - rootVisualElement.Add(_graphView); - _graphView.StretchToParentSize(); + GraphView = NodeEditorExtensions.CreateViewComponentFromBaseType>(); + rootVisualElement.Add(GraphView); + GraphView.StretchToParentSize(); } private void DefineGraphEditorActions(){ @@ -54,7 +53,7 @@ namespace TNode.Editor{ private void Save(){ //if no graph is loaded ,create a file save dialogue - if (_graphView.Data == null) + if (GraphView.Data == null) { string path = EditorUtility.SaveFilePanel("Save Graph", "", "", "asset"); if (path.Length != 0){ @@ -66,7 +65,7 @@ namespace TNode.Editor{ } } else{ - _graphView.SaveWithEditorData(graphEditorData); + GraphView.SaveWithEditorData(graphEditorData); AssetDatabase.Refresh(); } diff --git a/TNode/Editor/Inspector/InspectorImplementation.meta b/TNode/Editor/Inspector/InspectorImplementation.meta deleted file mode 100644 index d8de6bd..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 4cdebd0430794d32918ba8c63d71d0cc -timeCreated: 1656142311 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs b/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs deleted file mode 100644 index 362d8f7..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using TNode.Attribute; -using UnityEngine; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector.InspectorImplementation{ - [ViewComponent] - [Obsolete] - public class EnumFieldItem:InspectorItem{ - public EnumFieldItem() : base(){ - var field = new EnumField(); - Debug.Log("An Enum Field is created"); - CreateBindable(field); - OnDataChanged += () => { - - field.Init(Value); - Debug.Log(Value.GetType()); - }; - } - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs.meta b/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs.meta deleted file mode 100644 index 1a83a95..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/EnumFieldItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6eb83a1255d545e5998c7b3efd1b0d69 -timeCreated: 1657193097 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs b/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs deleted file mode 100644 index 5cbda65..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using TNode.Attribute; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector.InspectorImplementation{ - [Obsolete] - [ViewComponent] - public class FloatFieldItem:InspectorItem{ - public FloatFieldItem():base(){ - CreateBindable(new FloatField()); - } - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs.meta b/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs.meta deleted file mode 100644 index 170c2d3..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/FloatFieldItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 932de5e7a487475aa764dd819cc33aa0 -timeCreated: 1656583186 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs b/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs deleted file mode 100644 index b1d6a01..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using UnityEditor; -using UnityEditor.UIElements; -using UnityEngine.UIElements; -using Object = UnityEngine.Object; - -namespace TNode.Editor.Inspector.InspectorImplementation{ - [Obsolete] - public class PropertyFieldItem:InspectorItem{ - - public PropertyFieldItem(){ - - - OnDataChanged += () => { - var data = new SerializedObject(Value as Object); - var testProperty = data.GetIterator().GetArrayElementAtIndex(0); - PropertyField propertyField = new PropertyField(testProperty); - this.Q()?.RemoveFromHierarchy(); - this.Add(propertyField); - - }; - } - - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta b/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta deleted file mode 100644 index bced887..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/PropertyFieldItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 98769c8b285d438197820fa366568fee -timeCreated: 1657280625 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs b/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs deleted file mode 100644 index a065a9a..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using TNode.Attribute; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector.InspectorImplementation{ - [Obsolete] - /// - /// Force these element to bind native c# property - /// - [ViewComponent] - public class StringFieldItem:InspectorItem{ - public StringFieldItem():base(){ - CreateBindable(new TextField()); - } - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs.meta b/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs.meta deleted file mode 100644 index c837e6d..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/StringFieldItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 6b4f88e6c094449280ba5e38cb508287 -timeCreated: 1656143219 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs b/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs deleted file mode 100644 index 41c0328..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using TNode.Attribute; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector.InspectorImplementation{ - [Obsolete] - [ViewComponent] - public class ToggleFieldItem:InspectorItem{ - public ToggleFieldItem(){ - CreateBindable(new Toggle()); - } - - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs.meta b/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs.meta deleted file mode 100644 index 7ab36a8..0000000 --- a/TNode/Editor/Inspector/InspectorImplementation/ToggleFieldItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: d009d4819d604971976932b1d8f40bad -timeCreated: 1656580623 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorItem.cs b/TNode/Editor/Inspector/InspectorItem.cs deleted file mode 100644 index 1575c7c..0000000 --- a/TNode/Editor/Inspector/InspectorItem.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using TNode.BaseViews; -using TNode.Models; -using UnityEngine; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector{ - [Obsolete] - public abstract class InspectorItem:VisualElement,INodeDataBinding { - protected NodeData _bindingNodeData; - protected string _bindingFieldName; - protected BaseField Bindable; - protected event System.Action OnDataChanged; - - public string BindingPath{ - get => _bindingFieldName; - set{ - _bindingFieldName = value; - if(_bindingFieldName!=null&&_bindingNodeData!=null){ - OnDataChanged?.Invoke(); - } - } - } - - public NodeData BindingNodeData{ - get => _bindingNodeData; - set{ - var oldWrapper = ((NodeDataWrapper) _bindingNodeData); - if(oldWrapper!=null){ - oldWrapper.OnValueChanged -= OnNodeDataValueChanged; - } - _bindingNodeData = value; - if(_bindingFieldName!=null&&_bindingNodeData!=null){ - OnDataChanged?.Invoke(); - } - if(_bindingNodeData!=null) - ((NodeDataWrapper) _bindingNodeData).OnValueChanged += OnNodeDataValueChanged; - } - } - - private T GetValue(){ - - var fieldInfo = _bindingNodeData.GetType().GetField(BindingPath, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance); - if (fieldInfo == null){ - throw new Exception("Null field info"); - } - if (fieldInfo.FieldType == typeof(T)){ - return (T)fieldInfo.GetValue(BindingNodeData); - } - - if (fieldInfo.FieldType.IsEnum){ - return (T)fieldInfo.GetValue(BindingNodeData); - } - Debug.LogError("Wrong Type for current node data"); - return default; - } - - protected T Value => GetValue(); - - protected void SetValue(T value){ - NodeDataWrapper wrapper = _bindingNodeData; - wrapper.SetValue(BindingPath,value); - } - public InspectorItem(){ - - OnDataChanged+= OnDataChangedHandler; - } - /* - * e => { - SetValue(e.newValue); - } - */ - private void OnInspectorItemValueChanged(ChangeEvent e){ - SetValue(e.newValue); - } - - public void CreateBindable(BaseField bindable){ - if (Bindable != null){ - Bindable.Clear(); - Bindable.UnregisterValueChangedCallback(OnInspectorItemValueChanged); - } - Bindable = bindable; - Add(Bindable); - Bindable?.RegisterValueChangedCallback(OnInspectorItemValueChanged); - } - private void OnDataChangedHandler(){ - Bindable = this.Q>(); - if(Bindable!= null){ - Bindable.value = Value; - Bindable.label = BindingPath; - } - } - - private void OnNodeDataValueChanged(NodeDataWrapper wrapper){ - var value = (T) wrapper.GetValue(BindingPath) ; - if(Bindable!=null){ - Bindable.value = value; - } - } - - ~InspectorItem(){ - OnDataChanged-= OnDataChangedHandler; - } - } -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorItem.cs.meta b/TNode/Editor/Inspector/InspectorItem.cs.meta deleted file mode 100644 index 9008d3f..0000000 --- a/TNode/Editor/Inspector/InspectorItem.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 82902f281e4642f2be8b742866d38839 -timeCreated: 1656126272 \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorItemFactory.cs b/TNode/Editor/Inspector/InspectorItemFactory.cs deleted file mode 100644 index 4a97483..0000000 --- a/TNode/Editor/Inspector/InspectorItemFactory.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using TNode.Cache; -using TNode.Editor.Inspector.InspectorImplementation; -using Unity.VisualScripting; -using UnityEditor; -using UnityEngine; -using UnityEngine.UIElements; - -namespace TNode.Editor.Inspector{ - [Obsolete] - public class InspectorItemFactory{ - - public InspectorItem Create(){ - //Check type of GraphDataType - var hasSpecificType = NodeEditorExtensions.HasSpecificTypeComponent>(); - - if (hasSpecificType){ - return NodeEditorExtensions.CreateViewComponentFromBaseType>(); - } - - if (typeof(T).IsEnum){ - - return NodeEditorExtensions.CreateViewComponentFromBaseType(typeof(InspectorItem)) as InspectorItem; - } - return null; - } - - public INodeDataBindingBase Create(Type t){ - var genericType = typeof(InspectorItem<>).MakeGenericType(t); - var hasSpecificType = NodeEditorExtensions.HasSpecificTypeComponent(genericType); - - if (hasSpecificType){ - return NodeEditorExtensions.CreateViewComponentFromBaseType(genericType) as INodeDataBindingBase; - } - - if (t.IsEnum){ - - return NodeEditorExtensions.CreateViewComponentFromBaseType(typeof(InspectorItem)) as INodeDataBindingBase; - } - return null; - } - - } -} - \ No newline at end of file diff --git a/TNode/Editor/Inspector/InspectorItemFactory.cs.meta b/TNode/Editor/Inspector/InspectorItemFactory.cs.meta deleted file mode 100644 index f9838bb..0000000 --- a/TNode/Editor/Inspector/InspectorItemFactory.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 83b9e37f79cf4a18b265e3e22e7e3ced -timeCreated: 1656142463 \ No newline at end of file diff --git a/TNode/Editor/Inspector/MonoScriptInspector.cs b/TNode/Editor/Inspector/MonoScriptInspector.cs deleted file mode 100644 index a06049a..0000000 --- a/TNode/Editor/Inspector/MonoScriptInspector.cs +++ /dev/null @@ -1,16 +0,0 @@ -using UnityEditor; -using UnityEditor.AssetImporters; -using UnityEngine; - -namespace TNode.Editor.Inspector{ - // [CustomEditor(typeof(MonoImporter))] - // public class MonoScriptInspector:AssetImporterEditor{ - // public override void OnInspectorGUI(){ - // base.OnInspectorGUI(); - // if(GUILayout.Button("Open")){ - // EditorUtility.OpenWithDefaultApp(AssetDatabase.GetAssetPath(target)); - // } - // } - // } - // -} \ No newline at end of file diff --git a/TNode/Editor/Inspector/MonoScriptInspector.cs.meta b/TNode/Editor/Inspector/MonoScriptInspector.cs.meta deleted file mode 100644 index 9441899..0000000 --- a/TNode/Editor/Inspector/MonoScriptInspector.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 192a51f6578144c5bbddb5cf77685c71 -timeCreated: 1656214219 \ No newline at end of file diff --git a/TNode/Editor/Inspector/PropertyDrawer.meta b/TNode/Editor/Inspector/PropertyDrawer.meta deleted file mode 100644 index 196eeba..0000000 --- a/TNode/Editor/Inspector/PropertyDrawer.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: cc8c20a304714599959643305857c804 -timeCreated: 1657486909 \ No newline at end of file diff --git a/TNode/Editor/Manipulators.meta b/TNode/Editor/Manipulators.meta deleted file mode 100644 index f9c9614..0000000 --- a/TNode/Editor/Manipulators.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 400542f3cec140e2b55e2bcf637b2d9b -timeCreated: 1657009018 \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView.meta b/TNode/Editor/NodeGraphView.meta new file mode 100644 index 0000000..007e02c --- /dev/null +++ b/TNode/Editor/NodeGraphView.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9e377285943b43278ea539231483fe6f +timeCreated: 1657683945 \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs new file mode 100644 index 0000000..e851505 --- /dev/null +++ b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs @@ -0,0 +1,11 @@ +using TNode.Models; +using UnityEngine; + +namespace TNode.Editor.NodeGraphView{ + public interface IBaseDataGraphView{ + public void AddTNode(NodeData nodeData, Rect rect); + public void RemoveTNode(NodeData nodeData); + + public BlackboardData GetBlackboardData(); + } +} \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs.meta b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs.meta new file mode 100644 index 0000000..fada334 --- /dev/null +++ b/TNode/Editor/NodeGraphView/IBaseDataGraphView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 9839105141d14b3aac3891bcaaa3fe50 +timeCreated: 1657684189 \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView/IDataGraphView.cs b/TNode/Editor/NodeGraphView/IDataGraphView.cs new file mode 100644 index 0000000..db2d69b --- /dev/null +++ b/TNode/Editor/NodeGraphView/IDataGraphView.cs @@ -0,0 +1,7 @@ +using TNode.Models; + +namespace TNode.Editor.NodeGraphView{ + public interface IDataGraphView : IBaseDataGraphView where T:GraphData{ + + } +} \ No newline at end of file diff --git a/TNode/Editor/NodeGraphView/IDataGraphView.cs.meta b/TNode/Editor/NodeGraphView/IDataGraphView.cs.meta new file mode 100644 index 0000000..9b4ddd6 --- /dev/null +++ b/TNode/Editor/NodeGraphView/IDataGraphView.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b0f8421124864a7d993bcbfb419987dd +timeCreated: 1657684182 \ No newline at end of file diff --git a/TNode/Editor/NodeViews/DefaultNodeView.cs b/TNode/Editor/NodeViews/DefaultNodeView.cs deleted file mode 100644 index 10f4713..0000000 --- a/TNode/Editor/NodeViews/DefaultNodeView.cs +++ /dev/null @@ -1,11 +0,0 @@ -using TNode.BaseViews; -using TNode.Editor.BaseViews; -using TNode.Models; - -namespace TNode.Editor{ - - - public class DefaultNodeView:NodeView{ - - } -} \ No newline at end of file diff --git a/TNodeGraphViewImpl.meta b/TNodeGraphViewImpl.meta new file mode 100644 index 0000000..b9e7a1d --- /dev/null +++ b/TNodeGraphViewImpl.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 792d2c6b4dca441981787b922b385f0a +timeCreated: 1657684260 \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor.meta b/TNodeGraphViewImpl/Editor.meta new file mode 100644 index 0000000..dabd39a --- /dev/null +++ b/TNodeGraphViewImpl/Editor.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1e6ee4cc74d84496a099ac0624bda536 +timeCreated: 1657684324 \ No newline at end of file diff --git a/TNode/Editor/GraphBlackboard.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard.meta similarity index 100% rename from TNode/Editor/GraphBlackboard.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard.meta diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs new file mode 100644 index 0000000..93470ef --- /dev/null +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs @@ -0,0 +1,12 @@ +using UnityEditor.Experimental.GraphView; + +namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ + public class BlackboardPropertyField:BlackboardField{ + public BlackboardProperty.BlackboardProperty BlackboardProperty; + public BlackboardPropertyField(BlackboardProperty.BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){ + BlackboardProperty = blackboardProperty; + } + + + } +} \ No newline at end of file diff --git a/TNode/Editor/GraphBlackboard/BlackboardField.cs.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs.meta similarity index 100% rename from TNode/Editor/GraphBlackboard/BlackboardField.cs.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs.meta diff --git a/TNode/Editor/GraphBlackboard/BlackboardProperty.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty.meta similarity index 100% rename from TNode/Editor/GraphBlackboard/BlackboardProperty.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty.meta diff --git a/TNode/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs similarity index 85% rename from TNode/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs rename to TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs index d7dff1a..eaa5f89 100644 --- a/TNode/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs @@ -1,6 +1,6 @@ using System; -namespace TNode.Editor.GraphBlackboard{ +namespace TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty{ public class BlackboardProperty{ public string PropertyName; public Type PropertyType; diff --git a/TNode/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta similarity index 100% rename from TNode/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs.meta diff --git a/TNode/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs similarity index 86% rename from TNode/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs rename to TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs index 26c98c2..2ed561f 100644 --- a/TNode/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs @@ -1,7 +1,7 @@ using TNode.Attribute; using TNode.Models; -namespace TNode.Editor.GraphBlackboard{ +namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ [ViewComponent] public class DefaultGraphBlackboardView:GraphBlackboardView{ public DefaultGraphBlackboardView(){ diff --git a/TNode/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta similarity index 100% rename from TNode/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs.meta diff --git a/TNode/Editor/GraphBlackboard/GraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs similarity index 87% rename from TNode/Editor/GraphBlackboard/GraphBlackboardView.cs rename to TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs index a59ce41..05fe3f5 100644 --- a/TNode/Editor/GraphBlackboard/GraphBlackboardView.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs @@ -1,7 +1,7 @@ using TNode.Models; using UnityEditor.Experimental.GraphView; -namespace TNode.Editor.GraphBlackboard{ +namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ /// /// Implement this class to create graph black board for specified graph /// diff --git a/TNode/Editor/GraphBlackboard/GraphBlackboardView.cs.meta b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs.meta similarity index 100% rename from TNode/Editor/GraphBlackboard/GraphBlackboardView.cs.meta rename to TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs.meta diff --git a/TNodeGraphViewImpl/Editor/Inspector.meta b/TNodeGraphViewImpl/Editor/Inspector.meta new file mode 100644 index 0000000..11bcf1a --- /dev/null +++ b/TNodeGraphViewImpl/Editor/Inspector.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 152e46659fee4d2fb09bc06f18d54c98 +timeCreated: 1657684641 \ No newline at end of file diff --git a/TNode/Editor/Inspector/NodeInspector.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs similarity index 61% rename from TNode/Editor/Inspector/NodeInspector.cs rename to TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs index 1d2c516..0367625 100644 --- a/TNode/Editor/Inspector/NodeInspector.cs +++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs @@ -2,9 +2,9 @@ using System.Collections.Generic; using System.Reflection; using TNode.Attribute; -using TNode.BaseViews; -using TNode.Editor.BaseViews; +using TNode.Editor.NodeViews; using TNode.Models; +using TNodeGraphViewImpl.Editor.NodeGraphView; using Unity.VisualScripting; using UnityEditor; using UnityEditor.Experimental.GraphView; @@ -24,7 +24,7 @@ namespace TNode.Editor.Inspector{ } } - public INodeView NodeView; + public IBaseNodeView BaseNodeView; private void UpdateData(){ Debug.Log(_data); if (_data != null){ @@ -46,18 +46,18 @@ namespace TNode.Editor.Inspector{ var body = this.Q("InspectorBody"); body.Clear(); body.StretchToParentSize(); - foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ - var bindingPath = field.Name; - var type = field.FieldType; - InspectorItemFactory inspectorItemFactory = new InspectorItemFactory(); - //Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection - var createdItem = inspectorItemFactory.Create(type); - if (createdItem is { } castedItem){ - castedItem.BindingNodeData = _data; - castedItem.BindingPath = bindingPath; - } - Add((VisualElement)createdItem); - } + // foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ + // var bindingPath = field.Name; + // var type = field.FieldType; + // InspectorItemFactory inspectorItemFactory = new InspectorItemFactory(); + // //Invoke generic function Create<> of default inspector item factory to create an inspector item of appropriate type by reflection + // var createdItem = inspectorItemFactory.Create(type); + // if (createdItem is { } castedItem){ + // castedItem.BindingNodeData = _data; + // castedItem.BindingPath = bindingPath; + // } + // Add((VisualElement)createdItem); + // } } } } \ No newline at end of file diff --git a/TNode/Editor/Inspector/NodeInspector.cs.meta b/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs.meta similarity index 100% rename from TNode/Editor/Inspector/NodeInspector.cs.meta rename to TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs.meta diff --git a/TNode/Editor/Inspector/NodeInspectorInNode.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs similarity index 67% rename from TNode/Editor/Inspector/NodeInspectorInNode.cs rename to TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs index 8a0bc88..de375a1 100644 --- a/TNode/Editor/Inspector/NodeInspectorInNode.cs +++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs @@ -40,9 +40,6 @@ namespace TNode.Editor.Inspector{ if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData<>))){ return; } - - - var serializedObject = new SerializedObject((NodeDataWrapper)_data); foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public|BindingFlags.NonPublic)){ //Create corresponding property field @@ -53,28 +50,8 @@ namespace TNode.Editor.Inspector{ var drawer = new PropertyField(serializedObject.FindProperty("Data").FindPropertyRelative(field.Name),field.Name); Debug.Log(serializedObject.FindProperty("Data")); drawer.Bind(serializedObject); - Add(drawer); } } - - private void RefreshItems(){ - InspectorItemFactory inspectorItemFactory = new InspectorItemFactory(); - foreach (var field in _data.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public)){ - var bindingPath = field.Name; - var type = field.FieldType; - //check if the field has ShowInNodeView attribute - var showInNodeViewAttribute = field.GetCustomAttribute() != null; - if (!showInNodeViewAttribute) - continue; - var createdItem = inspectorItemFactory.Create(type); - if (createdItem is{ } castedItem){ - castedItem.BindingNodeData = _data; - castedItem.BindingPath = bindingPath; - } - - Add((VisualElement) createdItem); - } - } } } \ No newline at end of file diff --git a/TNode/Editor/Inspector/NodeInspectorInNode.cs.meta b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs.meta similarity index 100% rename from TNode/Editor/Inspector/NodeInspectorInNode.cs.meta rename to TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs.meta diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView.meta b/TNodeGraphViewImpl/Editor/NodeGraphView.meta new file mode 100644 index 0000000..eb09718 --- /dev/null +++ b/TNodeGraphViewImpl/Editor/NodeGraphView.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 509019c594fa494dba98f9910092b63e +timeCreated: 1657684502 \ No newline at end of file diff --git a/TNode/Editor/BaseViews/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs similarity index 74% rename from TNode/Editor/BaseViews/DataGraphView.cs rename to TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index ff2decd..bcc280c 100644 --- a/TNode/Editor/BaseViews/DataGraphView.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -3,116 +3,25 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; -using TNode.BaseViews; using TNode.Cache; -using TNode.Editor.GraphBlackboard; +using TNode.Editor; using TNode.Editor.Inspector; using TNode.Editor.Model; +using TNode.Editor.NodeGraphView; +using TNode.Editor.NodeViews; using TNode.Editor.Search; using TNode.Editor.Tools.NodeCreator; using TNode.Models; -using Unity.VisualScripting; +using TNodeGraphViewImpl.Editor.GraphBlackboard; +using TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; using Edge = UnityEditor.Experimental.GraphView.Edge; -namespace TNode.Editor.BaseViews{ - /* - public class DialogueGraphView : DataGraphView{ - public Action onNodeAdded; - public Action onNodeSelected; - public Action onNodeRemoved; - public Action onNodeUnselected; - // public DialogueGraphView(DialogueGraph graph):base(){ - // this.Data = graph; - // - // //Set background to a bit of darker - // - // - // //Register a data context change callback - // - // } - - public override void OnGraphViewCreate(){ - AddNode(GenerateEntryPoint()); - RegisterCallback(evt => { - var pos = evt.mousePosition; - - evt.menu.AppendAction("Add NodeAttribute", (dropMenuAction) => { - DialogueNodeView nodeView = new DialogueNodeView{ - GUID = Guid.NewGuid().ToString(), - title = "New NodeAttribute" - }; - // make it a 200x100 box - nodeView.SetPosition(new Rect(pos.x - 100, pos.y - 50, 200, 100)); - - - AddNode(nodeView); - }, DropdownMenuAction.AlwaysEnabled); - }); - this.OnDataChanged += OnOnDataChanged; - } - private void OnOnDataChanged(object sender, DataChangedEventArgs e){ - //clean all nodes from the graphview - foreach (var graphViewNode in nodes){ - RemoveElement(graphViewNode); - } - - foreach (var edge in edges){ - RemoveElement(edge); - } - //add all nodes from the new graph - foreach (var node in e.NewData.nodes){ - //AddNode(node); - } - } - - public void AddNode(DialogueNodeData dialogueNodeData){ - var res = InstantiateFromDialogueNodeData(dialogueNodeData); - AddNode(res); - } - public void AddNode(DialogueNodeView nodeView){ - AddElement(nodeView); - onNodeAdded?.Invoke(nodeView); - //Register nodeView selection callback - nodeView.RegisterCallback(evt => { - if (evt.clickCount == 1){ - onNodeSelected?.Invoke(nodeView); - } - }); - nodeView.OnUnselect += () => { onNodeUnselected?.Invoke(nodeView); }; - } - - public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter) => this.ports.ToList() - .Where(x => x != startPort && - x.direction != startPort.direction).ToList(); - - public DialogueNodeView GenerateEntryPoint(){ - var entryPoint = new DialogueNodeView{ - title = "Entry Point", - GUID = Guid.NewGuid().ToString(), - EntryPoint = true - }; - //Add output port to the nodeView - entryPoint.AddPort(Orientation.Horizontal, Direction.Output, "Next"); - //Set nodeView position to top center side of screen - entryPoint.SetPosition(new Rect(this.layout.width / 2 - 100, 0, 200, 200)); - return entryPoint; - } - protected DialogueNodeView InstantiateFromDialogueNodeData(DialogueNodeData dialogueNodeData){ - var node = new DialogueNodeView(); - node.title = dialogueNodeData.nodeName; - node.GUID = Guid.NewGuid().ToString(); - //TODO:after completing the separation of the node data and the node editor data,this should be switch to the node editor data - //node.SetPosition(dialogueNodeData.rect); - this.AddNode(node); - return node; - } - } - */ - public abstract class DataGraphView:GraphView,IDataGraphView where T:GraphData{ +namespace TNodeGraphViewImpl.Editor.NodeGraphView{ + public abstract class BaseDataGraphView:GraphView,IBaseDataGraphView where T:GraphData{ #region variables and properties private T _data; private bool _isInspectorOn; @@ -138,11 +47,11 @@ namespace TNode.Editor.BaseViews{ #endregion - //A Constructor for the DataGraphView ,never to override it + //A Constructor for the BaseDataGraphView ,never to override it #region construct default behaviour - public DataGraphView(){ + public BaseDataGraphView(){ styleSheets.Add(Resources.Load("GraphViewBackground")); var grid = new GridBackground(); Insert(0,grid); @@ -350,7 +259,7 @@ namespace TNode.Editor.BaseViews{ var nodeEditorData = new GraphElementEditorData{ pos = node.GetPosition(), }; - if (node is INodeView nodeView){ + if (node is IBaseNodeView nodeView){ nodeEditorData.guid = nodeView.GetNodeData().id; } graphEditorData.graphElementsData.Add(nodeEditorData); @@ -366,7 +275,7 @@ namespace TNode.Editor.BaseViews{ private void SaveNode(){ foreach (var node in nodes){ - if (node is INodeView nodeView){ + if (node is IBaseNodeView nodeView){ var nodeData = nodeView.GetNodeData(); if (!_data.NodeDictionary.ContainsKey(nodeData.id)){ _data.NodeDictionary.Add(nodeData.id, nodeData); @@ -377,8 +286,8 @@ namespace TNode.Editor.BaseViews{ private void SaveEdge(){ var links = new List(); foreach (var edge in edges){ - var inputNode = edge.input.node as INodeView; - var outputNode = edge.output.node as INodeView; + var inputNode = edge.input.node as IBaseNodeView; + var outputNode = edge.output.node as IBaseNodeView; if (inputNode != null && outputNode != null){ var inputNodeData = inputNode.GetNodeData(); var outputNodeData = outputNode.GetNodeData(); @@ -417,7 +326,7 @@ namespace TNode.Editor.BaseViews{ public virtual void OnGraphViewDestroy(){ } - ~DataGraphView(){ + ~BaseDataGraphView(){ OnGraphViewDestroy(); } @@ -434,11 +343,11 @@ namespace TNode.Editor.BaseViews{ if (evt.clickCount == 1){ if (_isInspectorOn){ _nodeInspector.Data = nodeData; - _nodeInspector.NodeView = nodeView as INodeView; + _nodeInspector.BaseNodeView = nodeView as IBaseNodeView; } } }); - if(nodeView is INodeView nodeViewInterface){ + if(nodeView is IBaseNodeView nodeViewInterface){ nodeViewInterface.SetNodeData(nodeData); } _nodeDict.Add(nodeData.id, nodeView); @@ -448,7 +357,7 @@ namespace TNode.Editor.BaseViews{ var menu = new GenericMenu(); menu.AddItem(new GUIContent("Delete"), false, () => { RemoveElement(nodeView); - if (nodeView is INodeView tNodeView){ + if (nodeView is IBaseNodeView tNodeView){ RemoveTNode(tNodeView.GetNodeData()); } }); @@ -477,12 +386,6 @@ namespace TNode.Editor.BaseViews{ } } - public interface IDataGraphView{ - public void AddTNode(NodeData nodeData, Rect rect); - public void RemoveTNode(NodeData nodeData); - - public BlackboardData GetBlackboardData(); - } public class DataChangedEventArgs{ public DataChangedEventArgs(T data){ diff --git a/TNode/Editor/BaseViews/DataGraphView.cs.meta b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs.meta similarity index 100% rename from TNode/Editor/BaseViews/DataGraphView.cs.meta rename to TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs.meta diff --git a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs similarity index 97% rename from TNode/Editor/BaseViews/SimpleGraphSubWindow.cs rename to TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs index da03952..da69ff1 100644 --- a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs @@ -5,7 +5,7 @@ using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine.UIElements; -namespace TNode.BaseViews{ +namespace TNodeGraphViewImpl.Editor.NodeGraphView{ public class SimpleGraphSubWindow:GraphElement,IGraphViewPersistence{ private readonly Dragger _dragger = new Dragger(); diff --git a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs.meta b/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs.meta similarity index 100% rename from TNode/Editor/BaseViews/SimpleGraphSubWindow.cs.meta rename to TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs.meta diff --git a/TNode/Editor/NodeViews.meta b/TNodeGraphViewImpl/Editor/NodeViews.meta similarity index 100% rename from TNode/Editor/NodeViews.meta rename to TNodeGraphViewImpl/Editor/NodeViews.meta diff --git a/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs new file mode 100644 index 0000000..caec25e --- /dev/null +++ b/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs @@ -0,0 +1,10 @@ +using TNode.Editor.NodeViews; +using TNode.Models; + +namespace TNode.Editor{ + + + public class DefaultBaseNodeView:BaseNodeView{ + + } +} \ No newline at end of file diff --git a/TNode/Editor/NodeViews/DefaultNodeView.cs.meta b/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs.meta similarity index 100% rename from TNode/Editor/NodeViews/DefaultNodeView.cs.meta rename to TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs.meta diff --git a/TNode/Editor/NodeViews/DragNodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs similarity index 65% rename from TNode/Editor/NodeViews/DragNodeView.cs rename to TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs index 5502fcc..dbcd21c 100644 --- a/TNode/Editor/NodeViews/DragNodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs @@ -1,11 +1,10 @@ using TNode.Attribute; -using TNode.Editor.BaseViews; using TNode.Models; namespace TNode.Editor.NodeViews{ [ViewComponent] - public class DragNodeView:NodeView>{ - public DragNodeView() : base(){ + public class DragBaseNodeView:BaseNodeView>{ + public DragBaseNodeView() : base(){ //Make capsule like style this.titleContainer.visible = false; diff --git a/TNode/Editor/NodeViews/DragNodeView.cs.meta b/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs.meta similarity index 100% rename from TNode/Editor/NodeViews/DragNodeView.cs.meta rename to TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs.meta diff --git a/TNode/Editor/NodeViews/NodeView.cs b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs similarity index 94% rename from TNode/Editor/NodeViews/NodeView.cs rename to TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs index 0079cb6..5cdc716 100644 --- a/TNode/Editor/NodeViews/NodeView.cs +++ b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs @@ -5,17 +5,13 @@ using TNode.Attribute; using TNode.Attribute.Ports; using TNode.Editor.Inspector; using TNode.Models; -using UnityEditor; using UnityEditor.Experimental.GraphView; -using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace TNode.Editor.BaseViews{ +namespace TNode.Editor.NodeViews{ - //A NodeAttribute monitor some type of node in the graph - - public abstract class NodeView : Node,INodeView where T:NodeData,new(){ + public abstract class BaseNodeView : Node,INodeView where T:NodeData,new(){ protected T _data; private readonly NodeInspectorInNode _nodeInspectorInNode; @@ -42,7 +38,7 @@ namespace TNode.Editor.BaseViews{ } public event System.Action OnDataChanged; - protected NodeView(){ + protected BaseNodeView(){ OnDataChanged+=OnDataChangedHandler; _nodeInspectorInNode = new NodeInspectorInNode(){ @@ -69,10 +65,8 @@ namespace TNode.Editor.BaseViews{ switch (portAttribute.NameHandling){ case PortNameHandling.Auto: return portAttribute.Name.Trim(' ').Length>0?portAttribute.Name:propertyInfo.Name; - break; case PortNameHandling.Manual: return portAttribute.Name; - break; case PortNameHandling.MemberName: return propertyInfo.Name; case PortNameHandling.Format: @@ -169,11 +163,15 @@ namespace TNode.Editor.BaseViews{ } } - public interface INodeView{ + public interface IBaseNodeView{ public void SetNodeData(NodeData nodeData); public NodeData GetNodeData(); - public void OnDataModified(); } + + public interface INodeView:IBaseNodeView where T:NodeData,new(){ + public T Data{ get; set; } + + } } \ No newline at end of file diff --git a/TNode/Editor/NodeViews/NodeView.cs.meta b/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs.meta similarity index 100% rename from TNode/Editor/NodeViews/NodeView.cs.meta rename to TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs.meta diff --git a/TNode/Editor/Search.meta b/TNodeGraphViewImpl/Editor/Search.meta similarity index 100% rename from TNode/Editor/Search.meta rename to TNodeGraphViewImpl/Editor/Search.meta diff --git a/TNode/Editor/Search/BlackboardSearchWindowProvider.cs b/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs similarity index 93% rename from TNode/Editor/Search/BlackboardSearchWindowProvider.cs rename to TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs index dfec7a4..ac91d2e 100644 --- a/TNode/Editor/Search/BlackboardSearchWindowProvider.cs +++ b/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs @@ -1,7 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; -using TNode.Editor.BaseViews; +using TNode.Editor.NodeGraphView; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; @@ -9,7 +9,7 @@ using UnityEngine; namespace TNode.Editor.Search{ public class BlackboardSearchWindowProvider:ScriptableObject,ISearchWindowProvider{ private Type _graphType; - private IDataGraphView _graphView; + private IBaseDataGraphView _graphView; private EditorWindow _editor; private struct InternalSearchTreeUserData{ @@ -60,7 +60,7 @@ namespace TNode.Editor.Search{ return false; } - public void Setup(Type graph,IDataGraphView graphView,EditorWindow editor){ + public void Setup(Type graph,IBaseDataGraphView graphView,EditorWindow editor){ _graphType = graph; _graphView = graphView; _editor = editor; diff --git a/TNode/Editor/Search/BlackboardSearchWindowProvider.cs.meta b/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs.meta similarity index 100% rename from TNode/Editor/Search/BlackboardSearchWindowProvider.cs.meta rename to TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs.meta diff --git a/TNode/Editor/Search/NodeSearchWindowProvider.cs b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs similarity index 93% rename from TNode/Editor/Search/NodeSearchWindowProvider.cs rename to TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs index 55ec5ff..058d07b 100644 --- a/TNode/Editor/Search/NodeSearchWindowProvider.cs +++ b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using TNode.Cache; -using TNode.Editor.BaseViews; +using TNode.Editor.NodeGraphView; using TNode.Editor.Tools.NodeCreator; using TNode.Models; using UnityEditor; @@ -48,7 +48,7 @@ namespace TNode.Editor.Search{ //Make an instance of the type if (NodeCreator.InstantiateNodeData(type) is { } nodeData){ nodeData.nodeName = $"New {type.Name}"; - ((IDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100)); + ((IBaseDataGraphView) _graphView).AddTNode(nodeData, new Rect(localPos.x, localPos.y, 100, 100)); } } return true; diff --git a/TNode/Editor/Search/NodeSearchWindowProvider.cs.meta b/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs.meta similarity index 100% rename from TNode/Editor/Search/NodeSearchWindowProvider.cs.meta rename to TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs.meta