void OnSelectionChange(Selectable previous, Selectable current) { if (current != null && current.GetComponent <Pawn>() != null && current.GetComponent <Pawn>().owner == TurnManager.instance.turnPlayer) { List <Skill> tmpList = current.GetComponent <Pawn>().skillList; if (characterDisplay != null) { characterDisplay.PopulateUI(current.GetComponent <Pawn>().character); } foreach (CommandButton b in buttonList) { b.Clear(); } for (int i = 0; i < tmpList.Count; i++) { //Debug.Log("SelectionChange Ability UI"); if (tmpList.Count > buttonList.Length) { Debug.LogError("Skill List is longer than list of buttons"); break; } Debug.Log(buttonList[i] + "Skill " + tmpList[i].name); buttonList[i].Set(tmpList[i]); // buttonList[i].GetComponentInChildren<Text>().text = tmpList[i].abilityCommand.ToString(); } } }
void RemoveTriggerEntry(EventTrigger trigger, EventTrigger.Entry entryToRemove, UnityEngine.Events.UnityAction <BaseEventData> handlerToRemove) { foreach (var entry in trigger.triggers) { if (entry.eventID == entryToRemove.eventID) { entry.callback.RemoveListener(handlerToRemove); if (entry.callback.GetPersistentEventCount() == 0) { if (!entryRemoveList.Contains(entry)) { entryRemoveList.Add(entry); } } //break; // There could be more than one existing entry of the same type, so look at all of them } } EventTrigger evTrigger = selectable.GetComponent <EventTrigger>(); if (evTrigger != null) { foreach (var entry in entryRemoveList) { if (evTrigger.triggers.Contains(entry)) { evTrigger.triggers.Remove(entry); } } entryRemoveList.Clear(); } }
private void SelectUI(Selectable option) { if (option.GetComponent <Button>()) { option.GetComponent <Button>().onClick.Invoke(); } }
private void Update() { if (!playerInput.GetSelectionInput() && !playerInput.GetMovementInput()) { return; } int layer = ~(1 << LayerMask.NameToLayer("Range")); Ray ray = mainCamera.ScreenPointToRay(playerInput.GetInputScreenPosition()); RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, 1, layer); if (playerInput.GetSelectionInput()) { if (hit && hit.collider && hit.collider.GetComponent <Selectable>()) { SelectSelectable(hit.collider.GetComponent <Selectable>()); } }//left click else if (playerInput.GetMovementInput()) { if (currentSelected) { print("move"); //move if (currentSelected.GetComponent <SquadUnit>()) { Vector3 pos = new Vector3(ray.origin.x, ray.origin.y, 0); currentSelected.GetComponent <SquadUnit>().MoveSquad(pos); } return; } }//end right click }
void Start() { deselectButtons = FindObjectOfType <EventSystem>(); //deselectButtons.GetComponent<EventSystem>(); //se coge la referencia del interactuable en qüestion switch (myType) { case MENU_ITEM_TYPE.BUTTON: button1 = selectableElement1.GetComponent <Button>(); break; case MENU_ITEM_TYPE.TOGGLE: toggle = selectableElement1.GetComponent <Toggle>(); break; case MENU_ITEM_TYPE.SLIDER: slider = selectableElement1.GetComponent <Slider>(); break; case MENU_ITEM_TYPE.MY_SLIDER: button1 = selectableElement1.GetComponent <Button>(); button2 = selectableElement2.GetComponent <Button>(); break; case MENU_ITEM_TYPE.SHROOM_BUTTON: button1 = selectableElement1.GetComponent <Button>(); break; } }
public void ComputeHighlightChange(Selectable previous, Selectable current) { ClearSelections(); if (previous != null) { if (previous.GetComponent <PawnHighlightingManager> () != null) { previous.GetComponent <PawnHighlightingManager> ().UpdateNodes(); } } if (current != null) { if (current.GetComponent <PawnHighlightingManager> () != null && TurnManager.instance.turnPlayer.Owns(current.GetComponent <Pawn> ())) { current.GetComponent <PawnHighlightingManager> ().SetState(PawnHighlightStates.Selected); current.GetComponent <PawnHighlightingManager> ().UpdateNodes(); } if (current.GetComponent <NodeHighlightManager> () != null) { current.GetComponent <NodeHighlightManager> ().SetState(NodeHighlightStates.Selected); } } }
void OnEnable() { if (selectable == null) { selectable = GetComponentInParent <Selectable>(); } if (selectable != null) { EventTrigger evTrigger = selectable.GetComponent <EventTrigger>(); if (evTrigger == null) { evTrigger = selectable.gameObject.AddComponent <EventTrigger>(); } if (clickEv != null) { evTrigger.triggers.Remove(clickEv); } clickEv = new EventTrigger.Entry(); clickEv.eventID = EventTriggerType.PointerClick; clickEv.callback.AddListener(CancelSelect); evTrigger.triggers.Add(clickEv); } }
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; } }
void UpdateState(Selectable previous, Selectable current) { if (current == null || current.GetComponent <Pawn> () == null) { Hide(); return; } currentSkills = current.GetComponent <Pawn> ().skillList.ToArray(); if (currentSkills.Length > buttons.Length) { throw new UnityException("Too many skillz in this pawn, yo"); } else { foreach (CommandButton b in buttons) { b.Clear(); } for (int counter = 0; counter < currentSkills.Length; counter++) { buttons[counter].Set(currentSkills[counter]); } } Show(); }
void Update() { if (selectedObject) { selectedItemPanel.SetActive(true); Upgradable upgradeComponent = selectedObject.GetComponent <Upgradable> (); Item itemComponent = selectedObject.GetComponent <Item> (); if (upgradeComponent) { if (upgradeComponent.isUpgradable()) { upgradeCost.text = upgradeComponent.getUpgradeCost().ToString(); upgradeButton.gameObject.SetActive(true); } else { upgradeCost.text = "N/A"; upgradeButton.gameObject.SetActive(false); } sellAmount.text = upgradeComponent.getSellValue().ToString(); if (itemComponent) { selectedItemText.text = itemComponent.itemName + " (Level " + upgradeComponent.level + ")"; selectedItemImage.sprite = itemComponent.getImage(); } } } else { selectedItemPanel.SetActive(false); } moneyAmount.text = money.ToString(); }
public void Select(string objName) { Debug.Log(objName); GameObject obj; if ((obj = GameObject.Find(objName)) != null) { currentSelection = obj.GetComponent <Selectable>(); if (currentSelection == null) { Debug.Log(objName + " is not selectable"); } else { //move camera to position to view the object Camera.main.transform.position = currentSelection.viewPos; //direct camera to look at the object Camera.main.transform.LookAt(currentSelection.transform.position); //change the handlers for the play and stop commands speechInput.ChangeHandler("play", currentSelection.GetComponent <Playable>().Play); speechInput.ChangeHandler("stop", currentSelection.GetComponent <Playable>().Stop); Debug.Log("selected " + objName); } } else { Debug.Log("Object " + objName + " not found"); } }
void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { Selectable next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); Dropdown dropDown = next.GetComponent <Dropdown>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); } else if (dropDown != null) { dropDown.OnPointerClick(new PointerEventData(system)); } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } //Here is the navigating back part: else { next = Selectable.allSelectables[0]; system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } } }
private void Update() { if (myEventSystem.currentSelectedGameObject == null) { return; } currentObject = myEventSystem.currentSelectedGameObject.GetComponent <Selectable> (); if (InputManager.SelectButtonDown()) { if (currentObject.GetComponent <Button> () == null) { return; } Button button = currentObject.GetComponent <Button> (); ExecuteEvents.Execute(button.gameObject, new BaseEventData(myEventSystem), ExecuteEvents.submitHandler); } if (InputManager.UpButtonDown()) { if (currentObject.FindSelectableOnUp() == null) { return; } GameObject nextObj = currentObject.FindSelectableOnUp().gameObject; myEventSystem.SetSelectedGameObject(nextObj); Debug.Log("Navigate up"); } if (InputManager.DownButtonDown()) { if (currentObject.FindSelectableOnDown() == null) { return; } GameObject nextObj = currentObject.GetComponent <Selectable> ().FindSelectableOnDown().gameObject; myEventSystem.SetSelectedGameObject(nextObj); Debug.Log("Navigate down"); } if (InputManager.LeftButtonDown()) { if (currentObject.FindSelectableOnLeft() == null) { return; } GameObject nextObj = currentObject.FindSelectableOnLeft().gameObject; myEventSystem.SetSelectedGameObject(nextObj); Debug.Log("Navigate left"); } if (InputManager.RightButtonDown()) { if (currentObject.FindSelectableOnRight() == null) { return; } GameObject nextObj = currentObject.FindSelectableOnRight().gameObject; myEventSystem.SetSelectedGameObject(nextObj); Debug.Log("Navigate right"); } }
public void Stack(int col) { Selectable card = currentCard.transform.GetChild(0).GetComponent <Selectable>(); float yOffset = 0.5f; int lenColumn = handList[col].Count(); yOffset *= lenColumn; card.transform.position = new Vector3(hand[col].transform.position.x, hand[col].transform.position.y - yOffset, hand[col].transform.position.z); card.transform.parent = hand[col].transform; card.GetComponent <SpriteRenderer>().sortingOrder = lenColumn + 3; hand[col].transform.GetChild(0).transform.SetAsFirstSibling(); handList[col].Add(card.name); updateHandSums(card.GetComponent <Selectable>().value, col); score = 0; foreach (int sum in columnsSums) { score += sum; } Run21DealACard(); }
private void OverrideToMe(Vector2 direction) { if (direction == Vector2.up) { Selectable target = m_mySelectable.navigation.selectOnUp; if (target != null) { Navigation nav = target.navigation; nav.selectOnDown = m_mySelectable; target.navigation = nav; if (target.GetComponent <NavigationConstraint>()) { target.GetComponent <NavigationConstraint>().Setup(); } } } else if (direction == Vector2.down) { Selectable target = m_mySelectable.navigation.selectOnDown; if (target != null) { Navigation nav = target.navigation; nav.selectOnUp = m_mySelectable; target.navigation = nav; if (target.GetComponent <NavigationConstraint>()) { target.GetComponent <NavigationConstraint>().Setup(); } } } else if (direction == Vector2.left) { Selectable target = m_mySelectable.navigation.selectOnLeft; if (target != null) { Navigation nav = target.navigation; nav.selectOnRight = m_mySelectable; target.navigation = nav; if (target.GetComponent <NavigationConstraint>()) { target.GetComponent <NavigationConstraint>().Setup(); } } } else if (direction == Vector2.right) { Selectable target = m_mySelectable.navigation.selectOnRight; if (target != null) { Navigation nav = target.navigation; nav.selectOnRight = m_mySelectable; target.navigation = nav; if (target.GetComponent <NavigationConstraint>()) { target.GetComponent <NavigationConstraint>().Setup(); } } } }
public void OnDisable() { selectable.GetComponent <NavMeshAgent>().enabled = false; selectable.GetComponent <Rigidbody>().isKinematic = false; sm.Deselect(selectable); sm.selectableItems.Remove(selectable); Invoke("DieSound", Random.Range(0f, 0.25f)); }
public void OnSelectionChange(Selectable previous, Selectable current) { if (current != null && current.GetComponent <Pawn>() && current.GetComponent <Pawn>().owner == TurnManager.instance.turnPlayer && current.GetComponent <Pawn>().owner.isPlayer) { Debug.Log("Ability Menu Selected"); MenuManager.instance.OpenMenu(UIMenu); } else { //MenuManager.instance.CloseMenu(UIMenu); MenuManager.instance.CloseAllMenus(); } }
private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { if (system.currentSelectedGameObject != null && system.currentSelectedGameObject.GetComponent <Selectable>() != null) { Selectable next = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift) ? system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnUp() : system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); } system.SetSelectedGameObject(next.gameObject); } //Here is the navigating back part: else { next = Selectable.allSelectablesArray[0]; system.SetSelectedGameObject(next.gameObject); } } } }
// Update is called once per frame public override void OnServiceUpdate() { if (Input.GetKeyDown(KeyCode.Tab)) { Selectable next = defaultSelectable; if (EventSystem.current.currentSelectedGameObject) { if (Globals.secondaryInputActive) { next = EventSystem.current.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnUp(); } else { next = EventSystem.current.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); } } if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(EventSystem.current)); //if it's an input field, also set the text caret } EventSystem.current.SetSelectedGameObject(next.gameObject, new BaseEventData(EventSystem.current)); } } }
private void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { if (GestionnaireSysteme.currentSelectedGameObject != null && GestionnaireSysteme.currentSelectedGameObject.GetComponent <Selectable>() != null) { // DÉclaration de la variable local. Selectable prochain = GestionnaireSysteme.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); // Si le prochain n'est pas null, fait ceci. if (prochain != null) { InputField zonesaisis = prochain.GetComponent <InputField>(); if (zonesaisis != null) { zonesaisis.OnPointerClick(new PointerEventData(GestionnaireSysteme)); } GestionnaireSysteme.SetSelectedGameObject(prochain.gameObject); } else { prochain = Selectable.allSelectablesArray[0]; GestionnaireSysteme.SetSelectedGameObject(prochain.gameObject); } } } }
private void Next() { EventSystem eventSystem = EventSystem.current; Selectable currentSelectable = eventSystem.currentSelectedGameObject.GetComponent <Selectable>(); if (currentSelectable == null) { return; } Selectable nextSelectable = currentSelectable.FindSelectableOnRight(); if (nextSelectable == null) { nextSelectable = currentSelectable.FindSelectableOnDown(); if (nextSelectable == null) { return; } } InputField inputfield = nextSelectable.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(eventSystem)); } eventSystem.SetSelectedGameObject(nextSelectable.gameObject, new BaseEventData(eventSystem)); }
private void Previous() { EventSystem eventSystem = EventSystem.current; Selectable currentSelectable = eventSystem.currentSelectedGameObject.GetComponent <Selectable>(); if (currentSelectable == null) { return; } Selectable previousSelectable = currentSelectable.FindSelectableOnLeft(); if (previousSelectable == null) { previousSelectable = currentSelectable.FindSelectableOnUp(); if (previousSelectable == null) { return; } } InputField inputfield = previousSelectable.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(eventSystem)); } eventSystem.SetSelectedGameObject(previousSelectable.gameObject, new BaseEventData(eventSystem)); }
void Update() { //Controls enter button functionality if (Input.GetKeyDown("return")) { ReadInputs(); } //if tab is pressed, go to next input field if (Input.GetKeyDown(KeyCode.Tab)) { Selectable next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } } //Used for invalid text feedback displayTime -= Time.deltaTime; if (displayTime <= 0.0) { invalidGO.SetActive(false); blockedGO.SetActive(false); } }
void Update() { if ((Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return)) && _isSelect) { Selectable next = null; if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnUp(); if (next == null) { next = system.lastSelectedGameObject.GetComponent <Selectable>(); } } else { next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next == null) { next = system.firstSelectedGameObject.GetComponent <Selectable>(); } } if (next != null) { InputField inputfield = next.GetComponent <InputField>(); system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } else { Debug.LogError("找不到下一个控件"); } } }
public void SelectPrevious() { EventSystem system = EventSystem.current; Selectable prev = null; try { prev = Previous(system.currentSelectedGameObject.GetComponent <Selectable>()); } catch { prev = null; } if (prev == null) { prev = Default; } if (prev != null) { InputField inputfield = prev.GetComponent <InputField>(); if (inputfield != null && inputfield.interactable) { inputfield.OnPointerClick(new PointerEventData(system)); //if it's an input field, also set the text caret system.SetSelectedGameObject(prev.gameObject); inputfield.Select(); inputfield.ActivateInputField(); inputfield.MoveTextStart(false); inputfield.MoveTextEnd(true); } } }
private void OnSelectionChanged(Selectable slct) { var rect = slct.GetComponent <RectTransform>(); TargetPos = rect.position; TargetSize = rect.sizeDelta + Padding; }
void Update() { if (system.currentSelectedGameObject != null && system.currentSelectedGameObject.GetComponent <InputField>() != null && Input.GetKeyDown(KeyCode.Tab)) { Selectable next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } } if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter)) { if (login.activeSelf) { Login(); } else { Register(); } } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { Selectable next = null; if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnUp(); } else { next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); } if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); //if it's an input field, also set the text caret } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } //else Debug.Log("next nagivation element not found"); } }
// Update is called once per frame void Update() { system = EventSystem.current; InputField firstInputfield = GameObject.Find("InputField").GetComponent <InputField>(); //firstInputfield.OnPointerClick(new PointerEventData(system)); //system.currentSelectedGameObject; Debug.Log(system.currentSelectedGameObject.name); if (Input.GetKeyDown(KeyCode.Tab)) { Selectable next = system.currentSelectedGameObject.GetComponent <Selectable>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); } system.SetSelectedGameObject(next.gameObject); } ////Here is the navigating back part: //else //{ // next = Selectable.allSelectables[0]; // system.SetSelectedGameObject(next.gameObject); //} } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Tab)) { if (system.currentSelectedGameObject.GetComponent <InputField>() != null) { Selectable next = system.currentSelectedGameObject.GetComponent <InputField>().FindSelectableOnDown(); if (next != null) { InputField inputfield = next.GetComponent <InputField>(); if (inputfield != null) { inputfield.OnPointerClick(new PointerEventData(system)); //if it's an input field, also set the text caret } system.SetSelectedGameObject(next.gameObject, new BaseEventData(system)); } } else { system.SetSelectedGameObject(system.firstSelectedGameObject); } } }
private void selectGameObject(Selectable selectable) { if (selectable != null) { InputField inputfield = selectable.GetComponent<InputField>(); if (inputfield != null) inputfield.OnPointerClick(new PointerEventData(_system)); //if it's an input field, also set the text caret _system.SetSelectedGameObject(selectable.gameObject, new BaseEventData(_system)); } }
/** * Each frame, check for user input that would change our currently selected object * Update the map and cursor appearance based on selections */ void Update () { // If the user clicks on the map, try to 'select' what they have clicked on if (Input.GetMouseButtonDown(0)) { // First clear the last selected object if (selectedObject) { selectedObject.GetComponent<Selectable>().deselect(GetInstanceID()); selectedObject = null; } // Get the newly selected object and set it to 'selected' selectedObject = getSelectableAtPosition(Camera.main.ScreenToWorldPoint((Vector2) Input.mousePosition)); // Make sure to 'select' the new object once we have obtained it if (selectedObject) { selectedObject.GetComponent<Selectable>().select(GetInstanceID()); } } // If the user right-clicks when a Friendly Ant Unit is selected, move that unit along a path to the right clicked tile if (Input.GetMouseButtonDown(1) && selectedObject != null && selectedObject.isNeutralOrFriendly()) { Debug.Log("User right clicked to give command to unit: " + selectedObject); // Get the mouse position of where the user clicked Vector2 mousePos = Camera.main.ScreenToWorldPoint((Vector2) Input.mousePosition); // Get the Ant Unit scripts AntUnit antUnitScript = selectedObject.GetComponent<AntUnit>(); WarriorUnit warriorUnitScript = selectedObject.GetComponent<WarriorUnit>(); Selectable clickedOnSelectable = getSelectableAtPosition(mousePos); Attackable clickedOnAttackableScript = null; if (clickedOnSelectable && clickedOnSelectable.gameObject) { clickedOnAttackableScript = clickedOnSelectable.gameObject.GetComponent<Attackable>(); } if (warriorUnitScript != null && clickedOnAttackableScript != null && !clickedOnAttackableScript.isNeutralOrFriendly()) { // If the thing we have selected is a WarriorUnit, and we clicked on an enemey AntUnit, // set it as a target instead of a simple move Debug.Log("Going to attack!"); warriorUnitScript.setTarget(clickedOnAttackableScript); } else if (antUnitScript != null) { // Set the unit on a path to their target Debug.Log("Giving ant move to command"); StartCoroutine(antUnitScript.moveTo(mapManager.getTileAtPosition(mousePos), true)); } } // Depending on what the user has selected and what they are currently hovering over, change the mouse cursor if (selectedObject != null) { setCursor(selectedObject); } }
public MurpleUIElement(MurpleUIElement.Type elementType, Selectable selectable) { mElementType = elementType; mSelectable = selectable; mRectTransform = mSelectable.GetComponent<RectTransform>(); }
private GameObject CreateMultiselectionButton(Vector2 buttonCenter, Selectable selectable) { IGameEntity entity = selectable.GetComponent<IGameEntity>(); UnityAction selectUnique = new UnityAction(() => { selectable.SelectOnlyMe(); }); return CreateCustomButton(buttonCenter, multiselectionButtonSize, "MultiSelectionButton", "", buttonImage: GetImageForEntity (entity), actionMethod: selectUnique); }
/** * 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(); }