/// <summary> /// Constructs a new Property /// </summary> /// <param name="owner">The owner of the property</param> /// <param name="defaultValue">The default and initial value of the property</param> /// <param name="onValueChanged">A callback for when the property value changes</param> public Property(TOwner owner, TValue defaultValue, OnValueChangedDelegate onValueChanged) { Owner = owner; DefaultValue = defaultValue; LoadValue(defaultValue); OnValueChanged = onValueChanged; }
public void PushOnChanged(OnValueChangedDelegate callback) { if (OnChangedStack == null) { OnChangedStack = new Stack <OnValueChangedDelegate>(); } OnChangedStack.Push(OnChanged); OnChanged = callback; }
public void Poke() { if (OnChanged != null) { OnChanged.Invoke(this); } var call = OnChangedOnceOnly; if (call != null) { OnChangedOnceOnly = null; call(this); } }
void AddIntSlider(SerializedProperty property, string text, string tooltip, OnValueChangedDelegate <int> onChange = null, int min = 0, int max = int.MaxValue) { Rect ourRect = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginProperty(ourRect, GUIContent.none, property); var orgValue = property.intValue; var newValue = EditorGUILayout.IntSlider(new GUIContent(text, tooltip), orgValue, min, max); if (onChange != null && orgValue != newValue) { newValue = onChange(orgValue, newValue); } property.intValue = newValue; EditorGUI.EndProperty(); EditorGUILayout.EndHorizontal(); }
/// <summary> /// 状態が変化した際に呼び出されるデリゲートを削除する /// </summary> /// <param name="tOnValueChangedDelegate">デリゲートメソッド</param> public void RemoveOnValueChanged(OnValueChangedDelegate tOnValueChangedDelegate) { onValueChangedDelegate -= tOnValueChangedDelegate; }
/// <summary> /// 状態が変化した際に呼び出されるデリゲートを追加する /// </summary> /// <param name="tOnValueChangedDelegate">デリゲートメソッド</param> public void AddOnValueChanged(OnValueChangedDelegate tOnValueChangedDelegate) { onValueChangedDelegate += tOnValueChangedDelegate; }
public void Unsubscribe(OnValueChangedDelegate d) { if(del != null) del -= d; }
public void Subscribe(OnValueChangedDelegate d) { Subscribe(d, true); }
public void Subscribe(OnValueChangedDelegate d, bool callNow) { if(del == null) del = d; else del += d; if(callNow) d(value); }
public void RegisterOnHealthValueChangedEventListener(OnValueChangedDelegate OnValueChangedDelegate) { this.OnHealthValueChangedEvent += OnValueChangedDelegate; /// Initialize the added event by manually calling it OnValueChangedDelegate.Invoke(this.CurrentHealth.GetValue(), this.CurrentHealth.GetValue()); }
void AddFloatSlider(SerializedProperty property, string text, string tooltip, OnValueChangedDelegate <float> onChange = null, float factor = 1f, float min = 0, float max = float.MaxValue) { Rect ourRect = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginProperty(ourRect, GUIContent.none, property); var orgValue = property.floatValue * factor; var newValue = EditorGUILayout.Slider(new GUIContent(text, tooltip), orgValue, min * factor, max * factor) / factor; if (onChange != null && orgValue != newValue) { newValue = onChange(orgValue, newValue); } property.floatValue = newValue; EditorGUI.EndProperty(); EditorGUILayout.EndHorizontal(); }
void AddEnumPopup(SerializedProperty property, string text, string tooltip, Type typeOfEnum, OnValueChangedDelegate <int> onChange = null) { Rect ourRect = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginProperty(ourRect, GUIContent.none, property); int selectionFromInspector = property.intValue; string[] enumNamesList = System.Enum.GetNames(typeOfEnum); var actualSelected = EditorGUILayout.Popup(text, selectionFromInspector, enumNamesList); if (onChange != null && actualSelected != property.intValue) { actualSelected = onChange(property.intValue, actualSelected); } property.intValue = actualSelected; EditorGUI.EndProperty(); EditorGUILayout.EndHorizontal(); }
public FloatVariable(float startValue, OnValueChangedDelegate onValueChanged = null) { Value = startValue; OnValueChanged = onValueChanged; }
/// <summary> /// Constructs a new Property /// </summary> /// <param name="defaultValue">The default and initial value of the property</param> /// <param name="onValueChanged">A callback for when the property value changes</param> public Property(TValue defaultValue, OnValueChangedDelegate onValueChanged = null) : this(default(TOwner), defaultValue, onValueChanged) { }
/// <summary> /// Constructs a new Property /// </summary> /// <param name="owner">The owner of the property</param> /// <param name="onValueChanged">A callback for when the property value changes</param> public Property(TOwner owner, OnValueChangedDelegate onValueChanged = null) : this(owner, default(TValue), onValueChanged) { }
void AddBoolProperty(SerializedProperty property, string text, string tooltip, OnValueChangedDelegate <bool> onChange = null) { Rect ourRect = EditorGUILayout.BeginHorizontal(); EditorGUI.BeginProperty(ourRect, GUIContent.none, property); var orgValue = property.boolValue; var newValue = EditorGUILayout.Toggle(new GUIContent(text, tooltip), orgValue); if (onChange != null && orgValue != newValue) { newValue = onChange(orgValue, newValue); } property.boolValue = newValue; EditorGUI.EndProperty(); EditorGUILayout.EndHorizontal(); }
public HealthSystem(CoreInteractiveObject AssociatedInteractiveObject, HealthSystemDefinition HealthSystemDefinition, OnValueChangedDelegate OnHealthValueChangedAction = null) { this.AssociatedInteractiveObject = AssociatedInteractiveObject; this.HealthSystemDefinition = HealthSystemDefinition; /// By default, the constructor OnValueChangedDelegate is registered to OnValueChangedEvent if (OnHealthValueChangedAction != null) { this.OnHealthValueChangedEvent += OnHealthValueChangedAction; } this.CurrentHealth = new FloatVariable(this.HealthSystemDefinition.StartHealth, this.OnHealthValueChanged); }