using System; using System.Collections.Generic; using System.Reflection; using Codice.Client.Common.TreeGrouper; using TNodeCore.Attribute.Ports; using TNodeCore.Models; using TNodeCore.RuntimeCache; using UnityEngine; namespace TNodeCore.Runtime{ public class RuntimeNode{ public NodeData NodeData { get; set; } //the link connect to node's in port public List InputLink = new List(); //the link connect to node's out port public List OutputLink = new List(); //Cache node data type for fast access private readonly Type _type; public Type NodeType => _type; public void SetInput(string portName,object value){ var valueType = value.GetType(); var portType = _portAccessors[portName].Type; if(portType!=valueType && !portType.IsAssignableFrom(valueType)){ var res =RuntimeCache.RuntimeCache.Instance.GetConvertedValue(valueType, portType, value); _portAccessors[portName].SetValue(this.NodeData, res); } else{ _portAccessors[portName].SetValue(this.NodeData,value); } } public object GetOutput(string portName){ return _portAccessors[portName].GetValue(this.NodeData); } private readonly Dictionary _portAccessors; public RuntimeNode(NodeData nodeData){ NodeData = nodeData; //Caching the type of the node _type = nodeData.GetType(); var info = nodeData.GetType().GetProperties(); _portAccessors = RuntimeCache.RuntimeCache.Instance.CachedPropertyAccessors[_type]; } public List GetInputNodesId(){ List dependencies = new List(); foreach (NodeLink link in InputLink) { dependencies.Add(link.outPort.nodeDataId); } return dependencies; } } }