fix:implict conversion bug fix

main
taoria 3 years ago
parent a8ed2ff94d
commit 1cb16c082b
  1. 32
      Samples/New HelloGraph.asset
  2. 14
      Samples/Nodes/CheckSizeNode.cs
  3. 3
      TNodeCore/Runtime/Components/ConditionalGraph.cs
  4. 4
      TNodeCore/Runtime/Models/ConditionalNode.cs
  5. 14
      TNodeCore/Runtime/RuntimeCache/RuntimeCache.cs
  6. 1
      TNodeCore/Runtime/RuntimeModels/StaticGraph.cs
  7. 1
      TNodeGraphViewImpl/Editor/GraphWatcherView/GraphWatcherView.cs

@ -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

@ -9,17 +9,19 @@ namespace Samples.Nodes{
public float A{ get; set; }
[Output]
public TransitionCondition Bigger(){
return new TransitionCondition(){
public TransitionCondition<float> Bigger(){
return new TransitionCondition<float>(){
Condition = A>0,
Priority = 0
Priority = 0,
DataFunc = ()=>A
};
}
[Output]
public TransitionCondition SmallerOrEqual(){
return new TransitionCondition(){
public TransitionCondition<float> SmallerOrEqual(){
return new TransitionCondition<float>(){
Condition = A<=0,
Priority = 0
Priority = 0,
DataFunc = ()=>A
};
}

@ -17,9 +17,6 @@ namespace TNode.TNodeCore.Runtime.Components{
}
EntryNode = entry.FirstOrDefault() as ConditionalRuntimeNode;
}
public void Run(){
var res = StepForward();
while (StepForward().MoveNext()){

@ -1,4 +1,6 @@
using Unity.Plastic.Newtonsoft.Json.Serialization;

using System;
namespace TNodeCore.Runtime.Models{
public class ConditionalNode:NodeData{

@ -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<Type,IPortConverterHelper>());
}
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<T1, T2>) Delegate.CreateDelegate(typeof(Func<T1, T2>), method);
if (ConvertFunc == null){
Debug.Log($"{method==null}");
}
}
public object Convert(object value){
return ConvertFunc((T1) value);
}
}

@ -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){

@ -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");

Loading…
Cancel
Save