1 using System.Collections;
2 using System.Collections.Generic;
9 namespace AVR.UI.Link {
11 [RequireComponent(typeof(InputField))]
14 public override List<System.Type> validTypes =>
new List<System.Type> {typeof(
bool), typeof(
float), typeof(
int), typeof(
double), typeof(
string)};
18 protected virtual UnityEngine.Events.UnityAction<
string> updateValueListener => delegate { this.updateValue(); };
27 UnityEditor.Events.UnityEventTools.RemovePersistentListener(input.onEndEdit, updateValueListener);
28 UnityEditor.Events.UnityEventTools.AddPersistentListener(input.onEndEdit, updateValueListener);
30 UnityEditor.Events.UnityEventTools.RemovePersistentListener(input.onValueChanged, updateValueListener);
31 UnityEditor.Events.UnityEventTools.AddPersistentListener(input.onValueChanged, updateValueListener);
36 public override void init() {
37 if(!input) input = GetComponent<InputField>();
39 if (input) old_value = input.text.ToString();
45 if (input.isFocused)
return;
48 string text = input.text;
54 case MemberType.FIELD:
56 target.GetType().GetField(field).SetValue(target,
57 System.Convert.ChangeType(text, target.GetType().GetField(field).FieldType)
61 case MemberType.PROPERTY:
63 target.GetType().GetProperty(field).SetValue(target,
64 System.Convert.ChangeType(text, target.GetType().GetProperty(field).PropertyType)
70 catch(System.Exception) {
71 AVR_DevConsole.cwarn(
"Could not update the given target value to "+text,
this);
75 string old_value =
"";
80 if(input.isFocused)
return;
84 object current_value = null;
88 case MemberType.FIELD:
90 current_value = target.GetType().GetField(field).GetValue(target);
93 case MemberType.PROPERTY:
95 current_value = target.GetType().GetProperty(field).GetValue(target);
100 input.text = current_value.ToString();
103 if(old_value!=current_value.ToString() && !Application.isPlaying) {
104 EditorUtility.SetDirty(input);
105 old_value = current_value.ToString();
109 catch(System.Exception) { }
Binds a given UI element (such as slider, toggle, dropdown or inputfield) with a given property or fi...