1 using System.Collections;
2 using System.Collections.Generic;
9 namespace AVR.UI.Link {
11 [RequireComponent(typeof(Slider))]
14 public override List<System.Type> validTypes =>
new List<System.Type> {typeof(
float), typeof(
int), typeof(
double)};
18 protected virtual UnityEngine.Events.UnityAction<
float> 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<Slider>();
36 if (input) old_value = input.value.ToString();
42 float val = input.value;
48 case MemberType.FIELD:
50 target.GetType().GetField(field).SetValue(target,
51 System.Convert.ChangeType(val, target.GetType().GetField(field).FieldType)
55 case MemberType.PROPERTY:
57 target.GetType().GetProperty(field).SetValue(target,
58 System.Convert.ChangeType(val, target.GetType().GetProperty(field).PropertyType)
64 catch(System.Exception) {
65 AVR_DevConsole.cwarn(
"Could not update the given target value to "+val,
this);
73 float current_value = 0f;
77 case MemberType.FIELD:
79 current_value = (float)target.GetType().GetField(field).GetValue(target);
82 case MemberType.PROPERTY:
84 current_value = (float)target.GetType().GetProperty(field).GetValue(target);
89 input.value = current_value;
92 if (old_value != current_value.ToString() && !Application.isPlaying)
94 EditorUtility.SetDirty(input);
95 old_value = current_value.ToString();
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 updateOutput()
Method is run continously from OnGUI. This method should update the value displayed by the UI when th...
override void init()
Method is run on program start
override void setup()
Method is run when the user selects a field in the inspector.