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: outPort:
portEntryName: C portEntryName: C
nodeDataId: 4300534d-023d-4b56-a0cb-39e197e68845 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: blackboardData:
id: 5 id: 5
sceneReference: sceneReference:
@ -84,7 +90,7 @@ MonoBehaviour:
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 781 x: 784
y: 252 y: 252
width: 0 width: 0
height: 0 height: 0
@ -93,29 +99,29 @@ MonoBehaviour:
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
00000003: 00000003:
type: {class: CheckSizeNode, ns: Samples.Nodes, asm: Assembly-CSharp} type: {class: AddNode, ns: Samples.Nodes, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 908 x: 1121
y: 252 y: 187
width: 0 width: 0
height: 0 height: 0
id: f236a611-cc64-4fce-88d2-40baf7f4a490 id: 926f2eea-3403-4663-88bd-7ed16ce029fa
nodeName: CheckSizeNode nodeName: AddNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
00000004: 00000004:
type: {class: AddNode, ns: Samples.Nodes, asm: Assembly-CSharp} type: {class: CheckSizeNode, ns: Samples.Nodes, asm: Assembly-CSharp}
data: data:
positionInView: positionInView:
serializedVersion: 2 serializedVersion: 2
x: 1119 x: 900
y: 210 y: 228
width: 0 width: 0
height: 0 height: 0
id: 926f2eea-3403-4663-88bd-7ed16ce029fa id: f236a611-cc64-4fce-88d2-40baf7f4a490
nodeName: AddNode nodeName: CheckSizeNode
entryPoint: 0 entryPoint: 0
isTest: 0 isTest: 0
00000005: 00000005:
@ -143,6 +149,6 @@ MonoBehaviour:
width: 0 width: 0
height: 0 height: 0
id: id:
persistScale: 1 persistScale: 0.8695652
persistOffset: {x: -212, y: 19} persistOffset: {x: -76, y: 126.00001}
isBlackboardOn: 1 isBlackboardOn: 1

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

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

@ -1,4 +1,6 @@
using Unity.Plastic.Newtonsoft.Json.Serialization; 
using System;
namespace TNodeCore.Runtime.Models{ namespace TNodeCore.Runtime.Models{
public class ConditionalNode:NodeData{ public class ConditionalNode:NodeData{

@ -214,19 +214,21 @@ namespace TNodeCore.Runtime.RuntimeCache{
private void CachingImplicitConversion(Type baseType, Type targetType){ 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 //Create Implicit Conversion Helper that caches the implicit cast function
var typeConverter = Activator.CreateInstance(typeof(ImplicitConversionHelper<,>).MakeGenericType(baseType, targetType)) as IPortConverterHelper; var typeConverter = Activator.CreateInstance(typeof(ImplicitConversionHelper<,>).MakeGenericType(baseType, targetType)) as IPortConverterHelper;
if (!CachedPortConverters.ContainsKey(baseType)){ if (!CachedPortConverters.ContainsKey(baseType)){
CachedPortConverters.Add(baseType,new Dictionary<Type,IPortConverterHelper>()); CachedPortConverters.Add(baseType,new Dictionary<Type,IPortConverterHelper>());
} }
CachedPortConverters[baseType].Add(targetType,typeConverter); CachedPortConverters[baseType].Add(targetType,typeConverter);
} }
public object GetConvertedValue(Type from,Type to,object value){ public object GetConvertedValue(Type from,Type to,object value){
if(!CachedPortConverters.ContainsKey(from)){ if(!CachedPortConverters.ContainsKey(from)){
//Find the cached port failed ,check if there is an implicit conversion //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. //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); var method = typeof(T2).GetMethod("op_Implicit", BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(T1) }, null);
if (method == null){ if (method == null){
//Search it in T1 //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 //Create the delegate
if (method != null) if (method != null)
ConvertFunc = (Func<T1, T2>) Delegate.CreateDelegate(typeof(Func<T1, T2>), method); ConvertFunc = (Func<T1, T2>) Delegate.CreateDelegate(typeof(Func<T1, T2>), method);
if (ConvertFunc == null){
Debug.Log($"{method==null}");
}
} }
public object Convert(object value){ public object Convert(object value){
return ConvertFunc((T1) value); return ConvertFunc((T1) value);
} }
} }

@ -20,7 +20,6 @@ namespace TNodeCore.Runtime.RuntimeModels{
var inNodeId = linkData.inPort.nodeDataId; var inNodeId = linkData.inPort.nodeDataId;
var inNode = _nodes[inNodeId]; var inNode = _nodes[inNodeId];
Debug.Log($"{inNode},{outNode}");
inNode.InputLinks.Add(linkData); inNode.InputLinks.Add(linkData);
} }
public StaticGraph(GraphData graphData){ public StaticGraph(GraphData graphData){

@ -28,7 +28,6 @@ namespace TNodeGraphViewImpl.Editor.GraphWatcherView{
} }
var baseNodeViews = gv.nodes.ToList().Select(x=>(IBaseNodeView)x); var baseNodeViews = gv.nodes.ToList().Select(x=>(IBaseNodeView)x);
var node = baseNodeViews.First(x=>x.GetNodeData().id==runtimeNodeGraph.CurrentNode().id); var node = baseNodeViews.First(x=>x.GetNodeData().id==runtimeNodeGraph.CurrentNode().id);
Debug.Log(node.GetNodeData().id);
var nodeView = (Node)node; var nodeView = (Node)node;
_highlightedNode = nodeView; _highlightedNode = nodeView;
_highlightedNode.AddToClassList("highlightNode"); _highlightedNode.AddToClassList("highlightNode");

Loading…
Cancel
Save