diff --git a/Samples/New HelloGraph.asset b/Samples/New HelloGraph.asset index 2d5317e..54974c3 100644 --- a/Samples/New HelloGraph.asset +++ b/Samples/New HelloGraph.asset @@ -37,6 +37,12 @@ MonoBehaviour: outPort: portEntryName: C nodeDataId: 4300534d-023d-4b56-a0cb-39e197e68845 + - inPort: + portEntryName: A + nodeDataId: 926f2eea-3403-4663-88bd-7ed16ce029fa + outPort: + portEntryName: Bigger + nodeDataId: f236a611-cc64-4fce-88d2-40baf7f4a490 blackboardData: id: 5 sceneReference: @@ -84,7 +90,7 @@ MonoBehaviour: data: positionInView: serializedVersion: 2 - x: 781 + x: 784 y: 252 width: 0 height: 0 @@ -93,29 +99,29 @@ MonoBehaviour: entryPoint: 0 isTest: 0 00000003: - type: {class: CheckSizeNode, ns: Samples.Nodes, asm: Assembly-CSharp} + type: {class: AddNode, ns: Samples.Nodes, asm: Assembly-CSharp} data: positionInView: serializedVersion: 2 - x: 908 - y: 252 + x: 1121 + y: 187 width: 0 height: 0 - id: f236a611-cc64-4fce-88d2-40baf7f4a490 - nodeName: CheckSizeNode + id: 926f2eea-3403-4663-88bd-7ed16ce029fa + nodeName: AddNode entryPoint: 0 isTest: 0 00000004: - type: {class: AddNode, ns: Samples.Nodes, asm: Assembly-CSharp} + type: {class: CheckSizeNode, ns: Samples.Nodes, asm: Assembly-CSharp} data: positionInView: serializedVersion: 2 - x: 1119 - y: 210 + x: 900 + y: 228 width: 0 height: 0 - id: 926f2eea-3403-4663-88bd-7ed16ce029fa - nodeName: AddNode + id: f236a611-cc64-4fce-88d2-40baf7f4a490 + nodeName: CheckSizeNode entryPoint: 0 isTest: 0 00000005: @@ -143,6 +149,6 @@ MonoBehaviour: width: 0 height: 0 id: - persistScale: 1 - persistOffset: {x: -212, y: 19} + persistScale: 0.8695652 + persistOffset: {x: -76, y: 126.00001} isBlackboardOn: 1 diff --git a/Samples/Nodes/CheckSizeNode.cs b/Samples/Nodes/CheckSizeNode.cs index 9a7404c..22019e7 100644 --- a/Samples/Nodes/CheckSizeNode.cs +++ b/Samples/Nodes/CheckSizeNode.cs @@ -9,17 +9,19 @@ namespace Samples.Nodes{ public float A{ get; set; } [Output] - public TransitionCondition Bigger(){ - return new TransitionCondition(){ + public TransitionCondition Bigger(){ + return new TransitionCondition(){ Condition = A>0, - Priority = 0 + Priority = 0, + DataFunc = ()=>A }; } [Output] - public TransitionCondition SmallerOrEqual(){ - return new TransitionCondition(){ + public TransitionCondition SmallerOrEqual(){ + return new TransitionCondition(){ Condition = A<=0, - Priority = 0 + Priority = 0, + DataFunc = ()=>A }; } diff --git a/TNodeCore/Runtime/Components/ConditionalGraph.cs b/TNodeCore/Runtime/Components/ConditionalGraph.cs index 35bfeb8..1fd4c71 100644 --- a/TNodeCore/Runtime/Components/ConditionalGraph.cs +++ b/TNodeCore/Runtime/Components/ConditionalGraph.cs @@ -17,9 +17,6 @@ namespace TNode.TNodeCore.Runtime.Components{ } EntryNode = entry.FirstOrDefault() as ConditionalRuntimeNode; } - - - public void Run(){ var res = StepForward(); while (StepForward().MoveNext()){ diff --git a/TNodeCore/Runtime/Models/ConditionalNode.cs b/TNodeCore/Runtime/Models/ConditionalNode.cs index 11e2eeb..5045711 100644 --- a/TNodeCore/Runtime/Models/ConditionalNode.cs +++ b/TNodeCore/Runtime/Models/ConditionalNode.cs @@ -1,4 +1,6 @@ -using Unity.Plastic.Newtonsoft.Json.Serialization; + + +using System; namespace TNodeCore.Runtime.Models{ public class ConditionalNode:NodeData{ diff --git a/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs b/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs index 8fc673a..33876aa 100644 --- a/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs +++ b/TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs @@ -214,19 +214,21 @@ namespace TNodeCore.Runtime.RuntimeCache{ private void CachingImplicitConversion(Type baseType, Type targetType){ - if (HasImplicitConversion(baseType, targetType)) return; - + if (!HasImplicitConversion(baseType, targetType)) return; + if (CachedPortConverters.ContainsKey(baseType)&&CachedPortConverters[baseType].ContainsKey(targetType)) return; //Create Implicit Conversion Helper that caches the implicit cast function var typeConverter = Activator.CreateInstance(typeof(ImplicitConversionHelper<,>).MakeGenericType(baseType, targetType)) as IPortConverterHelper; if (!CachedPortConverters.ContainsKey(baseType)){ CachedPortConverters.Add(baseType,new Dictionary()); } + CachedPortConverters[baseType].Add(targetType,typeConverter); } public object GetConvertedValue(Type from,Type to,object value){ + if(!CachedPortConverters.ContainsKey(from)){ //Find the cached port failed ,check if there is an implicit conversion //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. @@ -384,14 +386,20 @@ namespace TNodeCore.Runtime.RuntimeCache{ var method = typeof(T2).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T1) }, null); if (method == null){ //Search it in T1 - method = typeof(T1).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T2) }, null); + Debug.Log($"{typeof(T1)}"); + method = typeof(T1).GetMethods(BindingFlags.Public | BindingFlags.Static).FirstOrDefault(x => x.ReturnType==typeof(T2) && x.Name=="op_Implicit"); } //Create the delegate if (method != null) ConvertFunc = (Func) Delegate.CreateDelegate(typeof(Func), method); + if (ConvertFunc == null){ + Debug.Log($"{method==null}"); + + } } public object Convert(object value){ + return ConvertFunc((T1) value); } } diff --git a/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs b/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs index ee2e381..3222bb1 100644 --- a/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs +++ b/TNodeCore/Runtime/RuntimeModels/StaticGraph.cs @@ -20,7 +20,6 @@ namespace TNodeCore.Runtime.RuntimeModels{ var inNodeId = linkData.inPort.nodeDataId; var inNode = _nodes[inNodeId]; - Debug.Log($"{inNode},{outNode}"); inNode.InputLinks.Add(linkData); } public StaticGraph(GraphData graphData){ diff --git a/TNodeGraphViewImpl/Editor/GraphWatcherView/GraphWatcherView.cs b/TNodeGraphViewImpl/Editor/GraphWatcherView/GraphWatcherView.cs index 11812ea..eae51d4 100644 --- a/TNodeGraphViewImpl/Editor/GraphWatcherView/GraphWatcherView.cs +++ b/TNodeGraphViewImpl/Editor/GraphWatcherView/GraphWatcherView.cs @@ -28,7 +28,6 @@ namespace TNodeGraphViewImpl.Editor.GraphWatcherView{ } var baseNodeViews = gv.nodes.ToList().Select(x=>(IBaseNodeView)x); var node = baseNodeViews.First(x=>x.GetNodeData().id==runtimeNodeGraph.CurrentNode().id); - Debug.Log(node.GetNodeData().id); var nodeView = (Node)node; _highlightedNode = nodeView; _highlightedNode.AddToClassList("highlightNode");