You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I have a couple layers of inheritance first. It looks like this: BaseNode > DynamicNode > SequenceNode
In Dynamic node I'm creating ports on the fly with CustomPortBehavior and CustomPortInput. Everything works how you would expect except I'd prefer if the ports were reordered so I did by implementing the OverrideFieldOrder method. Essentially all I'm doing is reversing the original order. i.e. return base.OverrideFieldOrder(fields).Reverse();.
Also for some reason the property drawer for a float in DynamicNode is in the wrong place by default.
The order is reversed correctly but when creating a connection node in the menu it doesn't pickup up the correct type.
Before (Dragging&Dropping an edge):
After (Dragging&Dropping an edge):
The float itself does work before and after so I think it could be some kind of generic inheritance thing.
Code For DynamicNode:
DynamicNode Code
usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;usingGraphProcessor;usingSystem.Linq;usingSystem.Reflection;usingSystem;[System.Serializable]publicabstractclassDynamicNode<T>:BaseNode{[Input("Action Data")]publicDictionary<string,object>actionData=newDictionary<string,object>();[Input("Float Val"),SerializeField]publicfloatfloatVal;[SerializeField,ExpandableSO,ValueChangedCallback(nameof(OnDataChanged))]publicTdata;protectedoverridevoidProcess(){UpdateActionWithCustomPortData();}protectedvirtualvoidUpdateActionWithCustomPortData(){// We clone due to reference issuesDictionary<string,object>actionDataClone=newDictionary<string,object>(actionData);foreach(varfieldinGetInputFieldsOfType()){if(!actionDataClone.ContainsKey(field.fieldInfo.Name)){field.fieldInfo.SetValue(data,default);}else{field.fieldInfo.SetValue(data,actionDataClone[field.fieldInfo.Name]);}}actionData.Clear();}protectedvirtualvoidOnDataChanged(UnityEditor.SerializedPropertyserializedProperty){UpdatePortsForFieldLocal(nameof(actionData));}
#region Reflection Generation Of Ports
privateList<FieldPortInfo>GetInputFieldsOfType(){List<FieldPortInfo>foundInputFields=newList<FieldPortInfo>();TypedataType=actionData!=null?data.GetType():typeof(T);foreach(varfieldindataType.GetFields(BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Public)){foreach(varattributeinfield.GetCustomAttributes(typeof(InputAttribute),true)){if(attribute.GetType()!=typeof(InputAttribute))continue;foundInputFields.Add(newFieldPortInfo(field,attributeasInputAttribute));break;}}returnfoundInputFields;}[CustomPortInput(nameof(actionData),typeof(object))]protectedvoidPullInputs(List<SerializableEdge>connectedEdges){if(actionData==null)actionData=newDictionary<string,object>();foreach(SerializableEdgetinconnectedEdges){actionData.Add(t.inputPortIdentifier,t.passThroughBuffer);}}[CustomPortBehavior(nameof(actionData))]protectedIEnumerable<PortData>ActionDataBehaviour(List<SerializableEdge>edges){foreach(varfieldinGetInputFieldsOfType()){yieldreturnnewPortData{displayName=field.inputAttribute.name,displayType=field.fieldInfo.FieldType,identifier=field.fieldInfo.Name,acceptMultipleEdges=false,};}}publicoverrideIEnumerable<FieldInfo>OverrideFieldOrder(IEnumerable<FieldInfo>fields){returnbase.OverrideFieldOrder(fields).Reverse();// static long GetFieldInheritanceLevel(FieldInfo f)// {// int level = 0;// var t = f.DeclaringType;// while (t != null)// {// t = t.BaseType;// level++;// }// return level;// }// // Order by MetadataToken and inheritance level to sync the order with the port order (make sure FieldDrawers are next to the correct port)// return fields.OrderByDescending(f => (GetFieldInheritanceLevel(f) << 32) | (long)f.MetadataToken);}
#endregion
}publicstructFieldPortInfo{publicFieldInfofieldInfo;publicInputAttributeinputAttribute;publicFieldPortInfo(FieldInfofieldInfo,InputAttributeinputAttribute){this.fieldInfo=fieldInfo;this.inputAttribute=inputAttribute;}}
The text was updated successfully, but these errors were encountered:
So I have a couple layers of inheritance first. It looks like this: BaseNode > DynamicNode > SequenceNode
In Dynamic node I'm creating ports on the fly with CustomPortBehavior and CustomPortInput. Everything works how you would expect except I'd prefer if the ports were reordered so I did by implementing the OverrideFieldOrder method. Essentially all I'm doing is reversing the original order. i.e.
return base.OverrideFieldOrder(fields).Reverse();
.Also for some reason the property drawer for a float in DynamicNode is in the wrong place by default.
The order is reversed correctly but when creating a connection node in the menu it doesn't pickup up the correct type.
Before (Dragging&Dropping an edge):
After (Dragging&Dropping an edge):
The float itself does work before and after so I think it could be some kind of generic inheritance thing.
Code For DynamicNode:
DynamicNode Code
The text was updated successfully, but these errors were encountered: