1 using System.Collections;
2 using System.Collections.Generic;
9 namespace AVR.UI.Link {
11 [RequireComponent(typeof(Toggle))]
14 public override List<System.Type> validTypes =>
new List<System.Type> {typeof(
bool)};
18 protected virtual UnityEngine.Events.UnityAction<
bool> updateValueListener => delegate { this.updateValue(); };
27 UnityEditor.Events.UnityEventTools.RemovePersistentListener(input.onValueChanged, updateValueListener);
28 UnityEditor.Events.UnityEventTools.AddPersistentListener(input.onValueChanged, updateValueListener);
33 public override void init() {
34 if(!input) input = GetComponent<Toggle>();
36 if (input) old_value = input.isOn.ToString();
41 bool val = input.isOn;
47 case MemberType.FIELD:
49 target.GetType().GetField(field).SetValue(target,
50 System.Convert.ChangeType(val, target.GetType().GetField(field).FieldType)
54 case MemberType.PROPERTY:
56 target.GetType().GetProperty(field).SetValue(target,
57 System.Convert.ChangeType(val, target.GetType().GetProperty(field).PropertyType)
63 catch(System.Exception) {
64 AVR_DevConsole.cwarn(
"Could not update the given target value to "+val,
this);
72 bool current_value =
false;
76 case MemberType.FIELD:
78 current_value = (bool)target.GetType().GetField(field).GetValue(target);
81 case MemberType.PROPERTY:
83 current_value = (bool)target.GetType().GetProperty(field).GetValue(target);
88 input.isOn = current_value;
91 if (old_value != current_value.ToString() && !Application.isPlaying)
93 EditorUtility.SetDirty(input);
94 old_value = current_value.ToString();
override void init()
Method is run on program start
override void updateOutput()
Method is run continously from OnGUI. This method should update the value displayed by the UI when th...
override void updateValue()
This method is executed when the runtime user changes the value of the UI element. This method should change the field on the actual target respectively.
Binds a given UI element (such as slider, toggle, dropdown or inputfield) with a given property or fi...
override void setup()
Method is run when the user selects a field in the inspector.