public void ConnectNearby() { connections.Clear(); SelectableUI[] uis = FindObjectsOfType <SelectableUI> (); Vector2[] directions = { Vector2.left, Vector2.right, Vector2.up, Vector2.down }; // find the nearest boxes to the left for (int i = 0; i < directions.Length; i++) { float closestDist = float.MaxValue; float perfectDist = float.MaxValue; float bestDot = 0; SelectableUI nearest = null; SelectableUI perfect = null; Vector2 nearestDir = Vector2.zero; Vector2 perfectDir = Vector2.zero; for (int j = 0; j < uis.Length; j++) { // work out direction Vector2 diff = uis [j].canvasCenter - canvasCenter; // are they similar float newDot = Vector2.Dot(diff.normalized, directions [i]); if (newDot > 0.8f) { Vector2 distVec = ComponentMultiply(diff, directions [i]); float newDist = distVec.sqrMagnitude; if (newDist < closestDist) { closestDist = newDist; bestDot = newDot; nearest = uis [j]; nearestDir = diff.normalized; } // not the closest... but it's a perfect fit! else if (bestDot < newDot && newDot > 0.99) { if (newDist < perfectDist) { perfectDist = newDist; perfect = uis [j]; perfectDir = diff.normalized; } } } } if (nearest != null) { AddConnection(nearest, nearestDir); } if (perfect != null) { AddConnection(perfect, perfectDir); } } }
private SelectableUI GetNextOption(SelectableUI.UIDirection directionToCheck) { SelectableUI optionToCheck = currentlySelectedUI.GetUIInDirection(directionToCheck); return(optionToCheck); //while (optionToCheck != null && !currentlyCheckedOptions.Contains(optionToCheck)) //{ //} }
void OnEnable() { text = transform.Find("TextMeshPro Text").GetComponent <TextMeshProUGUI>(); selectableUI = GetComponent <SelectableUI>(); if (!isEnabledAtStart) { Disable(); } }
/// <summary> /// Adds a connection without duplicates /// </summary> /// <param name="ui">component that wants to connect</param> /// <param name="dir">direction from us to component</param> void AddConnection(SelectableUI ui, Vector2 dir) { for (int i = 0; i < connections.Count; i++) { if (connections [i].target == ui) { return; } } connections.Add(new UIConnection(dir, ui)); }
private void SetNextSelectableUIOption(SelectableUI selectableUI) { if (selectableUI == null) { return; } if (this.currentlySelectedUI != null) { this.currentlySelectedUI.enabled = false; } this.currentlySelectedUI = selectableUI; this.currentlySelectedUI.enabled = true; }
/// <summary> /// updates the UI if there are any /// </summary> void Update() { if (selectablesUI.Count > 0) { // _____________ PANEL SELECTION TO UPDATE PROPERTIES __________________________________________________________ if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickDown) || Input.GetKeyDown(KeyCode.S)) { lineNumber++; int linecount = GameObjectHelper.FindNumberOfChildsWithTag(GameObjectHelper.FindGameObjectInChildWithTag(selectablesUI[0], "Values"), "UiLine"); if (lineNumber >= linecount) { lineNumber = 0; } foreach (GameObject SelectableUI in selectablesUI) { SelectableUI.GetComponent <Designer>().SetLineNumber(lineNumber); SelectableUI.GetComponent <Designer>().ModifyCanva(); } } if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickUp) || Input.GetKeyDown(KeyCode.Z)) { lineNumber--; int linecount = GameObjectHelper.FindNumberOfChildsWithTag(GameObjectHelper.FindGameObjectInChildWithTag(selectablesUI[0], "Values"), "UiLine"); if (lineNumber < 0) { var val = linecount - 1; lineNumber = (val >= 0) ? val : 0; } foreach (GameObject SelectableUI in selectablesUI) { SelectableUI.GetComponent <Designer>().SetLineNumber(lineNumber); SelectableUI.GetComponent <Designer>().ModifyCanva(); } } // upgrade/downgrade caracteristics of the object if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickLeft) || Input.GetKeyDown(KeyCode.Q)) { downgradeItem(); } if (OVRInput.GetDown(OVRInput.Button.PrimaryThumbstickRight) || Input.GetKeyDown(KeyCode.D)) { upgradeItem(); } } }
/// <summary> /// the item selected gets downgraded /// </summary> private void downgradeItem() { if (obj != null) { updater.SetObjUpdated(obj); List <float> param = GetCurrentParameters(); param[lineNumber] = param[lineNumber] - 1; updater.TryUpdating(param); foreach (GameObject SelectableUI in selectablesUI) { SelectableUI.GetComponent <Designer>().TryDesigning(param); } } }
public UIConnection(Vector2 dir, SelectableUI tgt) { direction = dir; target = tgt; }