Exemplo n.º 1
0
    /// <summary>
    /// Checks the objects under the mouse cursor, showing its info in the info panel
    /// Actually, this is the main function of this script: it analyzes the context and set the mouse state and
    /// cursor accordingly
    /// </summary>
    void MouseOver()
    {
        string infoPanelMsg = "";

        // Something is selected?
        if(selectedObject != null) {

            infoPanelMsg = selectedObject.gameObject.name + " " + GUIScript.CheckClickOnRects(new Vector2(mouseNow.x,mouseNow.y));
        }

        mouseNow = Input.mousePosition;

        // Moved the cursor?
        //if(mouseNow != mouseBefore) {

            RaycastHit hit;
            Transform whatIAmPointing = null;
            pointedObject = null;

            mouseBefore = mouseNow;

            // Converts the mouse position to world position
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Creates a raycast from the mouse position in the screen, ignoring the minimap (or not?)
            if(Physics.Raycast(ray.origin, ray.direction, out hit,
                    Mathf.Infinity, ~(1 << MainScript.minimapLayer | 1 << MainScript.minimapGroundLayer))) {

                whatIAmPointing = hit.transform;
                mouseHitPointNow = hit.point;
            }

            if(whatIAmPointing == null)
                return;
            else
                pointedObject = whatIAmPointing;

            // Check the visibility
            if(whatIAmPointing.gameObject.GetComponent<VisibilityControl>() != null) {

                if(!whatIAmPointing.gameObject.GetComponent<VisibilityControl>().IsVisible()) {
                    return;
                }
            }

            // 1 - check if we have something selected or not
            if(!selectedObject) {

                if(whatIAmPointing.gameObject.layer != MainScript.groundLayer)
                    infoPanelMsg = whatIAmPointing.name;

                // The cursor is the regular one
                cursorCurrent = cursorNormal;
                MouseState = eMouseStates.Hover;
                // And we show it
                bnShowMouseCursor = true;

                // Special case: hover over a resource site without an extractor
                if(whatIAmPointing.tag == "Resource") {

                    CResource resourceExtractor = whatIAmPointing.gameObject.GetComponent<CResource>();

                    if(resourceExtractor.CanWeBuildInThisResourceSite()) {

                        infoPanelMsg += " You can build a resource extractor here";
                        cursorCurrent = cursorBuild;
                    }
                }
                infoPanel.SetInfoLabel(infoPanelMsg);
                // And we're off!
                return;
            } // END IF - nothing selected

            // 2 - Ok, we have an unit selected.
            CBaseEntity selectedObjectEntity = selectedObject.gameObject.GetComponent<CBaseEntity>();

            // 2.1 - if it's movable (a monkey or a drone, for instance), them we use mostly the 'walk' cursor
            if(selectedObjectEntity.Movable) {

                // Are�we pointing at the ground? Walk!
                if(whatIAmPointing.gameObject.layer == MainScript.groundLayer) {

                    cursorCurrent = cursorWalk;
                    MouseState = eMouseStates.CanWalk;

                    // Check if the node under the cursor is walkable or not
                    if(AstarPath.active != null) {

                        Node node = AstarPath.active.GetNearest(hit.point);
                        bnNodeStatus = node.walkable;
                        if(!bnNodeStatus) {

                            cursorCurrent = cursorWalkNotOk;
                            MouseState = eMouseStates.CannotWalk;
                        }
                    }

                    // Ok, cursor set, get out
                    return;
                } // END IF - not pointing at the ground

                // are we pointing at an enemy?
                if(whatIAmPointing.gameObject.layer == MainScript.enemyLayer) {

                    // We have a monkey selected?
                    if(selectedObject.gameObject.tag == "Monkey") {

                        CMonkey selectedMonkey = selectedObject.gameObject.GetComponent<CMonkey>();

                        if(!selectedMonkey) {

                            // DEBUG
                            Debug.LogError("Could not find CMonkey component in " + selectedObject);
                        }

                        // Are we targeting a drone?
                        if(whatIAmPointing.gameObject.tag == "Drone") {

                            bool isThisDroneStunned = false;
                            // Is this drone stunned?
                            CDrone pointedDrone = whatIAmPointing.gameObject.GetComponent<CDrone>();
                            if(!pointedDrone) {

                                // DEBUG
                                Debug.LogError("Could not find CDrone component in " + whatIAmPointing);
                            }

                            isThisDroneStunned = pointedDrone.isStunned();

                            // Default behaviour
                            cursorCurrent = cursorWalkNotOk;
                            MouseState = eMouseStates.CannotWalk;

                            switch(selectedMonkey.monkeyClass) {

                                case CMonkey.eMonkeyType.Astronaut:
                                    {
                                        // The astronaut only attack working drones
                                        // From the GDD:
                                        // Astronaut vs visible saboteur drones: OK
                                        // Astronaut vs hunter drones: get caught
                                        // Astronaut vs patrol drones: not ok
                                        // TODO: put this rules here!
                                        if(!isThisDroneStunned && pointedDrone.droneType == CDrone.eDroneType.Saboteur) {

                                            cursorCurrent = cursorAttack;
                                            MouseState = eMouseStates.TargetingForBrawl;
                                        }
                                    }
                                    break;

                                case CMonkey.eMonkeyType.Cientist:
                                    break;

                                case CMonkey.eMonkeyType.Engineer:
                                    {
                                        // The engineer only attack (recycle) stunned drones
                                        if(isThisDroneStunned) {

                                            cursorCurrent = cursorRecycleEnable;
                                            MouseState = eMouseStates.TargetingForRecycle;
                                        }
                                        else {
                                            // Drone is not stunned anymore
                                            //cursorCurrent = cursorNormal;
                                            //MouseState = eMouseStates.Hover;
                                        }
                                    }
                                    break;

                                case CMonkey.eMonkeyType.Saboteur:
                                    {
                                        // Saboteur:
                                        // Can sabotage patrol drones and hunter drones, if not visible
                                        // The sabouter only attack (reprogram) stunned drones
                                        if(isThisDroneStunned) {

                                            cursorCurrent = cursorReprogramEnable;
                                            MouseState = eMouseStates.TargetingForReprogram;
                                        }
                                        else {

                                            // Drone not stunned. Well, we still can sabotage it
                                            cursorCurrent = cursorSabotageEnable;
                                            MouseState = eMouseStates.CanSabotageDrone;
                                        }
                                    }
                                    break;

                                default:
                                    // DEBUG
                                    Debug.LogError("I should not be here...");
                                    break;
                            }
                        } // END IF - Monkey selected - Targeting an enemy drone
                        else if(whatIAmPointing.gameObject.tag == "Building") {
                            // No, we are targeting an enemy building.
                            // Only saboteurs can do something here?
                            if(selectedMonkey.monkeyClass == CMonkey.eMonkeyType.Saboteur) {

                                // Get info about the building target
                                CBuilding targetBuilding = whatIAmPointing.GetComponent<CBuilding>();

                                if(!targetBuilding) {

                                    // DEBUG
                                    Debug.Log("Could not find CBuilding component in " + whatIAmPointing);
                                }

                                if(!targetBuilding.sabotado) {

                                    cursorCurrent = cursorSabotageEnable;
                                    MouseState = eMouseStates.CanSabotageBuilding;

                                }
                            }
                        } // END IF - Monkey selected - Targeting an enemy building
                    } // END IF - Monkey selected
                    else if(selectedObject.gameObject.tag == "Drone") {

                        // GDD:		* hunter vs saboteur: attack (identical to the astronaut's attack)
                        //				* saboteur vs patrol or hunter: sabotage
                        //				* saboteur vs saboteur: reprogram
                        //				saboteur vs building: sabotage

                        CDrone selectedDrone = selectedObject.gameObject.GetComponent<CDrone>();

                        if(!selectedDrone) {

                            // DEBUG
                            Debug.LogError("Could not find CDrone component in " + selectedObject.transform);
                        }

                        // Are we targeting another drone (an enemy one, that is)
                        if(whatIAmPointing.gameObject.tag == "Drone") {

                            bool isThePointedDroneStunned = false;
                            // Is this drone stunned?
                            CDrone pointedDrone = whatIAmPointing.gameObject.GetComponent<CDrone>();
                            if(!pointedDrone) {

                                // DEBUG
                                Debug.LogError("Could not find CDrone component in " + whatIAmPointing);
                            }

                            isThePointedDroneStunned = pointedDrone.isStunned();

                            switch(pointedDrone.droneType) {

                                case CDrone.eDroneType.Patrol:
                                    {
                                        // Saboteur x Patrol
                                        if(selectedDrone.droneType == CDrone.eDroneType.Saboteur && !isThePointedDroneStunned) {

                                            cursorCurrent = cursorSabotageEnable;
                                            MouseState = eMouseStates.CanSabotageDrone;
                                        }
                                    }
                                    break;

                                case CDrone.eDroneType.Saboteur:
                                    {
                                        if(selectedDrone.droneType == CDrone.eDroneType.Saboteur && isThePointedDroneStunned) {

                                            // Saboteur x Saboteur (stunned)
                                            cursorCurrent = cursorReprogramEnable;
                                            MouseState = eMouseStates.TargetingForReprogram;
                                        }
                                        else if(selectedDrone.droneType == CDrone.eDroneType.Hunter && !isThePointedDroneStunned) {

                                            // Hunter vs Saboteur
                                            cursorCurrent = cursorAttack;
                                            MouseState = eMouseStates.TargetingForBrawl;
                                        }
                                    }
                                    break;

                                case CDrone.eDroneType.Hunter:
                                    {
                                        // Saboteur x Hunter
                                        if(selectedDrone.droneType == CDrone.eDroneType.Saboteur && !isThePointedDroneStunned) {

                                            cursorCurrent = cursorSabotageEnable;
                                            MouseState = eMouseStates.CanSabotageDrone;
                                        }
                                    }
                                    break;

                                default:
                                    break;
                            }

                        } // END IF - Drone selected - targeting a drone
                        else if(whatIAmPointing.gameObject.tag == "Building") {

                            // Saboteur drones x building
                            if(selectedDrone.droneType == CDrone.eDroneType.Saboteur) {

                                CBuilding pointedBuilding = whatIAmPointing.gameObject.GetComponent<CBuilding>();

                                // FIXME: Slots don't have CBuilding, so the mouseOver crash here
                                if(!pointedBuilding)
                                    return;

                                // We cannot sabotage a already sabotaged building
                                if(pointedBuilding.sabotado)
                                    return;

                                cursorCurrent = cursorSabotageEnable;
                                MouseState = eMouseStates.CanSabotageBuilding;
                            }
                        } // END IF - Drone selected - targeting a building
                    } //	END IF - Drone selected

                    return;
                } // END IF - not pointing at an enemy

                // Not pointing at the ground and not pointing at an enemy.
                // Is a monkey selected?
                if(selectedObject.gameObject.tag == "Monkey") {

                    CMonkey selectedMonkey = selectedObject.gameObject.GetComponent<CMonkey>();

                    if(!selectedMonkey) {

                        // DEBUG
                        Debug.LogError("Cannot find CMonkey component on " + selectedObject);
                        return;
                    }

                    // are we pointing at one of ours buildings?
                    if(whatIAmPointing.tag == "Building" && whatIAmPointing.gameObject.layer == MainScript.alliedLayer)	{

                        CBuilding pointedBuilding = whatIAmPointing.gameObject.GetComponent<CBuilding>();

                        // FIXME: Slots don't have CBuilding, so the mouseOver crash here
                        if(!pointedBuilding)
                            return;

                        // Is this the Command Center?
                        if(pointedBuilding.buildingType == CBuilding.eBuildingType.CommandCenter &&
                                !pointedBuilding.TheresAMonkeyInside()) {

                            cursorCurrent = cursorGetInside;
                            MouseState = eMouseStates.MonkeyCanEnterBuilding;
                        }
                        else if(pointedBuilding.buildingType == CBuilding.eBuildingType.LaunchingPlatform) {

                            cursorCurrent = cursorGetInside;
                            MouseState = eMouseStates.MonkeyCanEnterBuilding;
                        }
                        else if(pointedBuilding.sabotado && selectedMonkey.monkeyClass == CMonkey.eMonkeyType.Engineer) {

                                cursorCurrent = cursorBuild;
                                MouseState = eMouseStates.EngineerFix;
                        }
                        else {

                            cursorCurrent = cursorWalkNotOk;
                            MouseState = eMouseStates.CannotWalk;
                        }

                        // FIXME: check the correct cursor. Not walk, perhaps?
                        //	cursorCurrent = cursorNormal;
                        //	MouseState = eMouseStates.Hover;

                    } // END IF - Monkey selected - pointing at a building
                    else if(whatIAmPointing.tag == "RocketPart" &&
                            selectedMonkey.monkeyClass == CMonkey.eMonkeyType.Cientist) {

                        CRocketPart cRocketPart = whatIAmPointing.GetComponent<CRocketPart>();

                        // Ok, but it's this part already being carried by someone in my team?
                        if(cRocketPart.isCaptured) {

                            // Set the cursor
                            cursorCurrent = cursorCaptureRay;
                            // Set the state
                            MouseState = eMouseStates.CanReleaseCaptured;
                            // Keeps the pointed object
                            //pointedObject = whatIAmPointing;
                        }
                        else if(cRocketPart.IsVisible() && !selectedMonkey.CheckIfHaveSomethingCaptured()){

                            // Set the cursor
                            cursorCurrent = cursorCaptureRay;
                            // Set the state
                            MouseState = eMouseStates.CanCapture;
                            // Keeps the pointed object
                            //pointedObject = whatIAmPointing;
                        }
                    }
                    else if(whatIAmPointing.gameObject.layer == MainScript.neutralLayer) {

                        // Over neutral we can walk
                        cursorCurrent = cursorWalk;
                        MouseState = eMouseStates.CanWalk;
                    }
                    else {

                        // well, then we can't walk
                        cursorCurrent = cursorWalkNotOk;
                        MouseState = eMouseStates.CannotWalk;
                    }
                } // END IF - Monkey selected - not pointing at the ground, not pointing at an enemy
                else { // not a monkey selected

                            // DEBUG
                            //Debug.Log(this.transform + " RP + Monkey Cientist");
                            cursorCurrent = cursorNormal;
                            MouseState = eMouseStates.Hover;
                }
            } // END IF - Movable selected
            else {

                // Object is not movable: building, resource, etc.
                cursorCurrent = cursorNormal;
                MouseState = eMouseStates.Hover;
            }
        //}
    }
Exemplo n.º 2
0
    /// <summary>
    /// Execute when the player presses the left mouse button
    /// Behaviours: select an unit, deselect-it if clicked in the terrain
    /// </summary>
    void CheckLeftMouseClick()
    {
        // Check if we're inside the game defined viewport
        if(mouseNow.y < gameBarTop || mouseNow.y > gameBarBottom ||  GUIScript.CheckClickOnRects(new Vector2(mouseNow.x,mouseNow.y)) )
            return;

        // Checks if we clicked in an unit
        Transform whatIClicked = GetWhatIClicked();

        // Possibilities:
        // 1-I don't have anything selected. In this case, select the object under the mouse cursor, if possible
        // 2-I already have select an object. In this case, the click will point where it should move
        if(whatIClicked != null) {

            // Get the basic info on the unit
            selectedBaseEntity = whatIClicked.gameObject.GetComponent<CBaseEntity>();

            if(selectedBaseEntity != null) {

                // Do not let we select enemy units
                if(selectedBaseEntity.Team == CBaseEntity.eObjTeam.Opponent) {

                    return;
                }

                if(selectedBaseEntity.Selectable) {

                    // Unit not selected?
                    if(!selectedBaseEntity.isSelected) {

                        // Unselect previous units
                        if(selectedObject != null) {
                            selectedObject.gameObject.GetComponent<CBaseEntity>().Deselect();
                            RemoveCursor();
                        }

                        // Select this unit
                        selectedObject = selectedBaseEntity.Select();

                        infoPanel.SetInfoLabel(selectedObject.gameObject.name);

                        if(selectedBaseEntity.Movable) {

                            // Change the mouse state
                            MouseState = eMouseStates.CanWalk;
                        }
                        else {

                            // FIXME: to avoid a previously selected drone to walk, even not being selected
                            MouseState = eMouseStates.Hover;
                        }
                    }
                }
            }
            else {

                // Unselect current object
                if(selectedObject != null) {

                    // Deselect the current selected object
                    selectedObject.gameObject.GetComponent<CBaseEntity>().Deselect();
                    selectedObject = null;
                    // Change the mouse state
                    MouseState = eMouseStates.Hover;
                    RemoveCursor();

                    // Reset the menu panel
                    mainScript.bottomMenu.PlayerInfoMenuEnable(null);
                }
            }
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Executed when a script wants to receive a position when a mouse button is clicked
    /// </summary>
    public void IWantToSelectAPosition()
    {
        MouseState = eMouseStates.SelectingPosition;
        bnPositionAlreadySelected = false;

        // Instantiate a cursor
        projectorSelectTargetPosition = Instantiate(cursorObject,
                transform.position, Quaternion.Euler(90.0f, 0.0f, 0.0f)) as Transform;
    }
Exemplo n.º 4
0
    // SelectObject
    public void SelectObject(Transform targetObject)
    {
        // Get the basic info on the unit
        selectedBaseEntity = targetObject.gameObject.GetComponent<CBaseEntity>();

        if(selectedBaseEntity != null) {

                // Do not let we select enemy units
                if(selectedBaseEntity.Team == CBaseEntity.eObjTeam.Opponent) {

                    return;
                }

                if(selectedBaseEntity.Selectable) {

                    // Unit not selected?
                    if(!selectedBaseEntity.isSelected) {

                        // Unselect previous units
                        if(selectedObject != null) {

                            selectedObject.gameObject.GetComponent<CBaseEntity>().Deselect();
                            RemoveCursor();
                        }

                        // Select this unit
                        selectedObject = selectedBaseEntity.Select();

                        infoPanel.SetInfoLabel(selectedObject.gameObject.name);

                        if(selectedBaseEntity.Movable) {

                            // Change the mouse state
                            MouseState = eMouseStates.CanWalk;
                        }
                }
            }

        }
    }
Exemplo n.º 5
0
    // Use this for initialization
    void Start()
    {
        // Cache the main script
        mainScript = GameObject.Find("/Codigo").GetComponent<MainScript>();

        if(!mainScript) {

            // DEBUG
            Debug.LogError("MainScript object not found. Check the code.");
        }

        mouseBefore = mouseNow = Input.mousePosition;
        MouseState = eMouseStates.Hover;

        // Adjust the gameBarTop to pixels
        gameBarBottom = Screen.height - gameBarBottom;

        // Hides the OS cursor
        Screen.showCursor = false;
        cursorCurrent = cursorNormal;
    }