Forums › 💬 FlowCanvas › ⚙️ Support › problem about custom node inherited from flowNode class › Reply To: problem about custom node inherited from flowNode class
here is the custom node code
[Name(“rotate”)]
[Category(“UnityEngine/Transform”)]
[Description(“旋转”)]
public class G_Rotate : FlowNode
{
[SerializeField]
private int index = 0;
public int Index
{
get { return index; }
set
{
if (index != value)
{
index = value;
if (index == 0)
{
name = “rotate(Self)”;
}
else
{
name = “rotate(World)”;
}
GatherPorts();
}
}
}
[SerializeField]
private int mode = 0;
public int Mode
{
get { return mode; }
set
{
if (mode != value)
{
mode = value;
GatherPorts();
}
}
}
protected override void RegisterPorts()
{
var transform = AddValueInput<Transform>(“Transform”);
var outPut = AddFlowOutput(“Out”);
switch (mode)
{
case 0:
{
var axis = AddValueInput<Vector3>(“Axis”);
var angle = AddValueInput<float>(“Angle”);
AddFlowInput(“In”, (f) =>
{
transform.value.Rotate(axis.value, angle.value, index == 0 ? Space.Self : Space.World);
outPut.Call(f);
});
break;
}
case 1:
{
var vector3 = AddValueInput<Vector3>(“Vector3”);
AddFlowInput(“In”, (f) =>
{
transform.value.Rotate(vector3.value, index == 0 ? Space.Self : Space.World);
outPut.Call(f);
});
break;
}
case 2:
{
var floatX = AddValueInput<float>(“X”);
var floatY = AddValueInput<float>(“Y”);
var floatZ = AddValueInput<float>(“Z”);
AddFlowInput(“In”, (f) =>
{
transform.value.Rotate(floatX.value, floatY.value, floatZ.value,
index == 0 ? Space.Self : Space.World);
outPut.Call(f);
});
break;
}
}
}
#if UNITY_EDITOR
protected override void OnNodeInspectorGUI()
{
base.OnNodeInspectorGUI();
Index = UnityEditor.EditorGUILayout.Popup(“Space Type:”, Index, new string[2] { “Self”, “World” });
Mode = UnityEditor.EditorGUILayout.Popup(“Rotate Mode:”,Mode, new string[3] { “Rotate Along Axis”, “Rotate by Vector3”, “Rotate by 3 Float”});
}
#endif
}
