private void Start() { const int treeRecursionLimit = 0; this.treeScroll.onValueChanged.AddListener( (x) => { if (this.treesSyncRecursionGuard > treeRecursionLimit) { return; } ++this.treesSyncRecursionGuard; this.optionScroll.verticalNormalizedPosition = this.treeScroll.verticalNormalizedPosition; this.StartCoroutine(_SetVertScroll(this.optionScroll, this.treeScroll.verticalNormalizedPosition)); --this.treesSyncRecursionGuard; }); this.optionScroll.onValueChanged.AddListener( (x) => { if (this.treesSyncRecursionGuard > treeRecursionLimit) { return; } ++this.treesSyncRecursionGuard; this.treeScroll.verticalNormalizedPosition = this.optionScroll.verticalNormalizedPosition; this.StartCoroutine(_SetVertScroll(this.treeScroll, this.optionScroll.verticalNormalizedPosition)); --this.treesSyncRecursionGuard; }); this.tree.subscribers.Add(this); this.nodeWorld = this.tree.AddNode("Environment", null); this.nodeDecay = this.tree.AddNode("Decay", this.nodeWorld); this.nodeShapes = this.tree.AddNode("Shapes", null); GameObject goDecay = GameObject.Instantiate(this.prefabSpinnerReset); goDecay.transform.SetParent(this.optionScroll.content); this.decayEd = goDecay.GetComponent <ValueEditor_Base>(); this.decayEd.Init(this.mgr, null, this.mgr.evDecay); this.decayEd.OnUpdateValue(); this.environmentItems.Add(this.nodeDecay, this.decayEd); this.tree.LayoutTree(); }
/// <summary> /// For a specified actor, rebuild its tree of parameters to make sure /// they are up to date. /// </summary> /// <param name="actor">The actor to rebuilt the subtree for.</param> void RefreshActorParams(SceneActor actor) { PxPre.Tree.Node n; if (this.actorToNode.TryGetValue(actor, out n) == false) { return; } // We are going to re-add items from scratch n.DestroyChildren(); NodeWidgets nw; this.actorToParams.TryGetValue(actor, out nw); HashSet <string> foundParams = new HashSet <string>(nw.widgets.Keys); foreach (EditValue ev in actor.EnumerateRelevantParams()) { PxPre.Tree.Node np = this.tree.AddNode(ev.name, n); foundParams.Remove(ev.name); NodeWidgets.ParamNodePair pnp; if (nw.widgets.TryGetValue(ev.name, out pnp) == true) { pnp.node = np; np.MinHeight = pnp.param.rectTransform.sizeDelta.y; nw.widgets[ev.name] = pnp; } else { pnp = new NodeWidgets.ParamNodePair(); pnp.node = np; GameObject goPrefab = null; if (ev.name == "Rotation") { // Rotation is an edge case where the parameter gets its // own specific widget. goPrefab = GameObject.Instantiate(this.prefabWRotation); } else if (ev.val.ty == Val.Type.Float) { goPrefab = GameObject.Instantiate(this.prefabWSpinner); } else if (ev.val.ty == Val.Type.Int) { goPrefab = GameObject.Instantiate(this.prefabWSpinner); } else if (ev.val.ty == Val.Type.Bool) { goPrefab = GameObject.Instantiate(this.prefabWCheckbox); } else if (ev.val.ty == Val.Type.Enum) { goPrefab = GameObject.Instantiate(this.prefabWPulldown); } if (goPrefab != null) { ValueEditor_Base veb = goPrefab.GetComponent <ValueEditor_Base>(); veb.transform.SetParent(this.optionScroll.content, false); veb.Init(this.mgr, actor, ev); np.MinHeight = goPrefab.GetComponent <RectTransform>().sizeDelta.y; pnp.param = veb; nw.widgets.Add(ev.name, pnp); } } } // Remove anything we originally had that's no longer needed. foreach (string str in foundParams) { GameObject.Destroy(nw.widgets[str].param.gameObject); nw.widgets.Remove(str); } }
/// <summary> /// Utility function to implement checking if the Escape key is pressed during a drag operation, /// and canceling the drag operation and restoring the original value. /// </summary> /// <param name="draggedPtr"> /// The PointerEventData involved with the drag. This is required to cancel the drag operation /// through Unity's input system.</param> /// <param name="mgr">The application manager.</param> /// <param name="actor">The actor who's parameter was being modified.</param> /// <param name="ve">The widget who's drag action is being cancelled.</param> /// <returns></returns> public static IEnumerator EndDragOnEscape(UnityEngine.EventSystems.PointerEventData draggedPtr, Main mgr, SceneActor actor, ValueEditor_Base ve) { while (true) { if (Input.GetKeyDown(KeyCode.Escape) == true) { draggedPtr.pointerDrag = null; draggedPtr.dragging = false; ve.EV.val.SetValue(startingDragValue); mgr.NotifyActorModified(actor, ve.EV); ve.escapeCheck = null; yield break; } yield return(null); } }
/// <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); }