FlowCanvas Forums › Support › two-way binding properties node. › Reply To: two-way binding properties node.
Regarding the advice I asked you about how I could listen to the change in the value of an ValueInput, I extended the ValueInput class this way:
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 |
using FlowCanvas; using NodeCanvas.Editor; using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEditor; using UnityEngine; namespace MyProject.FlowCanvas { public class ObservableValueInput<T> : global::FlowCanvas.ValueInput<T> { public ObservableValueInput() { } public ObservableValueInput(FlowNode parent, string name, string ID) : base(parent, name, ID) { } public event System.Action<T, T> onValueChanged; public override object serializedValue { get { return base.serializedValue; } set { System.Object oldvalue = base.serializedValue; base.serializedValue = value; if (oldvalue != value) { if (onValueChanged != null) { onValueChanged((T)oldvalue, (T)value); } } } } } } |
I also had to extend the FlowControlNode class by adding the AddObservableValueInput method. The problem that to do this I had to modify the class changing the access level of the QualifyPortNameAndID method and the inputPorts variable from private to protected. How can I achieve the same result without modifying your framework? I do not want to have to report my changes to your framework every time when there is a new update
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 |
using FlowCanvas; using NodeCanvas.Editor; using NodeCanvas.Framework; using ParadoxNotion.Design; using UnityEditor; using UnityEngine; namespace MyProject.FlowCanvas { /// <summary> /// To be able to extend the class correctly, you have changed the visibility levels to the parent class of the source framework: /// inputPorts da private a protected /// QualitiPortNameAndId da private a protected /// /// /// /// </summary> abstract public class FlowControlNode :FlowCanvas.Nodes.FlowControlNode { /// <summary> /// Consente di poter aggiungere al nodo una input port di tipo ObservableValueInput /// in cui ci si può mettere in ascolto quando i suo valore cambia /// </summary> /// <param name="name">porta</param> /// <param name="ID"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public ObservableValueInput<T> AddObservableValueInput<T>(string name, string ID = "") { QualifyPortNameAndID(ref name, ref ID, inputPorts); return (ObservableValueInput<T>)(inputPorts[ID] = new ObservableValueInput<T>(this, name, ID)); } protected override void OnNodePicked() { GraphEditorUtility.onActiveElementChanged += onActiveElementChanged; } protected abstract void OnNodeUnPicked(); void onActiveElementChanged(IGraphElement node) { if (node != this) { OnNodeUnPicked(); GraphEditorUtility.onActiveElementChanged -= onActiveElementChanged; } } } } |