fix:support type conversion for multiport

main
taoria 3 years ago
parent 985f5e5638
commit 3487a24680
  1. 6
      Samples/AddNode.cs
  2. 28
      TNodeCore/Runtime/RuntimeNode.cs
  3. 1
      TNodeGraphViewImpl/Editor/NodeGraphView/DataGraphView.cs
  4. 2
      TNodeGraphViewImpl/Editor/NodeViews/NodeView.cs

@ -1,4 +1,6 @@

using System.Collections.Generic;
using System.Runtime.InteropServices;
using TNodeCore.Runtime;
using TNodeCore.Runtime.Attributes;
using TNodeCore.Runtime.Attributes.Ports;
@ -15,6 +17,10 @@ namespace Samples{
[Output]
public Vector3 Res{ get; set; }
[Output(Group = true)] public List<Vector3> OutputList => new List<Vector3>{new Vector3(),new Vector3()};
public override void Process(){
Res = A + (Vector3)B;
Debug.Log(Res);

@ -17,18 +17,38 @@ namespace TNodeCore.Runtime{
private readonly Type _type;
public Type NodeType => _type;
public Type GetElementTypeOfPort(string portName,bool multi = false){
var type = _portAccessors[portName].Type;
if (multi == false)
return type;
if (type.IsArray){
return type.GetElementType();
}
if (type.IsGenericType){
return type.GetGenericArguments()[0];
}
return type;
}
public void SetInput(string portName,object value){
var valueType = value.GetType();
var portPath = portName.Split(':');
if (portPath.Length ==2){
portName = portPath[0];
int index = int.Parse(portPath[1]);
if(_portAccessors[portName].Type.IsArray){
if (_portAccessors[portName].GetValue(NodeData) is Array array)
var realPortType = GetElementTypeOfPort(portName, true);
if (realPortType != valueType){
value = RuntimeCache.RuntimeCache.Instance.GetConvertedValue(valueType,realPortType,value);
}
if(realPortType.IsArray){
if (_portAccessors[portName].GetValue(NodeData) is Array array){
array.SetValue(value, index);
}
if (_portAccessors[portName].Type.IsGenericType){
}
if (realPortType.IsGenericType){
if (_portAccessors[portName].GetValue(NodeData) is IList list)
list[index] = value;
}

@ -604,7 +604,6 @@ namespace TNodeGraphViewImpl.Editor.NodeGraphView{
private void SaveEditorModels(){
var placemats = placematContainer.Placemats.ToList();
var comments = this.Query<CommentView>().ToList();
Debug.Log(placemats.Count);
foreach (var placemat in placemats){
if (placemat is PlacematView placematView){
_data.EditorModels.Add(placematView.PlacematModel);

@ -224,7 +224,7 @@ namespace TNodeGraphViewImpl.Editor.NodeViews{
BuildPort(port, attribute, propertyInfo,outputContainer);
}
else{
var propertyValue = _data.GetValue(propertyInfo.Name);
var propertyValue = propertyInfo.GetValue(_data);
if (propertyValue is IList list){
for (var i = 0; i < list.Count; i++){
var port = new CustomPort(Orientation.Horizontal, Direction.Output,

Loading…
Cancel
Save