/// <summary> /// Callback for when the input is changed. /// </summary> public void OnTextChange() { Val vb = null; if (this.EV.val.ty == Val.Type.Float) { if (float.TryParse(this.input.text, out float f) == true) { vb = new ValFloat(f); } } else { if (int.TryParse(this.input.text, out int i) == true) { vb = new ValInt(i); } } if (vb != null) { this.EV.val.SetValue(this.EV.Clamp(vb)); this.Mgr.NotifyActorModified(this.actor, this.EV.name); } this.OnUpdateValue(); }
/// <summary> /// Callback for when the input value changes. /// </summary> public void OnTextChange() { if (this.recurseGuard > 0) { return; } Val vb = null; if (float.TryParse(this.input.text, out float f) == true) { vb = new ValFloat(f); } if (vb != null) { this.EV.val.SetValue(this.EV.Clamp(vb)); this.Mgr.NotifyActorModified(this.actor, this.EV.name); } this.OnUpdateValue(); }
/// <summary> /// A function to implement the spinner behaviour. /// </summary> /// <param name="mgr">The application manager.</param> /// <param name="actor">The actor that owns the parameter the widget is being setup for.</param> /// <param name="btn">The spinner button.</param> /// <param name="ev">The parameter value.</param> /// <param name="ve">The parameter's widget.</param> public static void SetupWidgetDrag(Main mgr, SceneActor actor, UnityEngine.UI.Button btn, EditValue ev, ValueEditor_Base ve) { UnityEngine.EventSystems.EventTrigger et = btn.gameObject.AddComponent <UnityEngine.EventSystems.EventTrigger>(); et.triggers = new List <UnityEngine.EventSystems.EventTrigger.Entry>(); UnityEngine.EventSystems.EventTrigger.Entry aBeginDrag = new UnityEngine.EventSystems.EventTrigger.Entry(); aBeginDrag.eventID = UnityEngine.EventSystems.EventTriggerType.BeginDrag; aBeginDrag.callback.AddListener( (x) => { UnityEngine.EventSystems.PointerEventData ped = x as UnityEngine.EventSystems.PointerEventData; if (ve.escapeCheck != null) { ve.StopCoroutine(ve.escapeCheck); } ve.escapeCheck = ve.StartCoroutine(EndDragOnEscape(ped, mgr, actor, ve)); startingDragValue = ev.val.Clone(); startDrag = ped.position; }); UnityEngine.EventSystems.EventTrigger.Entry aEndDrag = new UnityEngine.EventSystems.EventTrigger.Entry(); aEndDrag.eventID = UnityEngine.EventSystems.EventTriggerType.EndDrag; aEndDrag.callback.AddListener( (x) => { UnityEngine.EventSystems.PointerEventData ped = x as UnityEngine.EventSystems.PointerEventData; ValFloat diff = new ValFloat(-(startDrag.y - ped.position.y)); Val vb = ev.Offset(startingDragValue, diff); ev.val.SetValue(vb); mgr.NotifyActorModified(actor, ev.name); if (ve != null && ve.escapeCheck != null) { ve.StopCoroutine(ve.escapeCheck); ve.escapeCheck = null; } }); UnityEngine.EventSystems.EventTrigger.Entry aDrag = new UnityEngine.EventSystems.EventTrigger.Entry(); aDrag.eventID = UnityEngine.EventSystems.EventTriggerType.Drag; aDrag.callback.AddListener( (x) => { UnityEngine.EventSystems.PointerEventData ped = x as UnityEngine.EventSystems.PointerEventData; ValFloat diff = new ValFloat(-(startDrag.y - ped.position.y)); Val vb = ev.Offset(startingDragValue, diff); ev.val.SetValue(vb); mgr.NotifyActorModified(actor, ev.name); }); et.triggers.Add(aBeginDrag); et.triggers.Add(aEndDrag); et.triggers.Add(aDrag); }