From 34815e6634939fc64c9fa8971d9b60a6c425b993 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Tue, 2 Aug 2022 11:59:01 +0800 Subject: [PATCH 1/2] feature:Add Scene object support for specified type of node --- .../Runtime/Components/RuntimeGraph.cs | 78 +++++++++++++++++++ TNode/TNodeCore/Runtime/Models/IModel.cs | 6 +- TNode/TNodeCore/Runtime/Models/NodeData.cs | 3 + .../Editor/Cache/NodeEditorExtensions.cs | 10 +-- .../Editor/GraphBlackboard/BlackboardField.cs | 9 +-- .../BlackboardProperty/BlackboardProperty.cs | 2 +- .../DefaultGraphBlackboardView.cs | 4 +- .../GraphBlackboardPropertyField.cs | 2 +- .../GraphBlackboard/GraphBlackboardView.cs | 5 +- .../Editor/Inspector/NodeInspector.cs | 13 +--- .../Editor/Inspector/NodeInspectorInNode.cs | 14 ++-- .../Editor/NodeGraphView/DataGraphView.cs | 43 +++++----- .../NodeGraphView/SimpleGraphSubWindow.cs | 3 +- .../Editor/NodeViews/DefaultNodeView.cs | 6 +- .../Editor/NodeViews/DragNodeView.cs | 5 +- .../Editor/NodeViews/NodeView.cs | 5 +- .../Search/BlackboardSearchWindowProvider.cs | 2 +- .../Editor/Search/NodeSearchWindowProvider.cs | 4 +- 18 files changed, 144 insertions(+), 70 deletions(-) diff --git a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs index 0682e88..2363561 100644 --- a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs +++ b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs @@ -202,6 +202,9 @@ namespace TNodeCore.Runtime.Components{ foreach (var sceneNode in sceneNodes){ if (sceneNode != null) sceneNode.BlackboardData = runtimeBlackboardData; } +#if UNITY_EDITOR + BuildSceneNode(); +#endif _build = true; } @@ -246,6 +249,59 @@ namespace TNodeCore.Runtime.Components{ _graphTool.DirectlyTraversal(); return true; } + #region build scene node data + #if UNITY_EDITOR + public void BuildSceneNodePersistentData(SceneNodeData sceneNodeData){ + var tr = transform.Find("PersistentData"); + GameObject go; + if (tr == null){ + go = new GameObject("PersistentData"); + go.transform.SetParent(transform); + go.AddComponent(); + } + go = tr.gameObject; + var persistentData = go.GetComponent(); + persistentData.SceneNodeDataDictionary.Add(sceneNodeData.id,sceneNodeData); + } + + public void BuildSceneNode(){ + var fetchedSceneNode = graphData.NodeDictionary.Values.Where(x => x is SceneNodeData and not BlackboardDragNodeData); + foreach (var nodeData in fetchedSceneNode){ + if (transform.Find(nodeData.id.GetHashCode().ToString())){ + var scenePersistent = transform.Find("PersistentData").GetComponent(); + if (scenePersistent.SceneNodeDataDictionary.ContainsKey(nodeData.id)){ + var sceneNodeData = scenePersistent.SceneNodeDataDictionary[nodeData.id]; + RuntimeNodes[nodeData.id].NodeData = sceneNodeData; + } + } + else if (nodeData.Clone() is SceneNodeData clonedNodeData){ + clonedNodeData.BlackboardData = runtimeBlackboardData; + RuntimeNodes.Remove(nodeData.id); + RuntimeNodes.Add(nodeData.id,new RuntimeNode(clonedNodeData)); + BuildSceneNodePersistentData(clonedNodeData); + } + } + UpdatePersistentData(); + } + + private void UpdatePersistentData(){ + var persistentData = transform.Find("PersistentData")?.GetComponent(); + if (persistentData == null) return; + var fetchedSceneNode = + RuntimeNodes + .Where(x => x.Value.NodeData is SceneNodeData and not BlackboardDragNodeData) + .Select(x=>x.Value.NodeData).ToArray(); + + var dic = persistentData.SceneNodeDataDictionary; + foreach (var sceneNodeData in dic.Values){ + if(!fetchedSceneNode.Contains(sceneNodeData)){ + persistentData.SceneNodeDataDictionary.Remove(sceneNodeData.id); + } + } + } + #endif + #endregion + private void ModifyOrCreateInNode(NodeLink linkData){ var inNodeId = linkData.inPort.nodeDataId; var inNode = graphData.NodeDictionary[inNodeId]; @@ -329,6 +385,28 @@ namespace TNodeCore.Runtime.Components{ } + public class SceneDataPersistent:MonoBehaviour,ISerializationCallbackReceiver{ + + public readonly Dictionary SceneNodeDataDictionary = new(); + + [SerializeReference] + public List sceneNodeData=new (); + + + public void OnBeforeSerialize(){ + sceneNodeData.Clear(); + foreach(var node in SceneNodeDataDictionary.Values){ + sceneNodeData.Add(node); + } + } + public void OnAfterDeserialize(){ + SceneNodeDataDictionary.Clear(); + foreach(var node in sceneNodeData){ + SceneNodeDataDictionary.Add(node.id,node); + } + } + } + public enum ProcessingStrategy{ BreadthFirst, DepthFirst diff --git a/TNode/TNodeCore/Runtime/Models/IModel.cs b/TNode/TNodeCore/Runtime/Models/IModel.cs index ed465dd..c4ea9e9 100644 --- a/TNode/TNodeCore/Runtime/Models/IModel.cs +++ b/TNode/TNodeCore/Runtime/Models/IModel.cs @@ -1,5 +1,7 @@ -namespace TNodeCore.Runtime.Models{ - public interface IModel{ +using System; + +namespace TNodeCore.Runtime.Models{ + public interface IModel:ICloneable{ } } \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Models/NodeData.cs b/TNode/TNodeCore/Runtime/Models/NodeData.cs index 0a1000d..7fc1ae0 100644 --- a/TNode/TNodeCore/Runtime/Models/NodeData.cs +++ b/TNode/TNodeCore/Runtime/Models/NodeData.cs @@ -37,5 +37,8 @@ namespace TNodeCore.Runtime.Models{ } #endif + public object Clone(){ + return this.MemberwiseClone(); + } } } \ No newline at end of file diff --git a/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs b/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs index e77f967..5947bfc 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Cache/NodeEditorExtensions.cs @@ -2,19 +2,17 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using TNode.Editor; +using TNode.TNodeGraphViewImpl.Editor.GraphBlackboard; +using TNode.TNodeGraphViewImpl.Editor.NodeGraphView; +using TNode.TNodeGraphViewImpl.Editor.NodeViews; using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.EditorPersistence; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.GraphBlackboard; -using TNodeGraphViewImpl.Editor.NodeGraphView; -using TNodeGraphViewImpl.Editor.NodeViews; using UnityEditor; -using UnityEngine; -namespace TNodeGraphViewImpl.Editor.Cache{ +namespace TNode.TNodeGraphViewImpl.Editor.Cache{ /// /// Internal singleton class for caching TNode reflection Data. /// diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs index 51ed7d9..da64ac5 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardField.cs @@ -1,10 +1,7 @@ -using UnityEditor; -using UnityEditor.Experimental.GraphView; - -namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ +namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{ public class BlackboardField:UnityEditor.Experimental.GraphView.BlackboardField{ - public BlackboardProperty.BlackboardProperty BlackboardProperty; - public BlackboardField(BlackboardProperty.BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){ + public global::TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty.BlackboardProperty BlackboardProperty; + public BlackboardField(global::TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty.BlackboardProperty blackboardProperty):base(null,blackboardProperty.PropertyName,null){ BlackboardProperty = blackboardProperty; } } diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs index eaa5f89..ddc7992 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/BlackboardProperty/BlackboardProperty.cs @@ -1,6 +1,6 @@ using System; -namespace TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty{ +namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardProperty{ public class BlackboardProperty{ public string PropertyName; public Type PropertyType; diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs index 0cbfd1c..4c6d2ad 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/DefaultGraphBlackboardView.cs @@ -1,6 +1,6 @@ using System.Collections; using System.Reflection; -using TNode.Editor.Search; +using TNode.TNodeGraphViewImpl.Editor.Search; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Serialization; using TNodeCore.Runtime.Attributes; @@ -11,7 +11,7 @@ using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ +namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{ [ViewComponent] public class DefaultGraphBlackboardView:GraphBlackboardView{ public DefaultGraphBlackboardView():base(){ diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs index 75e4b2c..f227574 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardPropertyField.cs @@ -2,7 +2,7 @@ using UnityEditor.UIElements; using UnityEngine.UIElements; -namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ +namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{ public class GraphBlackboardPropertyField:PropertyField{ private readonly bool _runtime; diff --git a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs index b9c8d95..b248d9d 100644 --- a/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/GraphBlackboard/GraphBlackboardView.cs @@ -1,12 +1,11 @@ -using TNode.Editor.Search; -using TNodeCore.Editor.Blackboard; +using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Runtime.Models; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; -namespace TNodeGraphViewImpl.Editor.GraphBlackboard{ +namespace TNode.TNodeGraphViewImpl.Editor.GraphBlackboard{ /// /// Implement this class to create graph black board for specified graph /// diff --git a/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs b/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs index 3aca0e7..94f01ae 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspector.cs @@ -1,18 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using TNode.Editor.NodeViews; +using TNode.TNodeGraphViewImpl.Editor.NodeGraphView; +using TNode.TNodeGraphViewImpl.Editor.NodeViews; using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.NodeGraphView; -using TNodeGraphViewImpl.Editor.NodeViews; -using Unity.VisualScripting; -using UnityEditor; using UnityEditor.Experimental.GraphView; -using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace TNode.Editor.Inspector{ +namespace TNode.TNodeGraphViewImpl.Editor.Inspector{ public class NodeInspector:SimpleGraphSubWindow{ private NodeData _data; public NodeData Data{ diff --git a/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs b/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs index 47462d1..f54a4c6 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Inspector/NodeInspectorInNode.cs @@ -3,13 +3,11 @@ using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Serialization; using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.NodeViews; using UnityEditor; using UnityEditor.UIElements; -using UnityEngine; using UnityEngine.UIElements; -namespace TNode.Editor.Inspector{ +namespace TNode.TNodeGraphViewImpl.Editor.Inspector{ public class NodeInspectorInNode:VisualElement{ private NodeData _data; public NodeData Data{ @@ -57,10 +55,16 @@ namespace TNode.Editor.Inspector{ serializedObject.ApplyModifiedProperties(); ((NodeDataWrapper)_data).ForceNotify(); }); + if (_data is SceneNodeData and not BlackboardDragNodeData){ + + } + else{ + if (drawer.Q() != null){ + drawer.Q().allowSceneObjects = false; + } + } drawer.Bind(serializedObject); Add(drawer); - - } var globalTest = GetFirstAncestorOfType()?.TestMode; diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index 3796fb7..6eb4104 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -2,29 +2,26 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Threading.Tasks; -using TNode.Editor.Inspector; +using TNode.TNodeGraphViewImpl.Editor.Cache; +using TNode.TNodeGraphViewImpl.Editor.Inspector; +using TNode.TNodeGraphViewImpl.Editor.NodeViews; +using TNode.TNodeGraphViewImpl.Editor.Search; using TNodeCore.Editor; using TNodeCore.Editor.Blackboard; using TNodeCore.Editor.EditorPersistence; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Tools.NodeCreator; -using TNodeCore.Runtime; using TNodeCore.Runtime.Components; using TNodeCore.Runtime.Models; using TNodeCore.Runtime.RuntimeCache; -using TNodeGraphViewImpl.Editor.Cache; -using TNodeGraphViewImpl.Editor.NodeViews; -using TNodeGraphViewImpl.Editor.Search; -using Unity.VisualScripting; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; -using BlackboardField = TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardField; +using BlackboardField = TNode.TNodeGraphViewImpl.Editor.GraphBlackboard.BlackboardField; using Edge = UnityEditor.Experimental.GraphView.Edge; -namespace TNodeGraphViewImpl.Editor.NodeGraphView{ +namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ public class BaseDataGraphView:GraphView,IDataGraphView where T:GraphData{ #region variables and properties private T _data; @@ -71,8 +68,9 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); RegisterDragEvent(); OnInit(); - } + + /// /// Probably reusable in later GTFs version /// @@ -281,17 +279,20 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ foreach (var dataNode in _data.NodeDictionary.Values){ if(dataNode==null) continue; - - //Get the node type - var nodeType = dataNode.GetType(); //Get the derived type of NodeAttribute View from the node type if (dataNode is SceneNodeData runtimeNodeData){ - runtimeNodeData.BlackboardData = GetBlackboardData(); + if (runtimeNodeData is not BlackboardDragNodeData){ + runtimeNodeData.BlackboardData = GetBlackboardData(); + } + else{ + var node = _runtimeGraph.Get(runtimeNodeData.id).NodeData as SceneNodeData; + AddPersistentNode(node); + } } - var nodePos = Owner.graphEditorData.graphElementsData. - FirstOrDefault(x => x.guid == dataNode.id)?.pos??new Rect(0,0,200,200); - - AddTNode(dataNode,nodePos); + else{ + AddPersistentNode(dataNode); + } + } foreach (var edge in _data.NodeLinks){ @@ -310,6 +311,12 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{ } _nodeDict.Clear(); } + + private void AddPersistentNode(NodeData dataNode){ + var nodePos = Owner.graphEditorData.graphElementsData.FirstOrDefault(x => x.guid == dataNode.id)?.pos ?? + new Rect(0, 0, 200, 200); + AddTNode(dataNode, nodePos); + } //OnDataChanged event diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs index 4e39aa4..57d029a 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/SimpleGraphSubWindow.cs @@ -1,11 +1,10 @@ using System.Linq; -using TNode.Editor; using TNodeCore.Editor.EditorPersistence; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine.UIElements; -namespace TNodeGraphViewImpl.Editor.NodeGraphView{ +namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ public class SimpleGraphSubWindow:GraphElement,IGraphViewPersistence{ private readonly Dragger _dragger = new Dragger(); diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs index 40ad361..b047a15 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DefaultNodeView.cs @@ -1,8 +1,6 @@ -using TNode.Editor.NodeViews; -using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.NodeViews; +using TNodeCore.Runtime.Models; -namespace TNode.Editor{ +namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ public class DefaultBaseNodeView:BaseNodeView{ diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs index 6f329d9..576d87d 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs @@ -1,15 +1,12 @@ using TNodeCore.Editor.Serialization; using TNodeCore.Runtime.Attributes; using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.NodeViews; using UnityEditor; using UnityEditor.Experimental.GraphView; -using UnityEditor.Graphs; -using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; -namespace TNode.Editor.NodeViews{ +namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ [ViewComponent] public class DragBaseNodeView:BaseNodeView{ public DragBaseNodeView() : base(){ diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs index 0bfb934..c2f245b 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs @@ -1,8 +1,7 @@ using System; using System.Linq; using System.Reflection; -using TNode.Editor.Inspector; -using TNodeCore; +using TNode.TNodeGraphViewImpl.Editor.Inspector; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Serialization; using TNodeCore.Runtime; @@ -13,7 +12,7 @@ using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; -namespace TNodeGraphViewImpl.Editor.NodeViews{ +namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ public abstract class BaseNodeView : Node,INodeView where T:NodeData,new(){ protected T _data; diff --git a/TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs b/TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs index 4eedc26..2b8e789 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Search/BlackboardSearchWindowProvider.cs @@ -6,7 +6,7 @@ using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; -namespace TNode.Editor.Search{ +namespace TNode.TNodeGraphViewImpl.Editor.Search{ public class BlackboardSearchWindowProvider:ScriptableObject,ISearchWindowProvider{ private Type _graphType; private IBaseDataGraphView _graphView; diff --git a/TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs b/TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs index 133df73..388eaa7 100644 --- a/TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs +++ b/TNode/TNodeGraphViewImpl/Editor/Search/NodeSearchWindowProvider.cs @@ -1,16 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; +using TNode.TNodeGraphViewImpl.Editor.Cache; using TNodeCore.Editor.NodeGraphView; using TNodeCore.Editor.Tools.NodeCreator; using TNodeCore.Runtime.Models; -using TNodeGraphViewImpl.Editor.Cache; using UnityEditor; using UnityEditor.Experimental.GraphView; using UnityEngine; using UnityEngine.UIElements; -namespace TNodeGraphViewImpl.Editor.Search{ +namespace TNode.TNodeGraphViewImpl.Editor.Search{ public class NodeSearchWindowProvider:ScriptableObject,ISearchWindowProvider{ private Type _graphType; private GraphView _graphView; From 5659d24d33c8127bab7c8ad1d8c3a880cd293ed0 Mon Sep 17 00:00:00 2001 From: taoria <445625470@qq.com> Date: Tue, 2 Aug 2022 12:20:02 +0800 Subject: [PATCH 2/2] fix:fix a bug of scene object view --- .../Runtime/Components/RuntimeGraph.cs | 22 ++++++++++++++----- .../Editor/NodeGraphView/DataGraphView.cs | 4 +++- TilemapGenerator.meta | 8 +++++++ 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 TilemapGenerator.meta diff --git a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs index 2363561..64fc549 100644 --- a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs +++ b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs @@ -196,6 +196,10 @@ namespace TNodeCore.Runtime.Components{ ModifyOrCreateInNode(linkData); ModifyOrCreateOutNode(linkData); } + //iterate nodes and create runtime nodes + foreach (var nodeData in graphData.NodeDictionary.Values){ + CreateRuntimeNodeIfNone(nodeData); + } var nodeList = RuntimeNodes.Values; _graphTool = new GraphTool(nodeList.ToList(),RuntimeNodes,this); var sceneNodes = RuntimeNodes.Values.Where(x => x.NodeData is SceneNodeData).Select(x => x.NodeData as SceneNodeData); @@ -208,6 +212,12 @@ namespace TNodeCore.Runtime.Components{ _build = true; } + private void CreateRuntimeNodeIfNone(NodeData nodeData){ + if (RuntimeNodes.ContainsKey(nodeData.id)) return; + var runtimeNode = new RuntimeNode(nodeData); + RuntimeNodes.Add(nodeData.id,runtimeNode); + } + /// /// Cast the node data to a runtime node /// @@ -227,6 +237,8 @@ namespace TNodeCore.Runtime.Components{ /// /// public RuntimeNode Get(string id){ + if(!_build) + Build(); if (RuntimeNodes.ContainsKey(id)){ return RuntimeNodes[id]; } @@ -266,13 +278,11 @@ namespace TNodeCore.Runtime.Components{ public void BuildSceneNode(){ var fetchedSceneNode = graphData.NodeDictionary.Values.Where(x => x is SceneNodeData and not BlackboardDragNodeData); + var scenePersistent = transform.Find("PersistentData").GetComponent(); foreach (var nodeData in fetchedSceneNode){ - if (transform.Find(nodeData.id.GetHashCode().ToString())){ - var scenePersistent = transform.Find("PersistentData").GetComponent(); - if (scenePersistent.SceneNodeDataDictionary.ContainsKey(nodeData.id)){ - var sceneNodeData = scenePersistent.SceneNodeDataDictionary[nodeData.id]; - RuntimeNodes[nodeData.id].NodeData = sceneNodeData; - } + if (scenePersistent.SceneNodeDataDictionary.ContainsKey(nodeData.id)){ + var sceneNodeData = scenePersistent.SceneNodeDataDictionary[nodeData.id]; + RuntimeNodes[nodeData.id].NodeData = sceneNodeData; } else if (nodeData.Clone() is SceneNodeData clonedNodeData){ clonedNodeData.BlackboardData = runtimeBlackboardData; diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index 6eb4104..7aabeb9 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -281,10 +281,12 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ continue; //Get the derived type of NodeAttribute View from the node type if (dataNode is SceneNodeData runtimeNodeData){ - if (runtimeNodeData is not BlackboardDragNodeData){ + if (runtimeNodeData is BlackboardDragNodeData){ runtimeNodeData.BlackboardData = GetBlackboardData(); + AddPersistentNode(runtimeNodeData); } else{ + var node = _runtimeGraph.Get(runtimeNodeData.id).NodeData as SceneNodeData; AddPersistentNode(node); } diff --git a/TilemapGenerator.meta b/TilemapGenerator.meta new file mode 100644 index 0000000..fb32c7a --- /dev/null +++ b/TilemapGenerator.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: cf0168c8ec1f9304c9872577b1e6abdf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: