diff --git a/README.md b/README.md index 4f7ac3f..c986e22 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ the main goal of the repo is to make graph creation easier and more intuitive. # Some to-dos * Port connectivity of two types have implicit conversion -* Node placement +* Node placemat * Vertical node * A universal merger handle multiple input * Support static graph data traversal diff --git a/TNode/Samples/HelloBlackboard.cs b/TNode/Samples/HelloBlackboard.cs index 0b1f787..a7b19c7 100644 --- a/TNode/Samples/HelloBlackboard.cs +++ b/TNode/Samples/HelloBlackboard.cs @@ -8,8 +8,8 @@ using UnityEngine; namespace TNode.Samples{ [GraphUsage(typeof(HelloGraph))] public class HelloBlackboard:BlackboardData{ - public string HelloString = "Hello World"; - + public string HelloString; + public GameObject HelloGameObject; public List V3S; public List V2S; diff --git a/TNode/Samples/New HelloGraph.asset b/TNode/Samples/New HelloGraph.asset index 687fdaa..6310fac 100644 --- a/TNode/Samples/New HelloGraph.asset +++ b/TNode/Samples/New HelloGraph.asset @@ -14,9 +14,10 @@ MonoBehaviour: m_EditorClassIdentifier: nodeList: - rid: 4804121563801583862 + - rid: 4804121563801583947 + - rid: 4804121563801583866 - rid: 4804121563801583898 - rid: 4804121563801583870 - - rid: 4804121563801583866 nodeLinks: - inPort: portEntryName: A @@ -25,7 +26,7 @@ MonoBehaviour: portEntryName: Value nodeDataId: ac84573e-638d-45fa-b4e2-1a81c31fa9e7 - inPort: - portEntryName: B + portEntryName: A nodeDataId: 6ceba867-fe0d-40c3-9d30-2d5d12803b52 outPort: portEntryName: Value @@ -46,6 +47,7 @@ MonoBehaviour: width: 0 height: 0 HelloString: Hello World + HelloGameObject: {fileID: 0} V3S: - {x: 0, y: 0, z: 0} - {x: 0, y: 0, z: 0} @@ -59,8 +61,8 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 256 - y: 264 + x: 336 + y: 355 width: 0 height: 0 id: bae506a7-58ec-4b79-9c21-747fa2b6a7ba @@ -74,8 +76,8 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 620 - y: 234 + x: 1021.58136 + y: 228.81656 width: 0 height: 0 id: 6ceba867-fe0d-40c3-9d30-2d5d12803b52 @@ -87,8 +89,8 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 469.00006 - y: 336 + x: 758.5814 + y: 309.81662 width: 0 height: 0 id: b2ab4a52-e65d-4104-8891-dc316af217d9 @@ -102,8 +104,8 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 469 - y: 213 + x: 758.5814 + y: 195.81656 width: 0 height: 0 id: ac84573e-638d-45fa-b4e2-1a81c31fa9e7 @@ -112,3 +114,18 @@ MonoBehaviour: isTest: 0 blackDragData: V3S.0 isListElement: 1 + - rid: 4804121563801583947 + type: {class: BlackboardDragNodeData, ns: TNodeCore.Runtime.Models, asm: NewAssembly} + data: + positionInView: + serializedVersion: 2 + x: 299 + y: 313 + width: 0 + height: 0 + id: b8c1e42e-c6a3-491e-aba2-c2b6ebd1c419 + nodeName: + entryPoint: 0 + isTest: 0 + blackDragData: HelloGameObject + isListElement: 0 diff --git a/TNode/TNodeCore/Placemat.meta b/TNode/TNodeCore/Placemat.meta new file mode 100644 index 0000000..a640677 --- /dev/null +++ b/TNode/TNodeCore/Placemat.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6dbc9136434544f1b339c618729e0422 +timeCreated: 1659774798 \ No newline at end of file diff --git a/TNode/TNodeCore/Placemat/IPlacemat.cs b/TNode/TNodeCore/Placemat/IPlacemat.cs new file mode 100644 index 0000000..ace80e5 --- /dev/null +++ b/TNode/TNodeCore/Placemat/IPlacemat.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; +using TNodeCore.Runtime.Models; + +namespace TNodeCore.Placemat{ + public interface IPlacemat{ + public List HoldModels{get;set;} + } +} \ No newline at end of file diff --git a/TNode/TNodeCore/Placemat/IPlacemat.cs.meta b/TNode/TNodeCore/Placemat/IPlacemat.cs.meta new file mode 100644 index 0000000..621e4f8 --- /dev/null +++ b/TNode/TNodeCore/Placemat/IPlacemat.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5e52755cad2a44d3bc705de2bbbca544 +timeCreated: 1659774811 \ No newline at end of file diff --git a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs index 69735f0..7ca5bbe 100644 --- a/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs +++ b/TNode/TNodeCore/Runtime/Components/RuntimeGraph.cs @@ -253,7 +253,7 @@ namespace TNodeCore.Runtime.Components{ _graphTool.RunNodeDependently(Get(startNode)); return true; } - public bool ResolveDependency(){ + public bool TraverseAll(){ if(!_build) Build(); if (_graphTool == null) @@ -342,6 +342,16 @@ namespace TNodeCore.Runtime.Components{ if(isCaching) _graphTool.EndCachingPort(); } + public void RunNodesOfType(bool isCaching= false){ + var nodes = GetRuntimeNodesOfType(); + if(isCaching) + _graphTool.StartCachingPort(); + foreach (var runtimeNode in nodes){ + RunOnDependency(runtimeNode.NodeData); + } + if(isCaching) + _graphTool.EndCachingPort(); + } /// /// Run some nodes ,if the node is not in the graph ,then pass diff --git a/TNode/TNodeCore/Runtime/DataWrapper.cs b/TNode/TNodeCore/Runtime/DataWrapper.cs index 6243362..dcd8ccf 100644 --- a/TNode/TNodeCore/Runtime/DataWrapper.cs +++ b/TNode/TNodeCore/Runtime/DataWrapper.cs @@ -5,6 +5,7 @@ using UnityEngine; namespace TNodeCore.Runtime{ [Serializable] public class DataWrapper:ScriptableObject where TWrapper:DataWrapper,new(){ + public const string DataPath = "data"; [SerializeReference] public TData data; protected static readonly Dictionary Cache = new (); diff --git a/TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs b/TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs index a3d0f69..6b3acf8 100644 --- a/TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs +++ b/TNode/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs @@ -209,12 +209,15 @@ namespace TNodeCore.Runtime.RuntimeCache{ //This inner cache method would only run once,so add a guard to prevent it run again,even though the function itself has a guard statement. if(HasImplicitConversion(from,to)){ CachingImplicitConversion(from,to); + return CachedPortConverters[from][to].Convert(value); } + return value; } if(!CachedPortConverters[from].ContainsKey(to)){ //Just like above, this function should be checked in here too if(HasImplicitConversion(from,to)){ CachingImplicitConversion(from,to); + return CachedPortConverters[from][to].Convert(value); } return value; } diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs index 4eef460..ce4175d 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs @@ -161,7 +161,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ await Task.Delay(TimeSpan.FromSeconds(RefreshRate)); if(_runtimeGraph != null){ if (AutoUpdate){ - _runtimeGraph.ResolveDependency(); + _runtimeGraph.TraverseAll(); AfterGraphResolved?.Invoke(); } } @@ -171,7 +171,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ // if(_runtimeGraph != null){ // if (_runtimeGraphUpdate){ // _runtimeGraphUpdate = false; - // _runtimeGraph.ResolveDependency(); + // _runtimeGraph.TraverseAll(); // // AfterGraphResolved?.Invoke(); // } @@ -204,6 +204,30 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ searchWindow.Setup(typeof(T),this,Owner); SearchWindow.Open(searchWindowContext, searchWindow); }); + evt.menu.AppendAction("Create Placemat",dma=> { + //find placemat container + PlacematContainer placematContainer = this.Q(); + if (placematContainer == null){ + placematContainer = new PlacematContainer(this); + this.Add(placematContainer); + } + var dmaPos = dma.eventInfo.mousePosition+editorPosition; + var dmaPosRect = new Rect(dmaPos,new Vector2(500,500)); + placematContainer.CreatePlacemat(dmaPosRect,1,"Title"); + + // Placemat placemat = new Placemat{ + // Collapsed = false, + // title = "Placemat", + // visible = true + // }; + // placemat.style.minWidth = 500; + // placemat.style.minHeight = 500; + // var dmaPos = dma.eventInfo.mousePosition+editorPosition; + // placemat.SetPosition(new Rect(dmaPos,new Vector2(500,500))); + // AddElement(placemat); + // Debug.Log(placemat); + + }); }); } @@ -274,7 +298,7 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeGraphView{ }; runButton.RegisterCallback(evt => { if (IsRuntimeGraph){ - _runtimeGraph.ResolveDependency(); + _runtimeGraph.TraverseAll(); AfterGraphResolved?.Invoke(); } }); diff --git a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs index 4f417f8..fe19a13 100644 --- a/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs +++ b/TNode/TNodeGraphViewImpl/Editor/NodeViews/DragNodeView.cs @@ -25,10 +25,12 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ SerializedProperty serializedProperty = null; if (arrayElement){ var part = obj.BlackDragData.Split('.'); - serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(part[0]).GetArrayElementAtIndex(int.Parse(part[1])); + serializedProperty = serializedData.FindProperty(BlackboardDataWrapper.DataPath) + .FindPropertyRelative(part[0]) + .GetArrayElementAtIndex(int.Parse(part[1])); } else{ - serializedProperty = serializedData.FindProperty("data").FindPropertyRelative(obj.BlackDragData); + serializedProperty = serializedData.FindProperty(BlackboardDataWrapper.DataPath).FindPropertyRelative(obj.BlackDragData); } label.text = ObjectNames.NicifyVariableName(obj.BlackDragData); //Get serialized property's icon @@ -38,6 +40,9 @@ namespace TNode.TNodeGraphViewImpl.Editor.NodeViews{ icon = AssetPreview.GetMiniThumbnail(value); } else{ + if (serializedProperty.boxedValue == null){ + return; + } icon = AssetPreview.GetMiniTypeThumbnail(serializedProperty.boxedValue.GetType()); }