Exemple #1
0
 //a method that checks the selection status of an entity
 public static bool IsSelected(SelectionEntity selectionEntity, bool only, bool playerFaction)
 {
     return(selectionEntity != null && //valid selection entity
            selectionEntity.IsSelected && //must be selected
            (only == false || selectionEntity.IsSelectedOnly == true) //must it be only selected?
            //and finally check for the player faction
            && (playerFaction == false || selectionEntity.FactionEntity == null || selectionEntity.FactionEntity.FactionID == GameManager.PlayerFactionID));
 }
Exemple #2
0
        void Update()
        {
            //If the game is not running or the player is currently placing a building
            if (GameManager.GameState != GameState.running || gameMgr.PlacementMgr.IsBuilding())
            {
                return;           //don't proceed
            }
            UpdateCameraFollow(); //following entities with the camera

            //Checking if the selection key is held down or not!
            MultipleSelectionKeyDown = Input.GetKey(multipleSelectionKey);

            box.Update();                                 //update the selection box

            if (Input.GetKeyDown(idleUnitsSelection.key)) //if the player clicks the idle unit selection key
            {
                SelectIdleUnits();
            }

            //did the player just press one of these buttons?
            bool leftButtonDown  = Input.GetMouseButtonDown(0);
            bool rightButtonDown = Input.GetMouseButtonDown(1);

            //if the mouse pointer is over a UI element or the minimap, we will not detect entity selections. Also make sure that one of the mouse buttons are down
            if (EventSystem.current.IsPointerOverGameObject() ||
                gameMgr.CamMgr.MinimapCameraController.IsMouseOverMinimap(out RaycastHit hit) || (!leftButtonDown && !rightButtonDown))
            {
                return;
            }

            rayCheck = Camera.main.ScreenPointToRay(Input.mousePosition); //create a ray on the main camera from the mouse position
            if (Physics.Raycast(rayCheck, out rayHit, Mathf.Infinity, rayLayerMask.value))
            {
                SelectionEntity hitSelection = rayHit.transform.gameObject.GetComponent <SelectionEntity>();  //see if we have hit a selection entity
                bool            hitTerrain   = gameMgr.TerrainMgr.IsTerrainTile(rayHit.transform.gameObject); //did we hit the terrain?

                if (rightButtonDown)                                                                          //right mouse button is down, this is an action on the hit selection entity
                {
                    if (gameMgr.TaskMgr.UnitComponent.AwaitingTaskType != TaskTypes.none)
                    {                                                          //if we click with the right mouse button while having an awaiting component task..
                        gameMgr.TaskMgr.UnitComponent.ResetAwaitingTaskType(); //reset it.
                        return;
                    }

                    if (hitSelection)                                                                           //if a selection entity was hit
                    {
                        hitSelection.OnAction(TaskTypes.none);                                                  //trigger action
                    }
                    else if (hitTerrain)                                                                        //no selection entity was hit but the terrain was hit
                    {
                        OnSelectedUnitsAction(rayHit.point, TaskTypes.none);                                    //either move selected units or launch a terrain attack
                    }
                    Building selectedBuilding = (Building)selected.GetSingleEntity(EntityTypes.building, true); //get the single selected player faction building
                    if (selectedBuilding != null && (hitSelection != null || hitTerrain))                       //valid player faction building? update rally point if we hit something or we hit the terrain
                    {
                        selectedBuilding.UpdateRallyPoint(rayHit.point, hitSelection?.Source);
                    }
                }
                else if (leftButtonDown)      //if the left mouse button is down then this a selection action
                {
                    if (hitSelection == null) //no selection entity hit
                    {
                        TaskTypes currTask = gameMgr.TaskMgr.UnitComponent.AwaitingTaskType;

                        //if terrain was not hit or it was hit but there's no selected unit action
                        if (!hitTerrain ||
                            (currTask != TaskTypes.movement && currTask != TaskTypes.attack) ||
                            !OnSelectedUnitsAction(rayHit.point, currTask))
                        {
                            selected.RemoveAll();                              //player is just clicking to clear selection
                        }
                        gameMgr.TaskMgr.UnitComponent.ResetAwaitingTaskType(); //& reset awaiting task type
                        return;
                    }

                    if (gameMgr.TaskMgr.UnitComponent.AwaitingTaskType != TaskTypes.none)      //if there's a pending unit component task
                    {
                        hitSelection.OnAction(gameMgr.TaskMgr.UnitComponent.AwaitingTaskType); //trigger action
                        gameMgr.TaskMgr.UnitComponent.ResetAwaitingTaskType();
                    }
                    else //no pending unit component task -> select
                    {
                        selected.Add(hitSelection.Source, SelectionTypes.single); //select entity
                    }
                }
            }
        }
 /// <summary>
 /// Assigns a minimap icon to a SelectionEntity instance
 /// </summary>
 public void Assign(SelectionEntity selection)
 {
     selection.UpdateMinimapIcon(Get(selection.Source.transform, selection.GetMinimapIconSize())); //assign the minimap icon to the selection obj component
     selection.UpdateMinimapIconColor();                                                           //update the new minimap icon color
 }