diff --git a/TNode/Attribute/BlackboardSection.cs b/TNode/Attribute/BlackboardSection.cs new file mode 100644 index 0000000..bbefd7a --- /dev/null +++ b/TNode/Attribute/BlackboardSection.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using JetBrains.Annotations; + +namespace TNode.Attribute{ + + /// + /// Use this attribute to declare a blackboard section ,a blackboard section is a group of variables with same types + /// + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)] + [BaseTypeRequired(typeof(List<>))] + + public class BlackboardSection:System.Attribute{ + + } +} \ No newline at end of file diff --git a/TNode/Attribute/BlackboardSection.cs.meta b/TNode/Attribute/BlackboardSection.cs.meta new file mode 100644 index 0000000..1794987 --- /dev/null +++ b/TNode/Attribute/BlackboardSection.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 773d073006dc4dd488e18b38165efd5a +timeCreated: 1656942977 \ No newline at end of file diff --git a/TNode/Editor/BaseViews/DataGraphView.cs b/TNode/Editor/BaseViews/DataGraphView.cs index 33d6229..fc11fe7 100644 --- a/TNode/Editor/BaseViews/DataGraphView.cs +++ b/TNode/Editor/BaseViews/DataGraphView.cs @@ -111,7 +111,7 @@ namespace TNode.Editor.BaseViews{ private T _data; private bool _isInspectorOn; - private SearchWindowProvider _searchWindowProvider; + private NodeSearchWindowProvider _nodeSearchWindowProvider; private NodeInspector _nodeInspector; public GraphEditor Owner; private Dictionary _nodeDict = new(); @@ -126,7 +126,51 @@ namespace TNode.Editor.BaseViews{ ResetGraphView(); } } + public event DataChangedEventHandler OnDataChanged; + public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs e); + //A Constructor for the DataGraphView ,never to override it + public DataGraphView(){ + + styleSheets.Add(Resources.Load("GraphViewBackground")); + var grid = new GridBackground(); + Insert(0,grid); + grid.StretchToParentSize(); + this.AddManipulator(new ContentDragger()); + this.AddManipulator(new SelectionDragger()); + this.AddManipulator(new RectangleSelector()); + SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); + OnInit(); + } + private void ConstructDefaultBehaviour(){ + //Register a right click context menu + ConstructViewContextualMenu(); + } + + public void ConstructViewContextualMenu(){ + + //Rebuild the contextual menu + + this.RegisterCallback(evt => { + Vector2 editorPosition = Owner.position.position; + //Remove all the previous menu items + evt.menu.MenuItems().Clear(); + evt.menu.AppendAction("Create Node", dma => { + var dmaPos = dma.eventInfo.mousePosition+editorPosition; + SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200); + var searchWindow = ScriptableObject.CreateInstance(); + searchWindow.Setup(typeof(T),this,Owner); + SearchWindow.Open(searchWindowContext, searchWindow); + }); + + }); + + } + + private void OnInit(){ + ConstructDefaultBehaviour(); + OnGraphViewCreate(); + } public void ResetGraphView(){ //Clear all nodes foreach (var node in nodes){ @@ -145,8 +189,8 @@ namespace TNode.Editor.BaseViews{ var nodeType = dataNode.GetType(); //Get the derived type of NodeAttribute View from the node type - var nodePos = Owner.graphEditorData.nodesData. - FirstOrDefault(x => x.nodeGuid == dataNode.id)?.nodePos??new Rect(0,0,200,200); + var nodePos = Owner.graphEditorData.graphElementsData. + FirstOrDefault(x => x.guid == dataNode.id)?.pos??new Rect(0,0,200,200); AddTNode(dataNode,nodePos); } @@ -157,46 +201,23 @@ namespace TNode.Editor.BaseViews{ var inputNodeView = _nodeDict[inputNode.id]; var outputNodeView = _nodeDict[outputNode.id]; Edge newEdge = new Edge(){ + input = inputNodeView.inputContainer.Q(edge.inPort.portName), output = outputNodeView.outputContainer.Q(edge.outPort.portName) }; + Debug.Log(edge.inPort.portName); + Debug.Log(edge.outPort.portName); newEdge.input?.Connect(newEdge); newEdge.output?.Connect(newEdge); AddElement(newEdge); } _nodeDict.Clear(); } - //A Constructor for the DataGraphView ,never to override it - public DataGraphView(){ - - styleSheets.Add(Resources.Load("GraphViewBackground")); - var grid = new GridBackground(); - Insert(0,grid); - grid.StretchToParentSize(); - this.AddManipulator(new ContentDragger()); - this.AddManipulator(new SelectionDragger()); - this.AddManipulator(new RectangleSelector()); - SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); - OnInit(); - } //OnDataChanged event - public event DataChangedEventHandler OnDataChanged; - public delegate void DataChangedEventHandler(object sender, DataChangedEventArgs e); + - private void ConstructDefaultBehaviour(){ - //Register a right click context menu - //ConstructContextualMenuOption(); - } - public void ConstructViewContextualMenu(EventCallback callback){ - RegisterCallback(callback); - } - - private void OnInit(){ - ConstructDefaultBehaviour(); - OnGraphViewCreate(); - } public virtual void CreateInspector(){ NodeInspector nodeInspector = new NodeInspector(); @@ -213,6 +234,15 @@ namespace TNode.Editor.BaseViews{ public void CreateBlackBoard(){ var blackboard = new Blackboard(); + //Blackboard add "Add Node" button + blackboard.Add(new BlackboardSection(){ + title = "Hello World", + }); + blackboard.addItemRequested = (item) => { + //Create a sub window for the blackboard to show the selection + var subWindow = ScriptableObject.CreateInstance(); + }; + //Set black board to left side of the view blackboard.SetPosition(new Rect(0,0,200,600)); this.Add(blackboard); @@ -234,19 +264,19 @@ namespace TNode.Editor.BaseViews{ } public void SaveEditorData(GraphEditorData graphEditorData){ - graphEditorData.nodesData?.Clear(); + graphEditorData.graphElementsData?.Clear(); //iterator nodes - if (graphEditorData.nodesData == null){ - graphEditorData.nodesData = new List(); + if (graphEditorData.graphElementsData == null){ + graphEditorData.graphElementsData = new List(); } foreach (var node in this.nodes){ - var nodeEditorData = new NodeEditorData{ - nodePos = node.GetPosition(), + var nodeEditorData = new GraphElementEditorData{ + pos = node.GetPosition(), }; if (node is INodeView nodeView){ - nodeEditorData.nodeGuid = nodeView.GetNodeData().id; + nodeEditorData.guid = nodeView.GetNodeData().id; } - graphEditorData.nodesData.Add(nodeEditorData); + graphEditorData.graphElementsData.Add(nodeEditorData); EditorUtility.SetDirty(graphEditorData); } } @@ -278,11 +308,11 @@ namespace TNode.Editor.BaseViews{ var outputNodeData = outputNode.GetNodeData(); var newNodeLink = new NodeLink(new PortInfo(){ nodeDataId = inputNodeData.id, - portName = edge.input.name + portName = edge.input.portName, }, new PortInfo(){ nodeDataId = outputNodeData.id, - portName = edge.output.name + portName = edge.output.portName }); links.Add(newNodeLink); } @@ -335,6 +365,32 @@ namespace TNode.Editor.BaseViews{ nodeViewInterface.SetNodeData(nodeData); } _nodeDict.Add(nodeData.id, nodeView); + + //register an callback ,when right click context menu + nodeView.RegisterCallback(evt => { + var menu = new GenericMenu(); + menu.AddItem(new GUIContent("Delete"), false, () => { + RemoveElement(nodeView); + if (nodeView is INodeView tNodeView){ + var nodeData1 = tNodeView.GetNodeData(); + _data.NodeDictionary.Remove(nodeData1.id); + _nodeDict.Remove(nodeData1.id); + //Break all edges connected to this node + foreach (var edge in edges){ + if (edge.input.node == nodeView || edge.output.node == nodeView){ + RemoveElement(edge); + } + } + Owner.graphEditorData.graphElementsData.RemoveAll(x => x.guid == nodeData1.id); + } + }); + menu.ShowAsContext(); + }); + + + + + } } diff --git a/TNode/Editor/BaseViews/NodeView.cs b/TNode/Editor/BaseViews/NodeView.cs index 13f50d6..b5aca22 100644 --- a/TNode/Editor/BaseViews/NodeView.cs +++ b/TNode/Editor/BaseViews/NodeView.cs @@ -15,7 +15,7 @@ namespace TNode.Editor.BaseViews{ public abstract class NodeView : Node,INodeView where T:NodeData,new(){ protected T _data; private readonly NodeInspectorInNode _nodeInspectorInNode; - + public T Data{ get => _data; set{ @@ -69,6 +69,7 @@ namespace TNode.Editor.BaseViews{ Port port = InstantiatePort(Orientation.Horizontal, Direction.Output,Port.Capacity.Multi,propertyInfo.PropertyType); this.outputContainer.Add(port); port.portName = propertyInfo.Name; + port.name = propertyInfo.Name; } } foreach (var propertyInfo in propertyInfos){ @@ -78,6 +79,7 @@ namespace TNode.Editor.BaseViews{ Port port = InstantiatePort(Orientation.Horizontal, Direction.Input,Port.Capacity.Multi,propertyInfo.PropertyType); this.inputContainer.Add(port); port.portName = propertyInfo.Name; + port.name = propertyInfo.Name; } } } diff --git a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs b/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs index 6eb82cf..da03952 100644 --- a/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs +++ b/TNode/Editor/BaseViews/SimpleGraphSubWindow.cs @@ -41,7 +41,7 @@ namespace TNode.BaseViews{ } public void ResetPos(GraphEditorData editorData){ - var res = editorData.subWindowPos.FirstOrDefault(x => x.nodeGuid == this.GetPersistenceId()); + var res = editorData.graphElementsData.FirstOrDefault(x => x.guid == this.GetPersistenceId()); } public void SavePos(GraphEditorData editorData){ diff --git a/TNode/Editor/EditorPersistence/GraphEditorData.cs b/TNode/Editor/EditorPersistence/GraphEditorData.cs index e096ec5..02fc71c 100644 --- a/TNode/Editor/EditorPersistence/GraphEditorData.cs +++ b/TNode/Editor/EditorPersistence/GraphEditorData.cs @@ -2,14 +2,12 @@ using TNode.Editor.EditorPersistence; using TNode.Editor.Model; using UnityEngine; +using UnityEngine.Serialization; namespace TNode.Editor{ - [CreateAssetMenu(fileName = "NodeAttribute Editor Config", menuName = "TNode/NodeAttribute Editor Config")] + [CreateAssetMenu(fileName = "Graph Editor Data", menuName = "TNode/Graph Editor Data")] public class GraphEditorData:ScriptableObject{ - public List nodesData; - public List subWindowPos; - - public List graphViewPersistence; + public List graphElementsData; } } \ No newline at end of file diff --git a/TNode/Editor/EditorPersistence/NodeEditorData.cs b/TNode/Editor/EditorPersistence/GraphElementEditorData.cs similarity index 61% rename from TNode/Editor/EditorPersistence/NodeEditorData.cs rename to TNode/Editor/EditorPersistence/GraphElementEditorData.cs index 9f38640..f21170d 100644 --- a/TNode/Editor/EditorPersistence/NodeEditorData.cs +++ b/TNode/Editor/EditorPersistence/GraphElementEditorData.cs @@ -6,8 +6,8 @@ using UnityEngine.Serialization; namespace TNode.Editor.Model{ [Serializable] - public class NodeEditorData{ - public string nodeGuid; - public Rect nodePos; + public class GraphElementEditorData{ + public string guid; + public Rect pos; } } \ No newline at end of file diff --git a/TNode/Editor/EditorPersistence/NodeEditorData.cs.meta b/TNode/Editor/EditorPersistence/GraphElementEditorData.cs.meta similarity index 100% rename from TNode/Editor/EditorPersistence/NodeEditorData.cs.meta rename to TNode/Editor/EditorPersistence/GraphElementEditorData.cs.meta diff --git a/TNode/Editor/GraphBlackboard.meta b/TNode/Editor/GraphBlackboard.meta new file mode 100644 index 0000000..5c57522 --- /dev/null +++ b/TNode/Editor/GraphBlackboard.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 476d14ab24734294b206f16006438e60 +timeCreated: 1656941713 \ No newline at end of file diff --git a/TNode/Editor/GraphBlackboard/GraphBlackboard.cs b/TNode/Editor/GraphBlackboard/GraphBlackboard.cs new file mode 100644 index 0000000..40b9e3d --- /dev/null +++ b/TNode/Editor/GraphBlackboard/GraphBlackboard.cs @@ -0,0 +1,12 @@ +using TNode.Models; +using UnityEditor.Experimental.GraphView; + +namespace TNode.Editor.GraphBlackboard{ + /// + /// Implement this class to create graph black board for specified graph + /// + public class GraphBlackboard:Blackboard where T:BlackboardData{ + public T BlackboardData; + + } +} \ No newline at end of file diff --git a/TNode/Editor/GraphBlackboard/GraphBlackboard.cs.meta b/TNode/Editor/GraphBlackboard/GraphBlackboard.cs.meta new file mode 100644 index 0000000..3b9d3e8 --- /dev/null +++ b/TNode/Editor/GraphBlackboard/GraphBlackboard.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 285d836db7e04e2f989069277fd1853a +timeCreated: 1656941728 \ No newline at end of file diff --git a/TNode/Editor/GraphEditor.cs b/TNode/Editor/GraphEditor.cs index 48ad37a..7619b74 100644 --- a/TNode/Editor/GraphEditor.cs +++ b/TNode/Editor/GraphEditor.cs @@ -39,19 +39,6 @@ namespace TNode.Editor{ _graphView = NodeEditorExtensions.CreateInstance>(); rootVisualElement.Add(_graphView); _graphView.StretchToParentSize(); - _graphView.ConstructViewContextualMenu(evt => { - //Current issue is that the search window don't show up at the exact position of the mouse click by dma.eventInfo.mousePosition - //So I have to manually set the position of the search window to fit the mouse click position by add an offset driven by Editor's position - //Maybe a better way exists to fix this issue - Vector2 editorPosition = this.position.position; - evt.menu.AppendAction("Create Node", dma => { - var dmaPos = dma.eventInfo.mousePosition+editorPosition; - SearchWindowContext searchWindowContext = new SearchWindowContext(dmaPos,200,200); - var searchWindow = CreateInstance(); - searchWindow.Setup(typeof(T),_graphView,this); - SearchWindow.Open(searchWindowContext, searchWindow); - }); - }); } private void DefineGraphEditorActions(){ diff --git a/TNode/Editor/Search.meta b/TNode/Editor/Search.meta new file mode 100644 index 0000000..c1c4f31 --- /dev/null +++ b/TNode/Editor/Search.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 4fe6a069e0cc45158b4749dbdb7fd399 +timeCreated: 1656942698 \ No newline at end of file diff --git a/TNode/Editor/Search/BlackboardSearchWindowProvider.cs b/TNode/Editor/Search/BlackboardSearchWindowProvider.cs new file mode 100644 index 0000000..53dfcbb --- /dev/null +++ b/TNode/Editor/Search/BlackboardSearchWindowProvider.cs @@ -0,0 +1,5 @@ +namespace TNode.Editor{ + public class BlackboardSearchWindowProvider{ + + } +} \ No newline at end of file diff --git a/TNode/Editor/Search/BlackboardSearchWindowProvider.cs.meta b/TNode/Editor/Search/BlackboardSearchWindowProvider.cs.meta new file mode 100644 index 0000000..56fdf8c --- /dev/null +++ b/TNode/Editor/Search/BlackboardSearchWindowProvider.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 73c77be1f9364a0199d95eea7e7c0101 +timeCreated: 1656942712 \ No newline at end of file diff --git a/TNode/Editor/SearchWindowProvider.cs b/TNode/Editor/Search/NodeSearchWindowProvider.cs similarity index 94% rename from TNode/Editor/SearchWindowProvider.cs rename to TNode/Editor/Search/NodeSearchWindowProvider.cs index e719cbe..58a3c1d 100644 --- a/TNode/Editor/SearchWindowProvider.cs +++ b/TNode/Editor/Search/NodeSearchWindowProvider.cs @@ -12,7 +12,7 @@ using UnityEngine; using UnityEngine.UIElements; namespace TNode.Editor{ - public class SearchWindowProvider:ScriptableObject,ISearchWindowProvider{ + public class NodeSearchWindowProvider:ScriptableObject,ISearchWindowProvider{ private Type _graphType; private GraphView _graphView; private EditorWindow _editor; @@ -58,7 +58,7 @@ namespace TNode.Editor{ return false; } - public SearchWindowProvider(){ + public NodeSearchWindowProvider(){ } } } \ No newline at end of file diff --git a/TNode/Editor/SearchWindowProvider.cs.meta b/TNode/Editor/Search/NodeSearchWindowProvider.cs.meta similarity index 100% rename from TNode/Editor/SearchWindowProvider.cs.meta rename to TNode/Editor/Search/NodeSearchWindowProvider.cs.meta diff --git a/TNode/JsonSerialize/JsonSerializeTool.cs b/TNode/JsonSerialize/JsonSerializeTool.cs index 47c6553..e886ccf 100644 --- a/TNode/JsonSerialize/JsonSerializeTool.cs +++ b/TNode/JsonSerialize/JsonSerializeTool.cs @@ -1,16 +1,28 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; + namespace TNode.JsonSerialize{ - public class JsonSerializeTool{ + public static class JsonSerializeTool{ + class WritablePropertiesOnlyResolver : DefaultContractResolver + { + protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) + { + IList props = base.CreateProperties(type, memberSerialization); + return props.Where(p => p.Writable).ToList(); + } + } public static JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings(){ ReferenceLoopHandling = ReferenceLoopHandling.Ignore, NullValueHandling = NullValueHandling.Ignore, DateFormatString = "yyyy-MM-dd HH:mm:ss", Converters = new List { new Vector3Converter() }, - TypeNameHandling = TypeNameHandling.Auto - + TypeNameHandling = TypeNameHandling.Auto, + ContractResolver = new WritablePropertiesOnlyResolver() + }; public static JsonSerializerSettings InternalJsonSerializerSettings = new JsonSerializerSettings(){ diff --git a/TNode/JsonSerialize/Vector3Converter.cs b/TNode/JsonSerialize/Vector3Converter.cs index 7484816..00d4f93 100644 --- a/TNode/JsonSerialize/Vector3Converter.cs +++ b/TNode/JsonSerialize/Vector3Converter.cs @@ -21,7 +21,6 @@ namespace TNode.JsonSerialize{ if (array != null) return new Vector3(array[0], array[1], array[2]); } - return default(Vector3); } diff --git a/TNode/Models/BlackDragNodeData.cs b/TNode/Models/BlackDragNodeData.cs new file mode 100644 index 0000000..6038a6f --- /dev/null +++ b/TNode/Models/BlackDragNodeData.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; +using TNode.Attribute.Ports; + +namespace TNode.Models{ + public class BlackDragNodeData:NodeData{ + [JsonIgnore] + private string _blackDragData; + [JsonIgnore] + private BlackboardData _blackboardData; + + } +} \ No newline at end of file diff --git a/TNode/Models/BlackDragNodeData.cs.meta b/TNode/Models/BlackDragNodeData.cs.meta new file mode 100644 index 0000000..fd3d40d --- /dev/null +++ b/TNode/Models/BlackDragNodeData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: f6434bdf404f4ee892274b61db24d0f8 +timeCreated: 1656943697 \ No newline at end of file diff --git a/TNode/Models/BlackboardData.cs b/TNode/Models/BlackboardData.cs new file mode 100644 index 0000000..5d60568 --- /dev/null +++ b/TNode/Models/BlackboardData.cs @@ -0,0 +1,6 @@ +namespace TNode.Models{ + + public class BlackboardData{ + + } +} \ No newline at end of file diff --git a/TNode/Models/BlackboardData.cs.meta b/TNode/Models/BlackboardData.cs.meta new file mode 100644 index 0000000..6e52149 --- /dev/null +++ b/TNode/Models/BlackboardData.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 395a389740e542ea9930248876904aee +timeCreated: 1656940618 \ No newline at end of file diff --git a/TNode/Models/GraphData.cs b/TNode/Models/GraphData.cs index bacbe9e..2d4d323 100644 --- a/TNode/Models/GraphData.cs +++ b/TNode/Models/GraphData.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; +using TNode.Editor; using TNode.JsonSerialize; +using UnityEditor.Experimental.GraphView; using UnityEngine.Serialization; namespace TNode.Models{ @@ -10,24 +12,27 @@ namespace TNode.Models{ public class GraphData:ScriptableObject,ISerializationCallbackReceiver{ [SerializeField] public Dictionary NodeDictionary = new Dictionary(); - public List nodeLinks = new List(); - - + public List nodeLinks = new(); + public BlackboardData blackboardData = new(); + [TextArea(1,10)] [SerializeField] - [TextArea] //[HideInInspector] private string jsonObject; - + [TextArea(1,10)] + [SerializeField] + private string jsonBlackboard; public void OnBeforeSerialize(){ - var serializedData = JsonConvert.SerializeObject(NodeDictionary,JsonSerializeTool.JsonSerializerSettings); - - jsonObject = serializedData; + jsonObject = JsonConvert.SerializeObject(NodeDictionary,JsonSerializeTool.JsonSerializerSettings); + jsonBlackboard = JsonConvert.SerializeObject(blackboardData,JsonSerializeTool.JsonSerializerSettings); } - public void OnAfterDeserialize(){ + //Deserialize node dictionary var deserializedData = JsonConvert.DeserializeObject>(jsonObject,JsonSerializeTool.JsonSerializerSettings); - var deserializedData2 = JsonUtility.FromJson>(jsonObject); NodeDictionary = deserializedData; + //Deserialize blackboard data + var deserializedBlackboard = JsonConvert.DeserializeObject(jsonBlackboard,JsonSerializeTool.JsonSerializerSettings); + blackboardData = deserializedBlackboard; + Debug.Log("hi"); } } diff --git a/TNode/Models/NodeData.cs b/TNode/Models/NodeData.cs index 53a5aef..d9c6bf9 100644 --- a/TNode/Models/NodeData.cs +++ b/TNode/Models/NodeData.cs @@ -21,6 +21,12 @@ namespace TNode.Models{ public string id; public string nodeName; public bool entryPoint; + + + public virtual void OnProcess(){ + + } + // #if UNITY_EDITOR // public Rect rect; // #endif diff --git a/TNode/Runtime/RuntimeGraph.cs b/TNode/Runtime/RuntimeGraph.cs index 55e11d1..1a140b7 100644 --- a/TNode/Runtime/RuntimeGraph.cs +++ b/TNode/Runtime/RuntimeGraph.cs @@ -1,9 +1,28 @@ -using TNode.Models; +using System.Collections; +using System.Collections.Generic; +using TNode.Models; using UnityEngine; namespace TNode.Runtime{ public class RuntimeGraph:MonoBehaviour{ public GraphData graphData; + public SortedSet _sortedSet; + + public void Start(){ + //iterate through all nodes and add them to the sorted set + foreach (var node in graphData.NodeDictionary.Values){ + + } + } + + public void StartProcessNode(ProcessingStrategy strategy, RuntimeNode entry){ + + } } + + public enum ProcessingStrategy{ + BreadthFirst, + DepthFirst + } } \ No newline at end of file diff --git a/TNode/Runtime/RuntimeNode.cs b/TNode/Runtime/RuntimeNode.cs index 94a84ec..2376057 100644 --- a/TNode/Runtime/RuntimeNode.cs +++ b/TNode/Runtime/RuntimeNode.cs @@ -5,17 +5,11 @@ using System.Linq; using TNode.Models; namespace TNode.Runtime{ - public class RuntimeNode where T:NodeData{ - public T NodeData{ get; set; } - - //Links related to runtime node,for fast access.only remember out links + public abstract class RuntimeNode{ + public NodeData NodeData; public List NodeLinks; - - - public void Process(){ - - var outputPorts = NodeLinks.Select(x => x.outPort.portName); + public void ProcessThisNode(){ + NodeData.OnProcess(); } - } } \ No newline at end of file diff --git a/TNode/RuntimeCache/RuntimeCache.cs b/TNode/RuntimeCache/RuntimeCache.cs index 464bd79..4ec50ce 100644 --- a/TNode/RuntimeCache/RuntimeCache.cs +++ b/TNode/RuntimeCache/RuntimeCache.cs @@ -34,13 +34,18 @@ namespace TNode.RuntimeCache{ var type = typeof(T); if(!CachedDelegatesForGettingValue.ContainsKey(type)){ CachedDelegatesForGettingValue.Add(type, new List()); + var properties = type.GetProperties(); + foreach(var property in properties){ + var getValueDelegate = GetValueDelegateForProperty(property); + CachedDelegatesForGettingValue[type].Add(getValueDelegate); + } } - //iterate properties of the nodeData and add them to the cache - var properties = type.GetProperties(); - foreach(var property in properties){ - var getValueDelegate = GetValueDelegateForProperty(property); - CachedDelegatesForGettingValue[type].Add(getValueDelegate); + else{ + //Cache already exists for this type + } + + }