Forums › 💬 FlowCanvas › ⚙️ Support › two-way binding properties node. › Reply To: two-way binding properties node.
Thanks, It’s works!
I want that user can editing some variables of node through the tools of support.
So, I have created a node custom “TweenPosition” for create an animation of an object in a determinate position (To). You can look my example here:
If you can look at my code I would like to know if it is the correct way to achieve this goal.Basically what I do that when the node is selected I then transfer the reference of the “to” field of the node to an internal my class that serves to manage the waypoint on the scene.
This class is my custom flownode
Tweenposition.cs
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using NodeCanvas.Editor; using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEditor; using UnityEngine; namespace FlowCanvas.Nodes { [Name("Tween Position")] [Category("ActionSwipeStory")] [Description("crea effetto transizione")] public class TweenPosition : FlowControlNode { ValueInput<GameObject> obj; ValueInput<Vector3> to; protected override void RegisterPorts() { obj = AddValueInput<GameObject>("object"); to = AddValueInput<Vector3>("to"); var t = AddValueInput<float>("time"); var start = AddFlowOutput("startEvent"); var end = AddFlowOutput("finishEvent"); AddFlowInput("In", (f) => { Debug.Log("Tween position"); start.Call(f); LeanTween.move(obj.value, to.value, t.value).setOnComplete(() => { end.Call(f); }); }); } protected override void OnNodePicked() { if (obj.value != null) { ConfigurationPlaceholder(); GraphEditorUtility.onActiveElementChanged += onActiveElementChanged; } } void ConfigurationPlaceholder() { Debug.Log("ConfigurationPlaceholder"); if (obj.value != null) { TweenPositionMonoB action = obj.value.GetComponent<TweenPositionMonoB>(); if (action == null) { action = obj.value.AddComponent<TweenPositionMonoB>(); } action.to = to; Selection.activeGameObject = obj.value; } } void OnNodeUnPicked() { Selection.activeGameObject = null; } void onActiveElementChanged(IGraphElement node) { if (node != this) { OnNodeUnPicked(); GraphEditorUtility.onActiveElementChanged -= onActiveElementChanged; } } protected override void OnNodeGUI() { base.OnNodeGUI(); } protected override void OnNodeReleased() { Debug.Log("Nodo rilasciato"); } } } |
This class is useful to create the placeholder waypoint on the object on which the node works
TweenPositionEditor.cs
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; [CustomEditor(typeof(TweenPositionMonoB))] public class TweenPositionEditor : Editor { void OnSceneGUI() { var t = target as TweenPositionMonoB; if (t.to != null) { t.to.serializedValue = Handles.FreeMoveHandle(t.to.value, Quaternion.identity, 0.7f, Vector2.zero, Handles.CylinderHandleCap); Handles.DrawLine(t.transform.localPosition, t.to.value); } } } |
This class does the through to share the variable position of the node “Tweenposition.cs” with the class “TweenPositionEditor.cs “that manage the waypoint drawn the handles on the Scenaview
TweenPositionMonoB.cs
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
using System.Collections; using System.Collections.Generic; using FlowCanvas; using UnityEngine; public class TweenPositionMonoB : MonoBehaviour { public ValueInput<Vector3> to; // Use this for initialization void Start() { } } |
If I may I would ask you another advice. I would like to know when the Serializevalue changes value. I thought I’d extend the class Valueinput<T> and overwrite the serializedvalue set method to launch an event when its value changes from the previous.
