public void Start() { dropdown = GetComponent <Dropdown>(); instantDropdown = GetComponent <CustomUnityDropdown>(); resetDropdown(); titleText.text = title; }
// Use this for initialization void Start() { Dropdown dropdown = GetComponent <Dropdown>(); if (dropdown) { foreach (Dropdown.OptionData data in dropdown.options) { for (int i = 10; i >= 0; --i) { string oldValue = "\\t" + i; string newValue = string.Empty; for (int j = 0; j < i; ++j) { newValue += "\t"; } data.text = data.text.Replace(oldValue, newValue); } } } CustomUnityDropdown instantDropdown = GetComponent <CustomUnityDropdown>(); if (instantDropdown) { foreach (CustomUnityDropdown.OptionData data in instantDropdown.options) { for (int i = 10; i >= 0; --i) { string oldValue = "\\t" + i; string newValue = string.Empty; for (int j = 0; j < i; ++j) { newValue += "\t"; } data.text = data.text.Replace(oldValue, newValue); } } } }
// Use this for initialization void Start() { Dropdown dropdown = GetComponent <Dropdown>(); if (dropdown) { foreach (Dropdown.OptionData data in dropdown.options) { stringsToLocalise.Add(new StringElement() { stringId = data.text, element = data }); } } CustomUnityDropdown instantDropdown = GetComponent <CustomUnityDropdown>(); if (instantDropdown) { foreach (CustomUnityDropdown.OptionData data in instantDropdown.options) { stringsToLocalise.Add(new StringElement() { stringId = data.text, element = data }); } } var text = GetComponent <Text>(); if (text) { stringsToLocalise.Add(new StringElement() { stringId = text.text, element = text }); } OnLocalise(); }
// Update is called once per frame public override void OnServiceUpdate() { bool menuBarObjectUnderMouse = false; if (Globals.applicationMode != Globals.ApplicationMode.Loading && inUIBar) { // Get a list of all the objects currently under the mouse to get past the blocker GameObject[] currentHoveringObjects = GetObjectsUnderMouse(); // Check if mouse is hovering over an associated object foreach (GameObject objectUnderPointer in currentHoveringObjects) { for (int i = 0; i < uiElements.Length; ++i) { if ((uiElements[i] == objectUnderPointer) || objectUnderPointer.transform.parent.gameObject == uiElements[i]) { currentElement = i; menuBarObjectUnderMouse = true; break; } } if (menuBarObjectUnderMouse) { break; } } // Exit if not in a dropdown associated with the collected gameobjects or not hovering over an associated object if (!menuBarObjectUnderMouse) { currentElement = -1; } else if (prevElement != currentElement) { Dropdown dropdown = null; CustomUnityDropdown instantDropdown = null; // Auto-switch dropdown on hover if (lastShownDropdown && lastShownDropdown.gameObject != uiElements[currentElement].gameObject) { Dropdown lastDropdown = lastShownDropdown.GetComponentInParent <Dropdown>(); CustomUnityDropdown lastInstantDropdown = lastShownDropdown.GetComponentInParent <CustomUnityDropdown>(); if (lastDropdown) { lastDropdown.Hide(); } if (lastInstantDropdown) { lastInstantDropdown.Hide(); } } EventSystem.current.SetSelectedGameObject(uiElements[currentElement].gameObject); dropdown = uiElements[currentElement].GetComponentInParent <Dropdown>(); instantDropdown = uiElements[currentElement].GetComponentInParent <CustomUnityDropdown>(); if (dropdown) { dropdown.Show(); lastShownDropdown = dropdown; } if (instantDropdown) { instantDropdown.Show(); lastShownDropdown = instantDropdown; } } } if (Input.GetMouseButtonDown(0) && !inUIBar) { GameObject[] currentHoveringObjects = GetObjectsUnderMouse(); GameObject foundObject = null; // Check if mouse is hovering over an associated object foreach (GameObject objectUnderPointer in currentHoveringObjects) { for (int i = 0; i < uiElements.Length; ++i) { if ((uiElements[i] == objectUnderPointer) || objectUnderPointer.transform.parent.gameObject == uiElements[i]) { currentElement = i; foundObject = uiElements[i]; break; } } if (foundObject) { break; } } if (foundObject) { inUIBar = true; // Set the last shown dropdown Dropdown dropdown = foundObject.GetComponentInParent <Dropdown>(); if (dropdown) { lastShownDropdown = dropdown; } CustomUnityDropdown instantDropdown = foundObject.GetComponentInParent <CustomUnityDropdown>(); if (instantDropdown) { lastShownDropdown = instantDropdown; } } mouseUpBlock = true; } // Properly deselect dropdown else if (Input.GetMouseButtonUp(0) /* && (EventSystem.current.currentSelectedGameObject || !menuBarObjectUnderMouse)*/) { if (mouseUpBlock) { mouseUpBlock = false; } else { EventSystem.current.SetSelectedGameObject(null); inUIBar = false; currentElement = -1; } } //Debug.Log(inUIBar); prevElement = currentElement; }