diff --git a/Resources.meta b/Resources.meta deleted file mode 100644 index d428cde..0000000 --- a/Resources.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 630fb8569cca3804a80f2fb55f7890f2 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Resources/Newtonsoft.Json-for-Unity.Converters.asset b/Resources/Newtonsoft.Json-for-Unity.Converters.asset deleted file mode 100644 index b01ce28..0000000 --- a/Resources/Newtonsoft.Json-for-Unity.Converters.asset +++ /dev/null @@ -1,162 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: ce56e4dbb13e1644aa983b6dd170e4a7, type: 3} - m_Name: Newtonsoft.Json-for-Unity.Converters - m_EditorClassIdentifier: - useUnityContractResolver: 1 - useAllOutsideConverters: 0 - outsideConverters: - - enabled: 0 - converterName: TNode.JsonSerialize.NodeDataConverter - settings: [] - - enabled: 0 - converterName: TNode.JsonSerialize.UnityObjectConverter - settings: [] - - enabled: 0 - converterName: TNode.JsonSerialize.Vector3Converter - settings: [] - useAllUnityConverters: 1 - unityConverters: - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.AI.NavMesh.NavMeshQueryFilterConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.AI.NavMesh.NavMeshTriangulationConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Camera.CullingGroupEventConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.BoundsConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.BoundsIntConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.PlaneConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.RectConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.RectIntConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Geometry.RectOffsetConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Hashing.Hash128Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Color32Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.ColorConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Matrix4x4Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.QuaternionConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.SphericalHarmonicsL2Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Vector2Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Vector2IntConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Vector3Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Vector3IntConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Math.Vector4Converter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.NativeArray.NativeArrayConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Physics.JointDriveConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Physics.JointLimitsConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Physics.SoftJointLimitConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Physics2D.ColliderDistance2DConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Physics2D.ContactFilter2DConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Random.RandomStateConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Scripting.LayerMaskConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.UnityConverters.Scripting.RangeIntConverter - settings: [] - useAllJsonNetConverters: 1 - jsonNetConverters: - - enabled: 1 - converterName: Newtonsoft.Json.Converters.StringEnumConverter - settings: [] - - enabled: 1 - converterName: Newtonsoft.Json.Converters.VersionConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.BinaryConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.BsonObjectIdConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.DataSetConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.DataTableConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.DiscriminatedUnionConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.EntityKeyMemberConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.ExpandoObjectConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.IsoDateTimeConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.JavaScriptDateTimeConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.KeyValuePairConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.RegexConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.UnixDateTimeConverter - settings: [] - - enabled: 0 - converterName: Newtonsoft.Json.Converters.XmlNodeConverter - settings: [] diff --git a/Resources/Newtonsoft.Json-for-Unity.Converters.asset.meta b/Resources/Newtonsoft.Json-for-Unity.Converters.asset.meta deleted file mode 100644 index ec4e066..0000000 --- a/Resources/Newtonsoft.Json-for-Unity.Converters.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 466d3febdbd656c4f9728b1116b1564f -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample.meta b/Sample.meta deleted file mode 100644 index 053ada4..0000000 --- a/Sample.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 18f38c39496afae47ab40fb512c3ce7c -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph.meta b/Sample/MathGraph.meta deleted file mode 100644 index 911ec5f..0000000 --- a/Sample/MathGraph.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 23ebabfc8f40d2c4689dc4ec9a5786d5 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/Editor.meta b/Sample/MathGraph/Editor.meta deleted file mode 100644 index 1a654ad..0000000 --- a/Sample/MathGraph/Editor.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 73ee98eea19fa9b42b9c7990a8161d56 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/Editor/MathEditor.cs b/Sample/MathGraph/Editor/MathEditor.cs deleted file mode 100644 index a5bb700..0000000 --- a/Sample/MathGraph/Editor/MathEditor.cs +++ /dev/null @@ -1,22 +0,0 @@ -using TNode.Editor; -using UnityEditor; -using UnityEditor.Callbacks; -using UnityEditor.Experimental.GraphView; -using UnityEngine; -using UnityEngine.UIElements; -using System; -public class MathEditor : GraphEditor{ - [OnOpenAsset] - public static bool OnOpenAsset(int instanceID, int line){ - var graph = EditorUtility.InstanceIDToObject(instanceID) as MathGraph; - if (graph != null) - { - var wnd = GetWindow(); - wnd.titleContent = new GUIContent("MathGraph Editor"); - wnd.CreateGUI(); - wnd.GraphView.Data = graph; - return true; - } - return false; - } -} \ No newline at end of file diff --git a/Sample/MathGraph/Editor/MathEditor.cs.meta b/Sample/MathGraph/Editor/MathEditor.cs.meta deleted file mode 100644 index 7b70665..0000000 --- a/Sample/MathGraph/Editor/MathEditor.cs.meta +++ /dev/null @@ -1,14 +0,0 @@ -fileFormatVersion: 2 -guid: c9041cb574597424fa4124edc3f99af1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: - - m_ViewDataDictionary: {instanceID: 0} - - mVisualTreeAsset: {fileID: 9197481963319205126, guid: b67f6dcbe2361b649ad2b7845207321b, type: 3} - - graphEditorData: {fileID: 11400000, guid: f582a62cc8e00144f97b4dff1f9ba8cc, type: 2} - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/Editor/MathGraphView.cs b/Sample/MathGraph/Editor/MathGraphView.cs deleted file mode 100644 index 2e366ef..0000000 --- a/Sample/MathGraph/Editor/MathGraphView.cs +++ /dev/null @@ -1,9 +0,0 @@ -using TNodeCore.Attribute; -using TNodeGraphViewImpl.Editor.NodeGraphView; - -[ViewComponent] -public class MathGraphView : BaseDataGraphView{ - - - -} \ No newline at end of file diff --git a/Sample/MathGraph/Editor/MathGraphView.cs.meta b/Sample/MathGraph/Editor/MathGraphView.cs.meta deleted file mode 100644 index c7e283a..0000000 --- a/Sample/MathGraph/Editor/MathGraphView.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7f4d84b648626d24eb29bfeb81c85e3f -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset b/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset deleted file mode 100644 index 4445e6d..0000000 --- a/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset +++ /dev/null @@ -1,15 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 99ad0af56b40495cb6bd6165e652266c, type: 3} - m_Name: NodeAttribute Editor Config - m_EditorClassIdentifier: - nodesData: [] diff --git a/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset.meta b/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset.meta deleted file mode 100644 index f33c3eb..0000000 --- a/Sample/MathGraph/Editor/NodeAttribute Editor Config.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f582a62cc8e00144f97b4dff1f9ba8cc -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/MathGraph.cs b/Sample/MathGraph/MathGraph.cs deleted file mode 100644 index d480670..0000000 --- a/Sample/MathGraph/MathGraph.cs +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; -using UnityEditor; -using System; -using TNodeCore.Models; - -[CreateAssetMenu(fileName = "New MathGraph", menuName = "TNode/MathGraph")] -[Serializable] -public class MathGraph : GraphData{ - -} \ No newline at end of file diff --git a/Sample/MathGraph/MathGraph.cs.meta b/Sample/MathGraph/MathGraph.cs.meta deleted file mode 100644 index 1420f5b..0000000 --- a/Sample/MathGraph/MathGraph.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 73baeb2c71a23da4ca06e3e3e52d5a78 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/MathGraph/New MathGraph.asset b/Sample/MathGraph/New MathGraph.asset deleted file mode 100644 index 154660b..0000000 --- a/Sample/MathGraph/New MathGraph.asset +++ /dev/null @@ -1,23 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!114 &11400000 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 73baeb2c71a23da4ca06e3e3e52d5a78, type: 3} - m_Name: New MathGraph - m_EditorClassIdentifier: - nodes: [] - nodeLinks: [] - entryNode: - rid: -2 - references: - version: 2 - RefIds: - - rid: -2 - type: {class: , ns: , asm: } diff --git a/Sample/MathGraph/New MathGraph.asset.meta b/Sample/MathGraph/New MathGraph.asset.meta deleted file mode 100644 index 041e2b1..0000000 --- a/Sample/MathGraph/New MathGraph.asset.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 4b23c513fb78ea44b8a11a0bf7c8479e -NativeFormatImporter: - externalObjects: {} - mainObjectFileID: 11400000 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Sample/TestExposedReference.cs b/Sample/TestExposedReference.cs deleted file mode 100644 index a44add9..0000000 --- a/Sample/TestExposedReference.cs +++ /dev/null @@ -1,10 +0,0 @@ -using UnityEngine; - -namespace Sample{ - // Create at Asset/Test - [CreateAssetMenu(fileName = "NewData", menuName = "Test/Data", order = 1)] - public class TestExposedReference:ScriptableObject{ - public ExposedReference camera; - public ExposedReference go; - } -} \ No newline at end of file diff --git a/Sample/TestExposedReference.cs.meta b/Sample/TestExposedReference.cs.meta deleted file mode 100644 index f6c4b0e..0000000 --- a/Sample/TestExposedReference.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: fed858872d394fb8896d48178f8a7d78 -timeCreated: 1657862979 \ No newline at end of file diff --git a/TNodeCore/Attribute/RuntimeNodeAttribute.cs b/TNodeCore/Attribute/RuntimeNodeAttribute.cs new file mode 100644 index 0000000..6d2ad80 --- /dev/null +++ b/TNodeCore/Attribute/RuntimeNodeAttribute.cs @@ -0,0 +1,6 @@ +using JetBrains.Annotations; +using TNodeCore.Models; + +namespace TNodeCore.Attribute{ + +} \ No newline at end of file diff --git a/TNodeCore/Attribute/RuntimeNodeAttribute.cs.meta b/TNodeCore/Attribute/RuntimeNodeAttribute.cs.meta new file mode 100644 index 0000000..ec78521 --- /dev/null +++ b/TNodeCore/Attribute/RuntimeNodeAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: e489ca10c5734869be9bce6e1a18297e +timeCreated: 1657952959 \ No newline at end of file diff --git a/TNodeCore/Editor/IGraphEditor.cs b/TNodeCore/Editor/IGraphEditor.cs new file mode 100644 index 0000000..2426868 --- /dev/null +++ b/TNodeCore/Editor/IGraphEditor.cs @@ -0,0 +1,8 @@ +using TNodeCore.Editor.NodeGraphView; + +namespace TNodeCore.Editor{ + public interface IGraphEditor{ + public void SetGraphView(IBaseDataGraphView graphView); + public IBaseDataGraphView GetGraphView(); + } +} \ No newline at end of file diff --git a/TNodeCore/Editor/IGraphEditor.cs.meta b/TNodeCore/Editor/IGraphEditor.cs.meta new file mode 100644 index 0000000..d22ea95 --- /dev/null +++ b/TNodeCore/Editor/IGraphEditor.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d84e826fe49d4314b8cc1241faf38fd9 +timeCreated: 1657944822 \ No newline at end of file diff --git a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs index e30b7ca..14e0ae3 100644 --- a/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs +++ b/TNodeCore/Editor/NodeGraphView/IBaseDataGraphView.cs @@ -10,6 +10,9 @@ namespace TNodeCore.Editor.NodeGraphView{ public GraphData GetGraphData(); public BlackboardData GetBlackboardData(); + public bool IsRuntimeGraph{ get; set; } + + public void SetGraphData(GraphData graph); } } \ No newline at end of file diff --git a/TNodeCore/Editor/Resources/GraphViewBackground.uss b/TNodeCore/Editor/Resources/GraphViewBackground.uss index 44451b6..e9d3385 100644 --- a/TNodeCore/Editor/Resources/GraphViewBackground.uss +++ b/TNodeCore/Editor/Resources/GraphViewBackground.uss @@ -4,3 +4,12 @@ GridBackground{ --thick-line-color: rgba(211, 211, 211, 0.2); --spacing:50; } + +#HintLabel{ + position: absolute; + left: 45%; + top: 45%; + + font-size: 14; + +} \ No newline at end of file diff --git a/TNodeCore/Editor/Serialization/NodeDataWrapper.cs b/TNodeCore/Editor/Serialization/NodeDataWrapper.cs index 772e9a8..5d1846e 100644 --- a/TNodeCore/Editor/Serialization/NodeDataWrapper.cs +++ b/TNodeCore/Editor/Serialization/NodeDataWrapper.cs @@ -4,46 +4,46 @@ using TNodeCore.Models; using UnityEngine; namespace TNodeCore.Editor.Serialization{ - [Obsolete] - public class NodeDataWrapper : ScriptableObject where T : NodeData{ - public T Data; - private static readonly Dictionary> Cache = new (); - public event Action> OnValueChanged; - public static NodeDataWrapper Get(T data){ - if(Cache.ContainsKey(data)){ - return Cache[data]; - } - var wrapper = ScriptableObject.CreateInstance>(); - Cache.Add(data,wrapper); - return wrapper; - } - public NodeDataWrapper(T data){ - this.Data = data; - } - - public void SetValue(string path, object value){ - var fieldInfo = Data.GetType().GetField(path); - fieldInfo.SetValue(Data,value); - OnValueChanged?.Invoke(this); - } - public object GetValue(string path){ - var fieldInfo = Data.GetType().GetField(path); - return fieldInfo.GetValue(Data); - } - public static implicit operator T(NodeDataWrapper wrapper){ - if (wrapper == null) - return null; - return wrapper.Data; - - } - public static implicit operator NodeDataWrapper(T unWrapper){ - if (unWrapper == null) - return null; - return Get(unWrapper); - } - } + // public class NodeDataWrapper : ScriptableObject where T : NodeData{ + // public T Data; + // private static readonly Dictionary> Cache = new (); + // public event Action> OnValueChanged; + // public static NodeDataWrapper Get(T data){ + // if(Cache.ContainsKey(data)){ + // return Cache[data]; + // } + // var wrapper = ScriptableObject.CreateInstance>(); + // Cache.Add(data,wrapper); + // return wrapper; + // } + // public NodeDataWrapper(T data){ + // this.Data = data; + // } + // + // public void SetValue(string path, object value){ + // var fieldInfo = Data.GetType().GetField(path); + // fieldInfo.SetValue(Data,value); + // OnValueChanged?.Invoke(this); + // } + // + // public object GetValue(string path){ + // var fieldInfo = Data.GetType().GetField(path); + // return fieldInfo.GetValue(Data); + // } + // public static implicit operator T(NodeDataWrapper wrapper){ + // if (wrapper == null) + // return null; + // return wrapper.Data; + // + // } + // public static implicit operator NodeDataWrapper(T unWrapper){ + // if (unWrapper == null) + // return null; + // return Get(unWrapper); + // } + // } public class NodeDataWrapper:DataWrapper{ } diff --git a/TNodeCore/Models/BlackboardData.cs b/TNodeCore/Models/BlackboardData.cs index 95b35b6..1da25ce 100644 --- a/TNodeCore/Models/BlackboardData.cs +++ b/TNodeCore/Models/BlackboardData.cs @@ -6,6 +6,9 @@ namespace TNodeCore.Models{ /// [Serializable] - public class BlackboardData:IModel{ + public class BlackboardData:IModel,ICloneable{ + public object Clone(){ + return this.MemberwiseClone(); + } } } \ No newline at end of file diff --git a/TNodeCore/Models/NodeData.cs b/TNodeCore/Models/NodeData.cs index 79aeb10..3e1565a 100644 --- a/TNodeCore/Models/NodeData.cs +++ b/TNodeCore/Models/NodeData.cs @@ -1,5 +1,6 @@ using System; using TNodeCore.Attribute; +using UnityEngine; namespace TNodeCore.Models{ /// @@ -22,12 +23,15 @@ namespace TNodeCore.Models{ public bool entryPoint; - public virtual void OnProcess(){ + public virtual void Process(){ } -// #if UNITY_EDITOR -// public Rect rect; -// #endif +#if UNITY_EDITOR + [HideInInspector] public bool isTest; + public virtual void OnTest(){ + + } + #endif } } \ No newline at end of file diff --git a/TNodeCore/Models/NodeLink.cs b/TNodeCore/Models/NodeLink.cs index dfccbcc..1b929ac 100644 --- a/TNodeCore/Models/NodeLink.cs +++ b/TNodeCore/Models/NodeLink.cs @@ -7,9 +7,11 @@ namespace TNodeCore.Models{ // public DialogueNodePortData From{ get; } public PortInfo inPort; public PortInfo outPort; + public NodeLink(PortInfo inPort, PortInfo outPort){ this.inPort = inPort; this.outPort = outPort; } + } } \ No newline at end of file diff --git a/TNodeCore/Runtime/RuntimeGraph.cs b/TNodeCore/Runtime/RuntimeGraph.cs index 1d019e4..06cae28 100644 --- a/TNodeCore/Runtime/RuntimeGraph.cs +++ b/TNodeCore/Runtime/RuntimeGraph.cs @@ -1,19 +1,152 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using TNodeCore.Models; using UnityEngine; namespace TNodeCore.Runtime{ public class RuntimeGraph:MonoBehaviour{ public GraphData graphData; - public SortedSet _sortedSet; + + public readonly Dictionary RuntimeNodes = new Dictionary(); + + private GraphTool _graphTool; + + private class GraphTool{ + [NonSerialized] + public readonly List TopologicalOrder = new List(); + public readonly List EntryNodes = new List(); + public readonly Dictionary RuntimeNodes; + public void DependencyTraversal(RuntimeNode runtimeNode){ + var links = runtimeNode.InputLink; + foreach (var link in links){ + var outputNode = RuntimeNodes[link.outPort.nodeDataId]; + DependencyTraversal(outputNode); + HandlingLink(link); + } + runtimeNode.NodeData.Process(); + } + + public void HandlingLink(NodeLink nodeLink){ + var inNode = RuntimeNodes[nodeLink.inPort.nodeDataId]; + var outNode = RuntimeNodes[nodeLink.outPort.nodeDataId]; + + //out node is node output data + //in node is node receive data + var outValue = outNode.GetOutput(nodeLink.outPort.portName); + inNode.SetInput(nodeLink.inPort.portName, outValue); + } + public GraphTool(List list, Dictionary graphNodes){ + RuntimeNodes = graphNodes; + if (list == null) return; + Queue queue = new Queue(); + Dictionary inDegreeCounterForTopologicalSort = new Dictionary(); + foreach (var runtimeNode in list){ + var id = runtimeNode.NodeData.id; + if (!inDegreeCounterForTopologicalSort.ContainsKey(id)){ + inDegreeCounterForTopologicalSort.Add(id,runtimeNode.InputLink.Count); + } + if (inDegreeCounterForTopologicalSort[id] == 0){ + queue.Enqueue(runtimeNode); + EntryNodes.Add(runtimeNode); + } + } + + //Topological sort + while (queue.Count > 0){ + var node = queue.Dequeue(); + TopologicalOrder.Add(node); + foreach (var outputLink in node.OutputLink){ + inDegreeCounterForTopologicalSort[outputLink.inPort.nodeDataId]--; + if (inDegreeCounterForTopologicalSort[outputLink.inPort.nodeDataId] == 0){ + queue.Enqueue(RuntimeNodes[outputLink.inPort.nodeDataId]); + } + } + } + if(TopologicalOrder.Count!= list.Count){ + throw new Exception("Topological sort failed,circular dependency detected"); + } + RuntimeNodes.Clear(); + inDegreeCounterForTopologicalSort.Clear(); + queue.Clear(); + } + + + } [SerializeReference] public BlackboardData runtimeBlackboardData; + + private bool _build = false; + public void Build(){ + + var link = graphData.NodeLinks; + //iterate links and create runtime nodes + foreach (var linkData in link){ + ModifyOrCreateInNode(linkData); + ModifyOrCreateOutNode(linkData); + } + var nodeList = RuntimeNodes.Values; + _graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes); + _build = true; + } + + public RuntimeNode Get(NodeData nodeData){ + if(!_build) + Build(); + + if(RuntimeNodes.ContainsKey(nodeData.id)){ + return RuntimeNodes[nodeData.id]; + } + return null; + } + + public RuntimeNode Get(string id){ + if (RuntimeNodes.ContainsKey(id)){ + return RuntimeNodes[id]; + } + + return null; + } + //DFS search for resolving dependency + public void StartDependencyTraversal(NodeData startNode,NodeData currentNode,int level=0){ + if (!_build) + Build(); + if(_graphTool==null) + return; + _graphTool.DependencyTraversal(Get(startNode)); + var inputNodesId = Get(currentNode).GetInputNodesId(); + foreach (var s in inputNodesId){ + var runtimeNode = Get(s); + } + } + private void ModifyOrCreateInNode(NodeLink linkData){ + var inNodeId = linkData.inPort.nodeDataId; + var inNode = graphData.NodeDictionary[inNodeId]; + if (!RuntimeNodes.ContainsKey(inNode.id)){ + var runtimeInNode = new RuntimeNode(inNode); + RuntimeNodes.Add(inNode.id,runtimeInNode); + } + RuntimeNodes[inNode.id].InputLink.Add(linkData); + + } + private void ModifyOrCreateOutNode(NodeLink linkData){ + var outNodeId = linkData.outPort.nodeDataId; + var outNode = graphData.NodeDictionary[outNodeId]; + if(!RuntimeNodes.ContainsKey(outNode.id)){ + var runtimeOutNode = new RuntimeNode(outNode); + RuntimeNodes.Add(outNode.id,runtimeOutNode); + } + RuntimeNodes[outNode.id].OutputLink.Add(linkData); + } public void OnValidate(){ if(runtimeBlackboardData==null||runtimeBlackboardData.GetType()==typeof(BlackboardData)){ - runtimeBlackboardData = graphData?.blackboardData; + if (graphData != null) + runtimeBlackboardData = graphData.blackboardData.Clone() as BlackboardData; } } + + } public enum ProcessingStrategy{ diff --git a/TNodeCore/Runtime/RuntimeNode.cs b/TNodeCore/Runtime/RuntimeNode.cs index 428b763..b83e15a 100644 --- a/TNodeCore/Runtime/RuntimeNode.cs +++ b/TNodeCore/Runtime/RuntimeNode.cs @@ -1,12 +1,39 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using Codice.Client.Common.TreeGrouper; using TNodeCore.Models; +using TNodeCore.RuntimeCache; namespace TNodeCore.Runtime{ - public abstract class RuntimeNode{ - public NodeData NodeData; - public List NodeLinks; - public void ProcessThisNode(){ - NodeData.OnProcess(); + public class RuntimeNode{ + public NodeData NodeData { get; set; } + //the link connect to node's in port + public List InputLink; + //the link connect to node's out port + public List OutputLink; + public Type type; + + + public void SetInput(string portName,object value){ + NodeData.SetValue(portName, value); + } + public object GetOutput(string portName){ + return NodeData.GetValue(portName); + } + + public RuntimeNode(NodeData nodeData){ + NodeData = nodeData; + //Caching the type of the node + type = nodeData.GetType(); + } + public List GetInputNodesId(){ + List dependencies = new List(); + foreach (NodeLink link in InputLink) + { + dependencies.Add(link.outPort.nodeDataId); + } + return dependencies; } + } } \ No newline at end of file diff --git a/TNodeCore/RuntimeCache/RuntimeCache.cs b/TNodeCore/RuntimeCache/RuntimeCache.cs index 6afe225..d3a1a79 100644 --- a/TNodeCore/RuntimeCache/RuntimeCache.cs +++ b/TNodeCore/RuntimeCache/RuntimeCache.cs @@ -50,6 +50,11 @@ namespace TNodeCore.RuntimeCache{ AddBlackboardDataTypeToCache(type,attribute); RegisterRuntimeBlackboard(type); } + //Check if the type is a node data type + if(typeof(NodeData).IsAssignableFrom(type)){ + //if it is, add it to the cache + RegisterRuntimeNodeData(type); + } } @@ -101,6 +106,41 @@ namespace TNodeCore.RuntimeCache{ } } + public void RegisterRuntimeNodeData(Type type){ + if (type == null) return; + if(!CachedDelegatesForGettingValue.ContainsKey(type)){ + CachedDelegatesForGettingValue.Add(type, new Dictionary()); + CachedDelegatesForSettingValue.Add(type,new Dictionary()); + var properties = type.GetProperties(); + foreach(var property in properties){ + //if the property only has a setter ,skip + + if(property.SetMethod != null){ + var setValueDelegate = SetValueDelegateForProperty(property); + CachedDelegatesForSettingValue[type].Add(property.Name,setValueDelegate); + } + if(property.GetMethod != null){ + var getValueDelegate = GetValueDelegateForProperty(property); + CachedDelegatesForGettingValue[type].Add(property.Name,getValueDelegate); + } + + + + } + //register the fields + var fields = type.GetFields(); + foreach(var field in fields){ + + var getValueDelegate = GetValueDelegateForField(field); + CachedDelegatesForGettingValue[type].Add(field.Name,getValueDelegate); + if (field.IsPublic){ + var setValueDelegate = SetValueDelegateForField(field); + CachedDelegatesForSettingValue[type].Add(field.Name,setValueDelegate); + } + + } + } + } private GetValueDelegate GetValueDelegateForField(FieldInfo field){ return field.GetValue; } @@ -120,26 +160,29 @@ namespace TNodeCore.RuntimeCache{ public static class RuntimeExtension{ //todo latter on i will try some way caching reflection more efficiently - public static T GetValue(this BlackboardData blackboardData,string path){ - var method = RuntimeCache.Instance.CachedDelegatesForGettingValue[blackboardData.GetType()][path]; - return (T) method.Invoke(blackboardData); + public static T GetValue(this IModel data,string path,Type type=null){ + var method = RuntimeCache.Instance.CachedDelegatesForGettingValue[type??data.GetType()][path]; + return (T) method.Invoke(data); } - public static object GetValue(this BlackboardData blackboardData, string path){ - var method = RuntimeCache.Instance.CachedDelegatesForGettingValue[blackboardData.GetType()][path]; - return method.Invoke(blackboardData); + public static object GetValue(this IModel data, string path,Type type=null){ + var method = RuntimeCache.Instance.CachedDelegatesForGettingValue[type??data.GetType()][path]; + return method.Invoke(data); } - public static void SetValue(this BlackboardData blackboardData,string path,T value){ - var method = RuntimeCache.Instance.CachedDelegatesForSettingValue[blackboardData.GetType()][path]; - method.Invoke(blackboardData,value); + + public static void SetValue(this IModel data,string path,T value,Type type=null){ + var method = RuntimeCache.Instance.CachedDelegatesForSettingValue[type??data.GetType()][path]; + method.Invoke(data,value); } - public static void SetValue(this BlackboardData blackboardData,string path,object value){ - var method = RuntimeCache.Instance.CachedDelegatesForSettingValue[blackboardData.GetType()][path]; - method.Invoke(blackboardData,value); + public static void SetValue(this IModel data,string path,object value,Type type=null){ + var method = RuntimeCache.Instance.CachedDelegatesForSettingValue[type??data.GetType()][path]; + method.Invoke(data,value); } - public static RuntimeCache.GetValueDelegate GetValueDelegate(this BlackboardData blackboardData,string path){ + public static RuntimeCache.GetValueDelegate GetValueDelegate(this IModel blackboardData,string path){ var method = RuntimeCache.Instance.CachedDelegatesForGettingValue[blackboardData.GetType()][path]; return method; } + + } } \ No newline at end of file diff --git a/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs b/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs index 68460b3..5d55934 100644 --- a/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs +++ b/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using TNode.Editor; using TNode.Editor.NodeViews; using TNodeCore.Attribute; @@ -58,10 +59,12 @@ namespace TNodeGraphViewImpl.Editor.Cache{ SetViewComponentAttribute(type); //Register Node Data by GraphUsageAttribute. SetGraphUsageAttribute(type); + } } } } + private void SetGraphUsageAttribute(Type type){ foreach (var attribute in type.GetCustomAttributes(typeof(GraphUsageAttribute), true)){ diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs index 0a74e1a..129d9ea 100644 --- a/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs @@ -2,6 +2,7 @@ using System.Reflection; using TNode.Editor.Search; using TNodeCore.Attribute; +using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Serialization; using TNodeCore.Models; using UnityEditor; @@ -21,6 +22,8 @@ namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ protected override void UpdateBlackboard(BlackboardData data){ if (data == null) return; var serializedObject = new SerializedObject((BlackboardDataWrapper)data); + var currentGraphView = graphView as IBaseDataGraphView; + var isRuntimeGraph = currentGraphView?.IsRuntimeGraph ?? false; foreach (var field in data.GetType() .GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)){ //if the field is MonoBehaviour,add a property field for blackboard @@ -31,14 +34,12 @@ namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ var foldoutData = new Foldout{ text = field.Name }; - var drawer = new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name); + var drawer = new GraphBlackboardPropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name,isRuntimeGraph); drawer.Bind(serializedObject); foldoutData.Add(drawer); visualElement.Add(propertyField); visualElement.Add(foldoutData); - Add(visualElement); - } else{ var blackboardList = new BlackboardSection{ diff --git a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs index e96416f..33c40e6 100644 --- a/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs +++ b/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs @@ -4,15 +4,18 @@ using UnityEngine.UIElements; namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ public class GraphBlackboardPropertyField:PropertyField{ - public GraphBlackboardPropertyField(SerializedProperty findPropertyRelative, string fieldName):base(findPropertyRelative, fieldName){ - - } + private readonly bool _runtime; + public GraphBlackboardPropertyField(SerializedProperty findPropertyRelative, string fieldName,bool runtime):base(findPropertyRelative, fieldName){ + _runtime = runtime; + } + protected override void ExecuteDefaultActionAtTarget(EventBase evt) { + base.ExecuteDefaultActionAtTarget(evt); if (this.Q() != null){ - this.Q().allowSceneObjects = false; + this.Q().allowSceneObjects = _runtime; } } diff --git a/TNodeGraphViewImpl/Editor/GraphEditor.cs b/TNodeGraphViewImpl/Editor/GraphEditor.cs index 2a01b69..f6c2460 100644 --- a/TNodeGraphViewImpl/Editor/GraphEditor.cs +++ b/TNodeGraphViewImpl/Editor/GraphEditor.cs @@ -1,25 +1,60 @@ -using Codice.CM.Common; -using TNode.Editor.Inspector; +using System; +using TNodeCore.Editor; using TNodeCore.Editor.EditorPersistence; +using TNodeCore.Editor.NodeGraphView; using TNodeCore.Models; using TNodeGraphViewImpl.Editor.Cache; using TNodeGraphViewImpl.Editor.NodeGraphView; using UnityEditor; -using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UIElements; -namespace TNode.Editor{ +namespace TNodeGraphViewImpl.Editor{ - - public abstract class GraphEditor : EditorWindow where T:GraphData{ + // public class SelectGraphWindow : EditorWindow{ + // public EditorWindow parent; + // public Type graphType; + // public static void ShowWindow (GraphEditor parent) where T:GraphData{ + // var window = GetWindow(); + // window.graphType = typeof(T); + // window.Show(); + // window.parent = parent; + // } + // private void OnGUI(){ + // + // if(GUILayout.Button("Create An Graph")){ + // //Add a save file dialog to save the graph + // //Create the graph + // var graphAsset = ScriptableObject.CreateInstance(graphType); + // var path = EditorUtility.SaveFilePanel("Save Graph", "", "", "asset"); + // //Save the graph + // AssetDatabase.CreateAsset(graphAsset, path); + // AssetDatabase.SaveAssets(); + // AssetDatabase.Refresh(); + // //Load the graph + // var graph = AssetDatabase.LoadAssetAtPath(path) as GraphData; + // var graphEditor = parent as IGraphEditor; + // if (graphEditor.GetGraphView() != null){ + // graphEditor.GetGraphView().SetGraphData(graph); + // Debug.Log(graph); + // } + // } + // //Drag and drop a graph asset to load it + // if(Event.current.type == EventType.DragUpdated){ + // DragAndDrop.visualMode = DragAndDropVisualMode.Copy; + // Event.current.Use(); + // } + // } + // } + public abstract class GraphEditor : EditorWindow,IGraphEditor where T:GraphData{ protected BaseDataGraphView GraphView; [SerializeField] private VisualTreeAsset mVisualTreeAsset = default; //Persist editor data ,such as node position,node size ,etc ,in this script object [FormerlySerializedAs("nodeEditorData")] public GraphEditorData graphEditorData; - + private bool _windowShowed=false; + public void CreateGUI(){ // Each editor window contains a root VisualElement object @@ -28,12 +63,26 @@ namespace TNode.Editor{ // Instantiate UXML VisualElement labelFromUXML = mVisualTreeAsset.Instantiate(); root.Add(labelFromUXML); - + BuildGraphView(); DefineGraphEditorActions(); + GraphView.Owner = this; OnCreate(); } - + + public void Update(){ + if (GraphView == null) return; + if (GraphView.Data != null) return; + if (_windowShowed==false){ + _windowShowed = true; + } + } + + + public void SetupNonRuntime(T graphData){ + GraphView.Data = graphData; + GraphView.IsRuntimeGraph = false; + } private void BuildGraphView(){ GraphView = NodeEditorExtensions.CreateViewComponentFromBaseType>(); rootVisualElement.Add(GraphView); @@ -75,6 +124,13 @@ namespace TNode.Editor{ protected virtual void OnCreate(){ } - + + public void SetGraphView(IBaseDataGraphView graphView){ + GraphView = graphView as BaseDataGraphView; + } + + public IBaseDataGraphView GetGraphView(){ + return GraphView; + } } } diff --git a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs index 4660f6a..8d44a8c 100644 --- a/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs +++ b/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs @@ -36,6 +36,9 @@ namespace TNode.Editor.Inspector{ RefreshPropertyDrawer(); } + private void CreateTestButton(){ + + } private void RefreshPropertyDrawer(){ //Check if the data's type is a generic type of BlackboardDragNodeData<> if (_data.GetType().IsSubclassOf(typeof(BlackboardDragNodeData))){ @@ -51,6 +54,17 @@ namespace TNode.Editor.Inspector{ var drawer = new PropertyField(serializedObject.FindProperty("data").FindPropertyRelative(field.Name),field.Name); drawer.Bind(serializedObject); Add(drawer); + + + } + if (_data.isTest){ + //Add a test button for the node + var testButton = new Button(()=>{ + Debug.Log("Test button clicked"); + }); + testButton.text = "Test"; + _data.OnTest(); + Add(testButton); } } diff --git a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index dbd8619..e23b499 100644 --- a/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -1,31 +1,32 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Linq; -using System.Reflection; -using TNode.Editor; using TNode.Editor.Inspector; -using TNode.Editor.NodeViews; using TNode.Editor.Search; using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.EditorPersistence; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Tools.NodeCreator; using TNodeCore.Models; +using TNodeCore.Runtime; using TNodeGraphViewImpl.Editor.Cache; using TNodeGraphViewImpl.Editor.GraphBlackboard; -using TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty; using TNodeGraphViewImpl.Editor.NodeViews; + using UnityEditor; using UnityEditor.Experimental.GraphView; +using UnityEditor.VersionControl; using UnityEngine; using UnityEngine.UIElements; + using Edge = UnityEditor.Experimental.GraphView.Edge; namespace TNodeGraphViewImpl.Editor.NodeGraphView{ public abstract class BaseDataGraphView:GraphView,IDataGraphView where T:GraphData{ #region variables and properties private T _data; + private RuntimeGraph _runtimeGraph; + private bool _isInspectorOn; private NodeSearchWindowProvider _nodeSearchWindowProvider; private NodeInspector _nodeInspector; @@ -64,7 +65,91 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); RegisterDragEvent(); OnInit(); + CheckAfterInit(); + } + /// + /// Probably reusable in later GTFs version + /// + private void WaitingForAGraph(){ + Debug.Log("hello"); + VisualElement visualElement = new VisualElement(); + //Set background color to white + visualElement.style.backgroundColor = new StyleColor(new Color(0.1f, 0.1f, 0.1f, 1)); + + Debug.Log("hello2"); + visualElement.StretchToParentSize(); + visualElement.name = "WaitingForAGraph"; + Add(visualElement); + visualElement.BringToFront(); + + + //Add a label at the center of the created element + Label label = new Label("drag a graph item here"){ + style ={ + position = Position.Absolute + }, + name = "HintLabel" + }; + + visualElement.RegisterCallback((evt) => { + //check if the dragged object is a graph data or a Game Object contains a runtime graph + var res = DragAndDrop.objectReferences; + foreach (var obj in res){ + if (obj is T graphData){ + Data = graphData; + IsRuntimeGraph = false; + } + else{ + if (obj is GameObject gameObject){ + + if (gameObject.GetComponent() != null){ + if (gameObject.GetComponent().graphData != null){ + + _runtimeGraph = gameObject.GetComponent(); + IsRuntimeGraph = true; + + + Data = gameObject.GetComponent().graphData as T; + if(Data==null){ + Debug.LogError($"Dragged a wrong graph data to editor,expected {typeof(T)} but got {gameObject.GetComponent().graphData.GetType()}"); + } + + } + } + } + } + } + }); + visualElement.RegisterCallback((evt) => { + //check if the dragged object is a graph data or a Game Object contains a runtime graph + var res = DragAndDrop.objectReferences; + foreach (var obj in res){ + if (obj is GraphData graphData){ + DragAndDrop.visualMode = DragAndDropVisualMode.Link; + } + else{ + if (obj is GameObject gameObject){ + if (gameObject.GetComponent() != null){ + DragAndDrop.visualMode = DragAndDropVisualMode.Link; + } + } + } + } + + }); + visualElement.Add(label); + OnDataChanged += (sender, e) => { + if (Data != null){ + visualElement.RemoveFromHierarchy(); + } + }; } + private void CheckAfterInit(){ + if(Data == null){ + WaitingForAGraph(); + } + } + private void ConstructDefaultBehaviour(){ //Register a right click context menu ConstructViewContextualMenu(); @@ -106,7 +191,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ if(selectable is { } field) { //Make a constructor of BlackboardDragNodeData by reflection var dragNodeData = NodeCreator.InstantiateNodeData(); - dragNodeData.blackboardData = _data.blackboardData; + dragNodeData.blackboardData = GetBlackboardData(); dragNodeData.blackDragData = field.BlackboardProperty.PropertyName; AddTNode(dragNodeData,new Rect(evt.mousePosition,new Vector2(200,200))); } @@ -116,7 +201,6 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ } private void OnDragUpdated(DragUpdatedEvent evt){ - Debug.Log(evt); //check if the drag data is BlackboardField @@ -188,7 +272,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ public virtual void CreateMiniMap(Rect rect){ var miniMap = new MiniMap(); - this.Add(miniMap); + Add(miniMap); miniMap.SetPosition(rect); } @@ -200,7 +284,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ if (_data.blackboardData == null) return; } - _blackboard.SetBlackboardData(_data.blackboardData); + _blackboard.SetBlackboardData(GetBlackboardData()); } public virtual void DestroyInspector(){ @@ -292,7 +376,7 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ public override List GetCompatiblePorts(Port startPort, NodeAdapter nodeAdapter){ - return ports.Where(x => x.portType == startPort.portType).ToList(); + return ports.Where(x => x.portType == startPort.portType || x.portType.IsAssignableFrom(startPort.portType)).ToList(); } public virtual void OnGraphViewCreate(){ @@ -358,13 +442,10 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ _blackboard.Setup(this,Owner); var castedBlackboard = _blackboard as Blackboard; - Add(castedBlackboard); - Rect blackboardPos = new Rect(0,0,300,700); castedBlackboard?.SetPosition(blackboardPos); - OnDataChanged+= (sender, e) => { BlackboardUpdate(); }; } @@ -374,8 +455,18 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ public BlackboardData GetBlackboardData(){ - return this._data.blackboardData; + if (IsRuntimeGraph){ + return _runtimeGraph.runtimeBlackboardData; + } + return _data.blackboardData; } + + public bool IsRuntimeGraph{ get; set; } + + public void SetGraphData(GraphData graph){ + Data = graph as T; + } + #endregion } diff --git a/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs b/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs index 35341c4..4eedc26 100644 --- a/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs +++ b/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs @@ -45,7 +45,6 @@ namespace TNode.Editor.Search{ } Debug.Log($"{list.Count}"); return list; - } public bool OnSelectEntry(SearchTreeEntry SearchTreeEntry, SearchWindowContext context){