private static void HandleSelectableClick(Selectable selectable) { var optionsSelector = selectable.GetComponent <OptionsSelectorElement>(); if (optionsSelector != null) { HandleOptionsSelectorClick(optionsSelector); return; } var twoButtonToggle = selectable.GetComponent <TwoButtonToggleElement>(); if (twoButtonToggle != null) { HandleTwoButtonToggleClick(twoButtonToggle); return; } var slider = selectable.GetComponentInChildren <Slider>(); if (slider != null) { HandleSliderClick(slider); return; } }
protected virtual void SetOnPointerClick(Selectable select) { var inputfield = select.GetComponentInChildren <InputField>(); if (inputfield) { inputfield.OnPointerClick(new PointerEventData(EventSystem.current)); } select.Select(); }
protected void HideChildText(Selectable component, bool isActive) { Text childText = component.GetComponentInChildren <Text>(); if (childText == null) { return; } childText.enabled = isActive; }
private IEnumerator CheckForBrochure() { yield return(null); if (done) { yield break; } //Get the SetupRoom to call the ModManagerHoldable SetupRoom setupRoom = (SetupRoom)SceneManager.Instance.CurrentRoom; ModManagerHoldable _brochure = setupRoom.ModManagerHoldable; //Grab ModButton and move it to give room for the new button Selectable ModButton = _brochure.OpenModManagerButton; ModButton.transform.Translate(0, 0, 0.01f); //Clone the ModButton Selectable ManualButton = Object.Instantiate(ModButton, ModButton.transform); //Grab the Brochure's selectable to add the new button to the list of its children selectables. Selectable Brochure = _brochure.GetComponent <Selectable>(); //Actually move the new button ManualButton.transform.Translate(-0.005f, -0.002f, 0.005f); //Quickly grab the texture for the middle panel so I can replace it. MeshRenderer replace = _brochure.GetComponent <Transform>().Find("PanelMiddleBack").GetComponent <MeshRenderer>(); replace.material.mainTexture = ManualCheckerLoader.Instance.brochureReplacement; Brochure.Children = Brochure.Children.Concat(new[] { ManualButton, null }).ToArray(); //The text autosizing makes the text smaller, which I do not want. So for now, setting this to false. ManualButton.GetComponentInChildren <TextMeshPro>().enableAutoSizing = false; ManualButton.GetComponentInChildren <TextMeshPro>().text = "Manage Manuals"; //Using this to deal with see through text in the Manual manager, maybe. fontmaterial = ManualButton.GetComponentInChildren <TextMeshPro>().fontMaterial; font = ManualButton.GetComponentInChildren <TextMeshPro>().font; /*Getting ready to call EnterModManagerStateFromSetup, however, I will be replacing modManagerScene with my own scene * As such, I'll basically be copying this method here, and replacing the last line.*/ //ManualButton.OnInteract += delegate () { button = true; Debug.LogFormat("[Manual] " + button.ToString()); SceneManager.Instance.EnterModManagerStateFromSetup(); return false; }; //ManualButton.OnInteract += delegate () { button = true; SceneManager.Instance.EnterModManagerStateFromSetup(); return false; }; ManualButton.OnInteract += delegate() { OnInteract(); return(false); }; done = true; }
void Update() { if (UI.UIHover) { return; } Selectable selected = Master.INSTANCE.Selected; // Resets the selection UI. foreach (Transform child in selection.transform) { Destroy(child.gameObject); } // If nothing is selected, then get turn off the selection pane and return. if (selected == null) { selection.GetComponent <Image>().enabled = false; return; } // Makes sure the selection pane is turned on if something is selected. selection.GetComponent <Image>().enabled = true; // This is the y coordinate of each component, it increases by 10 between each class // and 22 between each component in the class. int y = 0; // Loops through each class registered for the UI. foreach (Type clazz in classes) { y += 10; // Gets the instance of the current class in the selected object. var component = selected.GetComponent(clazz); if (component == null) { component = selected.GetComponentInChildren(clazz); } // If the selected object actually has that class. if (component != null) { // Gets each property with the show value in that class. PropertyInfo[] values = ShowValue.getValues(clazz); foreach (PropertyInfo value in values) { y += 22; drawValues(value, component, y); } } } }
protected void handleSell() { Selectable choice = EventSystem.current.currentSelectedGameObject.GetComponent <Selectable>(); string response = choice.GetComponentInChildren <Text>().text; if (response == "DONE") { isSelling = false; isBuying = false; end(); } else if (response == "<empty>") { FindObjectOfType <DialogueManager>().setMerchResponse("> Cargo pod empty"); } else if (response.Contains("hybrid grain")) { FindObjectOfType <DialogueManager>().setMerchResponse("> Sale of hybrid grain is prohibited per station quarantine"); } else { string[] cargo = GameControl.control.cargo; for (int i = 0; i < cargo.Length; i += 1) { if (cargo[i] == response) { GameControl.control.cargo[i] = "<empty>"; string cost = response.Substring(response.Length - 2); int intCost = Convert.ToInt32(cost); GameControl.control.credits += intCost; sold = true; break; } } if (sold) { cargo = GameControl.control.cargo; FindObjectOfType <DialogueManager>().setSell(cargo[0], cargo[1], cargo[2], cargo[3], "DONE"); FindObjectOfType <DialogueManager>().setMerchResponse("> I'll buy that"); sold = false; } } }
protected void handleBuy() { Selectable choice = EventSystem.current.currentSelectedGameObject.GetComponent <Selectable>(); string response = choice.GetComponentInChildren <Text>().text; if (response == "DONE") { isSelling = false; isBuying = false; end(); } else { string[] cargo = GameControl.control.cargo; for (int i = 0; i < cargo.Length; i += 1) { if (cargo[i] == "<empty>") { GameControl.control.cargo[i] = response; string cost = response.Substring(response.Length - 2); int intCost = Convert.ToInt32(cost); GameControl.control.credits += -intCost; bought = true; break; } } if (bought) { FindObjectOfType <DialogueManager>().setMerchResponse("> Excellent choice"); bought = false; } else { FindObjectOfType <DialogueManager>().setMerchResponse("> Cargo hold full"); } } }
public Element(string name, string group, string layer, DateTime startTime, DateTime endTime, int size, SpanAlignment guideSpan = SpanAlignment.None, bool calendarAligned = false, Color?setColor = null) { this.name = name; this.group = group; this.layer = layer; this.size = size; points = new bool[size, size]; this.guideSpan = guideSpan; this.calendarAligned = calendarAligned; instance.elementsPerLayer[layer].Add(this); RectTransform labelParentRTF = Instantiate(instance.elementLabelContainer, instance.labelLayersByName[layer]); //Debug.Log( "label parent rtf: " + labelParentRTF + "; label parent: " + labelParentRTF?.gameObject ); labelParentRTF.name = name; labelParent = labelParentRTF.gameObject; labelPrefabToUse = instance.labelPrefab; if (guideSpan == SpanAlignment.Months) { labelPrefabToUse = instance.monthLabelPrefab; } if (guideSpan == SpanAlignment.Years) { labelPrefabToUse = instance.yearLabelPrefab; } if (guideSpan == SpanAlignment.Decades) { labelPrefabToUse = instance.decadeLabelPrefab; } if (guideSpan == SpanAlignment.None) { this.color = setColor ?? MaxDifferentColor(instance.elementsPerLayer[layer].Select(e => e.color), 10); listing = Instantiate(instance.elementListingPrefab, instance.elementList); listingText = listing.GetComponentInChildren <Text>(); listingText.text = name; listingText.color = color; instance.elementsByListing[listing] = this; GroupElementListing gel = listing.GetComponentInChildren <GroupElementListing>(); gel.element = this; gel.layer = layer; if (!instance.groups.Contains(group) && group != "--") { instance.groups.Add(group); var groupListing = Instantiate(instance.groupListingPrefab, instance.groupList); groupListing.GetComponentInChildren <Text>().text = group; gel = groupListing.GetComponentInChildren <GroupElementListing>(); gel.group = group; gel.layer = layer; instance.groupListings.Add(gel); } label = Instantiate(labelPrefabToUse, labelParent.transform as RectTransform); Text labelText = label.GetComponentInChildren <Text>(); labelText.text = name; labelText.color = color.ShiftLuma(0.25f); Color backingColor = color * 0.4f; backingColor.a = 0.4f; label.GetComponentInChildren <Image>().color = backingColor; labels.Add(label); blocks.Add(new TimeBlock(startTime, endTime)); } }
// Update is called once per frame void Update() { if (SelectionMode) { if (Input.GetMouseButtonDown(0)) { Ray ray = Game.GetCurrentCamera().ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider != null && EventSystem.current != null && !EventSystem.current.IsPointerOverGameObject()) { var gameObject = hit.collider.gameObject; var selectable = gameObject.GetComponent <Selectable>(); if (selectable != null) { if (selectable.Equals(Selected)) { Selected.IsSelected = false; Selected.OnDeselected(); Selected = null; } else { if (Selected != null) { Selected.IsSelected = false; Selected.OnDeselected(); } selectable.OnSelected(); Selected = selectable; selectable.IsSelected = true; } } } } } else if (Input.GetMouseButtonDown(1)) { Ray ray = Game.GetCurrentCamera().ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider != null && EventSystem.current != null && !EventSystem.current.IsPointerOverGameObject()) { var gameObject = hit.collider.gameObject; var selectable = gameObject.GetComponent <Selectable>(); if (selectable != null && selectable.gameObject.GetComponentInChildren <Resource>() == null && Selected.GetComponentInChildren <Resource>() != null) { var resource = Selected.gameObject.GetComponentInChildren <Resource>(); resource.transform.SetParent(selectable.gameObject.transform); resource.gameObject.transform.position = selectable.gameObject.transform.position; resource.gameObject.transform.Translate(0, 1, 0); Selected.OnDeselected(); Selected = null; } } } } if (Input.GetKeyDown(KeyCode.G) && Selected != null) { Player.transform.position = Selected.transform.position; Player.transform.Translate(0, 1.5f, 0); } } }
// Selects the given object, adding a visual marker public void Select(Selectable selectable) { DeselectCurrent(); CurrentSelection = selectable; CurrentMarker = (GameObject)Instantiate(selectionMarker, CurrentSelection.gameObject.transform.position, Quaternion.identity); CurrentMarker.transform.parent = CurrentSelection.gameObject.transform; CurrentSelection.Selected(); CurrentSelectionVision = CurrentSelection.GetComponentInChildren<Vision>(); if(CurrentSelectionIsMyControllable()) { CurrentControlMenu = ((Controllable)CurrentSelection).ControlMenus[ControlStore.MENU_BASE]; } }
/** * Depending on the current situation with the selected object and where our mouse is hovering, * different cursors will need to be displayed */ private void setCursor(Selectable selectedObject) { // We only need to set custom cursors if a friendly ant unit is currently selected if (selectedObject != null && selectedObject.GetComponent<AntUnit>() != null && selectedObject.isNeutralOrFriendly()) { Selectable hoveredObject = getSelectableAtPosition((Vector2) Camera.main.ScreenToWorldPoint(Input.mousePosition)); if (hoveredObject != null) { // If a Tile is the topMostSelectable then we should display a 'move' type cursor if (hoveredObject.GetComponent<Tile>() != null) { if (hoveredObject.gameObject.layer != LayerMask.NameToLayer("Tile")) { Cursor.SetCursor(moveToDisabledCursor, Vector2.zero, CursorMode.Auto); } else { Cursor.SetCursor(moveToCursor, Vector2.zero, CursorMode.Auto); } return; } if (hoveredObject.GetComponent<Scentpath>() != null) { Cursor.SetCursor(moveToCursor, Vector2.zero, CursorMode.Auto); return; } // If Food is the topMostSelectable and we currently have a Gatherer selected, display a 'gather' type cursor if (selectedObject.GetComponent<GathererUnit>() != null && hoveredObject.GetComponent<Food>() != null) { Cursor.SetCursor(gatherCursor, Vector2.zero, CursorMode.Auto); return; } // If an AntUnit is the topMostSelectable and we currently have a Warrior selected, display an 'attack' type cursor if (selectedObject.GetComponent<WarriorUnit>() != null && hoveredObject.GetComponent<Attackable>() != null && !hoveredObject.isNeutralOrFriendly()) { Cursor.SetCursor(attackCursor, Vector2.zero, CursorMode.Auto); return; } // If a ruined anthill is the topMostSelectable and we currently have a Queen selected, display a 'build' type cursor if (selectedObject.GetComponent<QueenUnit>() != null && hoveredObject.GetComponent<DeadAnthill>() != null) { Cursor.SetCursor(buildCursor, Vector2.zero, CursorMode.Auto); return; } // If a friendly anthill is the topMostSelectable and we currently have a Gatherer with food selected, tell it to drop food off if (selectedObject.GetComponent<GathererUnit>() != null && selectedObject.GetComponentInChildren<Food>() != null && hoveredObject.GetComponent<Anthill>() != null && hoveredObject.isNeutralOrFriendly()) { Cursor.SetCursor(dropAtHomeCursor, Vector2.zero, CursorMode.Auto); return; } } } // Lastly, if no cursor has been set, use the default setDefaultCursor(); }