/** * <summary> * On mouse over * </summary> * * <returns> * void * </returns> */ private void OnMouseOver() { if (MouseBehaviour.Mode == MouseMode.Build) { return; } // Prevent selectino through the bottom UI if (ComponentPanelsUI.OnUI) { return; } MouseBehaviour.Mode = MouseMode.OverUnit; // Left clicked if (Input.GetMouseButtonDown(0)) { UnitsManagerBehaviour.Select(this.gameObject); } }
/** * <summary> * Get selectable game objects based on screen to viewport * from a list * * @param List<GameObject> selectableGameObjects * @param Bounds cameraViewportBounds * * @return void * </summary> */ public void SelectGameObjects(List <GameObject> selectableGameObjects, Bounds cameraViewportBounds) { List <GameObject> unitsWithinArea = new List <GameObject>(); // Add selectable units to the list foreach (GameObject selectableGameObject in selectableGameObjects) { Vector3 gameObjectViewport = Camera.main.WorldToViewportPoint(selectableGameObject.transform.position); if (cameraViewportBounds.Contains(gameObjectViewport)) { UnitBehaviour unitBehaviour = selectableGameObject.GetComponent <UnitBehaviour>(); // If unit is selectable if (unitBehaviour is ISelectableUnit) { unitsWithinArea.Add(selectableGameObject); } } } // Select units UnitsManagerBehaviour.Select(unitsWithinArea); }
/** * <summary> * @overload * * Select a group of units * </summary> * * <returns> * void * </returns> */ public static void Select(List <GameObject> units) { // Select a single unit, if the list has only one unit if (units.Count == 1) { UnitsManagerBehaviour.Select(units[0]); return; } // Validate unit game objects foreach (GameObject unit in units) { if (unit.GetComponent <UnitBehaviour>() == null) { throw new Exception(unit.name + " " + "is not a unit type"); } } // Clear previous units UnitsManagerBehaviour.UnselectGameObjects(); // Unselect resource if (ResourcesManagerBehaviour.SelectedResource != null) { ResourcesManagerBehaviour.UnselectResource(); } // Add unit to the global list foreach (GameObject unit in units) { UnitBehaviour unitBehaviour = unit.GetComponent <UnitBehaviour>(); if (unitBehaviour is ISelectableUnit) { UnitsManagerBehaviour.SelectedUnits.Add(unit); } } // Set selection foreach (GameObject unit in UnitsManagerBehaviour.SelectedUnits) { UnitBehaviour unitBehaviour = unit.GetComponent <UnitBehaviour>(); unitBehaviour.SetSelect(true); } // Show multiple unit icons if (UnitsManagerBehaviour.SelectedUnits.Count > 1) { Self.infoComponentPanel.SetActive(true); // Show info component panel Self.infoComponentPanel .transform .Find("Single") .gameObject .SetActive(false); // Hide multiple Self.infoComponentPanel .transform .Find("Multiple") .gameObject .SetActive(true); // Remove previous multiple selection slots Self.RemoveMultipleSelectionSlots(); // Generate new multiple selection slots Self.GenerateMultipleSelectionUnitSlots(); // Hide action component panel Self.actionComponentPanel.SetActive(false); } }