/// <summary> /// Invoke the true or false event stack based on a comparison of your targetVariable and a fixed number /// The comparison only runs when the Raise() is called, it's not monitored in Update or etc. /// </summary> public override void Raise() { if (targetVariable == null) { //Debug.Log("No number variable assigned in a fixed number to numberVariable comparison! " + this.gameObject.name); return; } if (targetVariable is FloatVariable) { FloatVariable f = (FloatVariable)targetVariable; if (f.value < fixedNumber) { IfVariableIsLower.Invoke(); } else { IfVariableIsHigher.Invoke(); } } if (targetVariable is IntVariable) { IntVariable i = (IntVariable)targetVariable; int v = Mathf.RoundToInt(fixedNumber); if (i.value < v) { IfVariableIsLower.Invoke(); } else { IfVariableIsHigher.Invoke(); } } }
public void Add(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value += Mathf.RoundToInt(f.value); } if (v is IntVariable) { IntVariable i = (IntVariable)v; value += i.value; } }
public void Add(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value += f.value; } if (v is IntVariable) { IntVariable i = (IntVariable)v; value += i.value; } }
public void Divide(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value = Mathf.RoundToInt(value / f.value); } if (v is IntVariable) { IntVariable i = (IntVariable)v; value /= i.value; } }
public void Divide(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value /= f.value; } if (v is IntVariable) { IntVariable i = (IntVariable)v; value /= i.value; } }
public void Multiply(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value *= f.value; } if (v is IntVariable) { IntVariable i = (IntVariable)v; value *= i.value; } }
public void Minus(NumberVariable v) { if (v is FloatVariable) { FloatVariable f = (FloatVariable)v; value -= f.value; } if (v is IntVariable) { IntVariable i = (IntVariable)v; value -= i.value; } }
/// <summary> /// Raise true or false event stack based on the comparison of two number variables /// </summary> public override void Raise() { if (value1 == null || value2 == null) { //Debug.Log("Number variable comparison doesn't have variables assigned! " + this.gameObject); return; } float v1 = 0; float v2 = 0; if (value1 is FloatVariable) { FloatVariable f = (FloatVariable)value1; v1 = f.value; } if (value1 is IntVariable) { IntVariable i = (IntVariable)value1; v1 = i.value; } if (value2 is FloatVariable) { FloatVariable f = (FloatVariable)value2; v2 = f.value; } if (value2 is IntVariable) { IntVariable i = (IntVariable)value2; v2 = i.value; } if (v1 < v2) { IfValue1IsLower.Invoke(); } else { IfValue1IsHigher.Invoke(); } }
using UnityEngine; using UnityEngine.Events; namespace SO { public class NumberVariableToNumberVariable_Comparison : EventExecutionOnMB { public NumberVariable value1; public NumberVariable value2; public UnityEvent IfValue1IsLower; public UnityEvent IfValue1IsHigher; /// <summary> /// Raise true or false event stack based on the comparison of two number variables /// </summary> public override void Raise() { if(value1 == null || value2 == null) { Debug.Log("Number variable comparison doesn't have variables assigned! " + this.gameObject); return; } float v1 = 0; float v2 = 0; if(value1 is FloatVariable) { FloatVariable f = (FloatVariable)value1; v1 = f.value; } if(value1 is IntVariable) { IntVariable i = (IntVariable)value1; v1 = i.value; } if (value2 is FloatVariable) { FloatVariable f = (FloatVariable)value2; v2 = f.value; } if (value2 is IntVariable) { IntVariable i = (IntVariable)value2; v2 = i.value; } if(v1 < v2) { IfValue1IsLower.Invoke(); } else { IfValue1IsHigher.Invoke(); } } } }
public void Set(NumberVariable v) { if (v is FloatVariable) { { FloatVariable f = (FloatVariable)v; value = Mathf.RoundToInt(f.value); } } if (v is IntVariable) { { IntVariable i = (IntVariable)v; value = i.value; } } }
using UnityEngine; using UnityEngine.Events; namespace SO { public class NumberToNumberVariable_Comparison : EventExecutionOnMB { public float fixedNumber; public NumberVariable targetVariable; public UnityEvent IfVariableIsLower; public UnityEvent IfVariableIsHigher; /// <summary> /// Invoke the true or false event stack based on a comparison of your targetVariable and a fixed number /// The comparison only runs when the Raise() is called, it's not monitored in Update or etc. /// </summary> public override void Raise() { if(targetVariable == null) { Debug.Log("No number variable assigned in a fixed number to numberVariable comparison! " + this.gameObject.name); return; } if(targetVariable is FloatVariable) { FloatVariable f = (FloatVariable)targetVariable; if (f.value < fixedNumber) IfVariableIsLower.Invoke(); else IfVariableIsHigher.Invoke(); } if(targetVariable is IntVariable) { IntVariable i = (IntVariable)targetVariable; int v = Mathf.RoundToInt(fixedNumber); if (i.value < v) IfVariableIsLower.Invoke(); else IfVariableIsHigher.Invoke(); } } } }
public void Set(NumberVariable v) { if (v is FloatVariable) { { FloatVariable f = (FloatVariable)v; value = f.value; } } if (v is IntVariable) { { IntVariable i = (IntVariable)v; value = i.value; } } }