Ejemplo n.º 1
0
    public override void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (directOrder)
            {
                foreach (Order order in Orders)
                {
                    if (order.BuildingGhost)
                    {
                        order.BuildingGhost.GetComponent <BuildingGhost>().NbWorkersAssigned--;
                    }
                }
                Orders.Clear();
            }

            if (target.GetComponent <Unit>())
            {
                SendMessage("StopAction");
                MoveScript.Move(target.transform.position);
            }
            else
            {
                Debug.Log("Order can't be interpreted");
            }
        }
        else
        {
            Orders.AddLast(new Order(OrderName.Mouse1, Vector3.zero, target));
        }
    }
Ejemplo n.º 2
0
    public void OnDeselectUnit(RTSGameObject gameObject)
    {
        //Debug.Log("OnDeselectUnit()");

        //Unit name
        unitName.GetComponent <Text>().text = "";

        //Unit pic
        unitPic.GetComponent <Image>().color = Color.white;

        //Unit action menu
        GameObject gridLayout    = unitActionMenu.transform.GetChild(0).gameObject;
        int        childrenCount = gridLayout.transform.childCount;

        for (int i = 0; i < childrenCount; ++i)
        {
            GameObject childGameObject = gridLayout.transform.GetChild(i).gameObject;
            Button     childButton     = childGameObject.GetComponent <Button>();
            Text       childText       = childGameObject.transform.GetChild(0).GetComponent <Text>();

            childButton.interactable = false;
            childText.text           = "";
            childButton.onClick.RemoveAllListeners();
        }
    }
Ejemplo n.º 3
0
    public void SendAttackOrder(RTSGameObject target, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (directOrder)
            {
                Orders.Clear();
            }
            if (target.GetComponent <Unit>())
            {
                if (target.faction == Faction.Neutral)
                {
                    Debug.Log("Can't attack this target");
                }

                else if (target.faction != this.faction)
                {
                    SendMessage("StopAction"); // Interrupt any other actions
                    AttackScript.Attack(target);
                }
            }
            else if (target.GetComponent <Collectable>())
            {
            }
            else if (target.GetComponent <CollectableObject>())
            {
            }
        }
        else
        {
            Orders.AddLast(new Order(OrderName.Attack, Vector3.zero, target));
        }
    }
Ejemplo n.º 4
0
    public override void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone)
    {
        if (!postpone)
        {
            if (target.GetComponent <Unit>())
            {
                if (target.faction == Faction.Neutral)
                {
                    Debug.Log("Can't attack this target");
                }

                else if (target.faction != this.faction)
                {
                    SendMessage("StopAction"); // Interrupt any other actions
                    AttackScript.Attack(target);
                }
            }
            else if (target.GetComponent <Collectable>()) // Goldmine, wood
            {
                MoveScript.Move(target.transform.position);
            }

            else if (target.GetComponent <CollectableObject>()) // Collectable object
            {
                // Take the Object
            }
        }
        else
        {
            Orders.AddLast(new Order(OrderName.Mouse1, Vector3.zero, target));
        }
    }
Ejemplo n.º 5
0
 public Order(OrderName _name, Vector3 _position, RTSGameObject _gameObject)
 {
     this._name          = _name;
     this._position      = _position;
     this._gameObject    = _gameObject;
     this._buildingGhost = null;
 }
Ejemplo n.º 6
0
 public void Aggro(RTSGameObject enemy)
 {
     if ((_isMoveAttack || GetComponent<AttackingUnit>().doingNothing()) && target == null && enemy != null)
     {
         _tmpEnemy = enemy;
         Invoke("NextAggro", 0.04f);
     }
 }
Ejemplo n.º 7
0
 public MouseClickEventArgs(ButtonType buttonType, ButtonEventType buttonEventType, Vector2 screenPosition, Vector3 worldPosition, RTSGameObject gameObject = null)
 {
     this.buttonType      = buttonType;
     this.buttonEventType = buttonEventType;
     this.screenPosition  = screenPosition;
     this.worldPosition   = worldPosition;
     this.gameObject      = gameObject;
 }
Ejemplo n.º 8
0
 public bool IsRTSEnemy(RTSGameObject rtsGameObject)
 {
     if (allEnemies.Contains(rtsGameObject))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 9
0
 public bool IsRTSAlly(RTSGameObject rtsGameObject)
 {
     if (allAllies.Contains(rtsGameObject))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 10
0
 public void StopAction()
 {
     //print("Action stopped");
     //_isAttacking = false;
     _isMoveAttack = false;
     target = null;
     _attackStance = false;
     onTheMove = false;
     _unitMoveScript.StopAction();
     _attackDestination = Vector3.zero;
 }
Ejemplo n.º 11
0
    public void DeselectObject(RTSGameObject gameObject)
    {
        //GameObject select data and method message
        gameObject.isSelected = false;
        gameObject.OnDeselected();

        //Remove the object from the list of selected objects
        selectedObjects.Remove(gameObject);

        CursorManager.main.ChangeCursor(CursorID.Normal);
    }
Ejemplo n.º 12
0
    public void Start()
    {
        seeker        = GetComponent <Seeker>();
        controller    = GetComponent <CharacterController>();
        rtsGameObject = GetComponent <RTSGameObject>();
        if (rtsGameObject == null)
        {
            Debug.LogWarning("No RTSGameObject was found.");
        }

        //timeToWait = Time.time;
    }
Ejemplo n.º 13
0
 public void NextAggro()
 {
     //print("Unit attack : " + _isMoveAttack + " " + GetComponent<RTSGameObject>().doingNothing());
     //if (!_targettedAttack || target == null)
     if ((_isMoveAttack || GetComponent<AttackingUnit>().doingNothing()) && target == null)
     {
         //print("Target it");
         //_targettedAttack = true;
         target = _tmpEnemy;
         onTheMove = false;
         //_isAttacking = true;
     }
 }
Ejemplo n.º 14
0
    public void SelectObject(RTSGameObject rtsGameObject)
    {
        if (!selectedObjects.Contains(rtsGameObject))          //If the selectedObject does NOT already contain the newly selected object

        {
            if (TeamManager.main.player1.IsRTSAlly(rtsGameObject))
            {
                if (rtsGameObject.unitType == UnitType.Unit)
                {
                    selectedObjects.Add(rtsGameObject);
                }
            }
        }
    }
Ejemplo n.º 15
0
    public void SelectObject(RTSGameObject gameObject)
    {
        if (!selectedObjects.Contains(gameObject))          //If the selectedObject does NOT already contain the newly selected object

        //Add the object to the list of selected objects
        {
            selectedObjects.Add(gameObject);

            //GameObject select data and method message
            gameObject.isSelected = true;
            gameObject.OnSelected();

            CursorManager.main.ChangeCursor(CursorID.Moveable);
        }
        else
        {
            //If the object is already selected and tried to be selected again
        }
    }
Ejemplo n.º 16
0
    public void Update()
    {
        firstSelectedGameObjects = SelectedManager.main.GetFirstSelectedObject();

        if (firstSelectedGameObjects == null && previousTemp != null)
        {
            OnDeselectUnit(previousTemp);
            previousTemp = null;
        }
        else if (previousTemp != firstSelectedGameObjects)
        {
            previousTemp = firstSelectedGameObjects;
            OnNewSelectedUnit(firstSelectedGameObjects);
        }
        else
        {
            //Debug.Log("Update");
        }
    }
Ejemplo n.º 17
0
 public override void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone)
 {
     print("got tf heer");
     if (!postpone)
     {
         if (directOrder)
         {
             Orders.Clear();
         }
         if (target.GetComponent <Collectable>()) // Goldmine, wood
         {
             print("got here");
             SendMessage("StopAction"); // Interrupt any other actions
             CollectScript.Collect(target.GetComponent <Collectable>());
         }
     }
     else
     {
         Orders.AddLast(new Order(OrderName.Mouse1, Vector3.zero, target));
     }
 }
Ejemplo n.º 18
0
    public void OnTriggerEnter(Collider other)
    {
        //Debug.Log("Hit");
        RTSGameObject rtsGameObject = other.gameObject.GetComponent <RTSGameObject>();

        if (rtsGameObject != null)
        {
            //if(rtsGameObject.unitType == UnitType.UnitEnemy) {
            //	rtsGameObject.SubtractHealth(damage);
            //	Destroy(this.gameObject);
            //	//Debug.Log("Dead");
            //}

            if (team != rtsGameObject.team)
            {
                rtsGameObject.SubtractHealth(damage);
                Destroy(this.gameObject);
                //Debug.Log("Destroy");
            }
        }
    }
Ejemplo n.º 19
0
    protected override void Awake()
    {
        base.Awake();

        ordersCanceled = 0;
        ordersCount    = 0;

        _rallyObject = null;

        _createTimer  = 0;
        _creatingUnit = false;

        orders = new OrderName[6];

        //addAction(OrderName.Create0);
        //addAction(OrderName.Create1);
        //addAction(OrderName.Create2);
        addAction(OrderName.Create0);
        addAction(OrderName.RallyPoint);

        //if (!GameMaster.Player1Hero)
    }
Ejemplo n.º 20
0
    public void OnNewSelectedUnit(RTSGameObject rtsGameObject)
    {
        //Debug.Log("OnNewSelectedUnit()");

        //Unit name
        unitName.GetComponent <Text>().text = rtsGameObject.name;

        //Unit pic
        unitPic.GetComponent <Image>().color = Color.blue;

        //Unit action menu
        GameObject gridLayout    = unitActionMenu.transform.GetChild(0).gameObject;
        int        childrenCount = gridLayout.transform.childCount;

        menuActions = rtsGameObject.menuActions;

        for (int i = 0; i < childrenCount; ++i)
        {
            GameObject childGameObject = gridLayout.transform.GetChild(i).gameObject;
            Button     childButton     = childGameObject.GetComponent <Button>();
            Text       childText       = childGameObject.transform.GetChild(0).GetComponent <Text>();

            if (menuActions.Count >= i + 1)             //Buttons to edit
            //Debug.Log("Button to edit: " + i);
            {
                childButton.interactable = menuActions[i].active;
                childText.text           = menuActions[i].name;
                childButton.onClick.AddListener(menuActions[i].Action);
                //childButton.onClick.AddListener(OnClickActionEvent);
            }
            else                        //Spill over buttons
            //Debug.Log("Spill over: " + childGameObject.name);
            {
                childButton.interactable = false;
                childText.text           = "";
                childButton.onClick.RemoveAllListeners();
            }
        }
    }
Ejemplo n.º 21
0
    public override void OnInspectorGUI()
    {
        RTSGameObject myTarget = (RTSGameObject)target;

        //base.OnInspectorGUI();

        GUILayout.Space(5);
        EditorGUILayout.LabelField("RTSGameObject", EditorStyles.boldLabel);
        GUILayout.Space(5);

        myTarget.teamController = (TeamController)EditorGUILayout.ObjectField("Team: ", myTarget.teamController, typeof(TeamController), true);
        myTarget.unitType       = (UnitType)EditorGUILayout.EnumPopup("RTS Type", myTarget.unitType);
        myTarget.team           = (Team)EditorGUILayout.EnumPopup("Team Color", myTarget.team);
        myTarget.maxHealth      = EditorGUILayout.IntField("Max Health", myTarget.maxHealth);
        myTarget.health         = EditorGUILayout.IntField("Health", myTarget.health);
        myTarget.attackRadius   = EditorGUILayout.FloatField("Attack Radius", myTarget.attackRadius);
        myTarget.nearRadius     = EditorGUILayout.FloatField("Near Radius", myTarget.nearRadius);
        myTarget.canAttack      = EditorGUILayout.Toggle("Can Attack", myTarget.canAttack);
        myTarget.turret         = (GameObject)EditorGUILayout.ObjectField("Prefab: Turret", myTarget.turret, typeof(GameObject), true);
        myTarget.bullet         = (GameObject)EditorGUILayout.ObjectField("Prefab: Bullet", myTarget.bullet, typeof(GameObject), true);
        myTarget.bulletSpawn    = (GameObject)EditorGUILayout.ObjectField("Prefab: Bullet Spawn", myTarget.bulletSpawn, typeof(GameObject), true);
        myTarget.attackTime     = EditorGUILayout.FloatField("Attack Time", myTarget.attackTime);
        GUILayout.Space(5);

        EditorGUILayout.LabelField("Is Selected: " + myTarget.isSelected);
        EditorGUILayout.LabelField("Is Attacking: " + myTarget.isAttacking);
        EditorGUILayout.LabelField("Target Lock: " + myTarget.targetLock);
        EditorGUILayout.LabelField("Attack Timer: " + myTarget.attackTimer);

        GUILayout.Space(20);

        if (GUI.changed)
        {
            EditorUtility.SetDirty(myTarget);
        }
    }
Ejemplo n.º 22
0
 public override void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 23
0
        public void CreateGridOld()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            grid = new Node[gridSizeX, gridSizeY];

            worldBottomLeft = this.transform.position - Vector3.right * gridWorldSize.x / 2 - Vector3.forward * gridWorldSize.y / 2;

            for (int x = 0; x < gridSizeX; x++)
            {
                for (int y = 0; y < gridSizeY; y++)
                {
                    //Node info
                    Vector3    worldPoint      = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
                    bool       isWalkable      = true;
                    int        movementPenalty = 0;
                    Color      color           = Color.green;
                    GameObject gameObject      = null;


                    //Checks if the node has collied with anything, using Physics.Raycast
                    {
                        //int rayStartHeight = 50;
                        //int rayLength = 100;

                        //Ray ray = new Ray(worldPoint + Vector3.up * rayStartHeight, Vector3.down);
                        //RaycastHit hit;

                        //if(!Physics.Raycast(ray, out hit, rayLength, unwalkableMask)) {
                        //walkable = true;
                        //} else {
                        //walkable = false;
                        //}
                    }

                    //Adds y axis to worldpoint
                    {
                        int rayStartHeight = 50;
                        int rayLength      = 100;

                        RaycastHit[] hits = Physics.RaycastAll(worldPoint + Vector3.up * rayStartHeight, Vector3.down, rayLength);
                        for (int i = 0; i < hits.Length; i++)
                        {
                            RaycastHit hit = hits[i];

                            //If you hit the terrain
                            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Terrain"))
                            {
                                worldPoint.y = hit.point.y;

                                //If the point's y is above the max height
                                if (worldPoint.y > maxHeight)
                                {
                                    isWalkable = false;
                                }
                            }

                            //Set the gameobject
                            if (hit.collider.gameObject.layer != LayerMask.NameToLayer("Terrain"))
                            {
                                gameObject = hit.collider.gameObject;
                            }

                            //If you hit a unwalkable object
                            if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Unwalkable"))
                            {
                                isWalkable = false;
                            }

                            //If you hit a RTSGameObject
                            RTSGameObject rtsGameObject = hit.collider.gameObject.GetComponent <RTSGameObject>();
                            if (rtsGameObject != null)
                            {
                                color = Color.yellow;
                            }
                        }
                    }

                    //Check terrain weights
                    {
                        Ray        ray = new Ray(worldPoint + Vector3.up * 50, Vector3.down);
                        RaycastHit hit;
                        int        rayDistance = 100;
                        if (Physics.Raycast(ray, out hit, rayDistance, walkableMask))
                        {
                            walkableAreaDictionary.TryGetValue(hit.collider.gameObject.layer, out movementPenalty);
                        }
                    }

                    //Unwalkable object border penalty
                    if (!isWalkable)
                    {
                        movementPenalty += objectBorderPenalty;
                    }

                    //Sets color
                    if (!isWalkable)
                    {
                        color = Color.red;
                    }

                    //Create a new node based on the info above and add it to the arrayList
                    //grid[x, y] = new Node(worldPoint, isWalkable, x, y, movementPenalty, color, gameObject);
                    grid[x, y] = new Node(worldPoint, new Vector2(x, y), isWalkable, movementPenalty, color, gameObject, NodeType.Nothing);
                }
            }
            BlurPenaltyMap(3);

            stopwatch.Stop();
            print("Timer: " + stopwatch.ElapsedMilliseconds + " ms");
        }
Ejemplo n.º 24
0
 public void DoPostponeAttackOrder(RTSGameObject target)
 {
     SendAttackOrder(target, false, false);
 }
Ejemplo n.º 25
0
 public void SendDirectAttackOrder(RTSGameObject target)
 {
     SendAttackOrder(target, true, false);
 }
Ejemplo n.º 26
0
 public void Attack(RTSGameObject target)
 {
     //_isAttacking = true;
     this.target = target;
 }
Ejemplo n.º 27
0
 public void SendDirectMouse1Order(RTSGameObject target)
 {
     SendMouse1Order(target, true, false);
 }
Ejemplo n.º 28
0
 public void DoPostponeMouse1Order(RTSGameObject target)
 {
     SendMouse1Order(target, false, false);
 }
Ejemplo n.º 29
0
 public abstract void SendMouse1Order(RTSGameObject target, bool directOrder, bool postpone);
Ejemplo n.º 30
0
    private void CheckMouseClickEvents()
    {
        screenPosision.Set((int)Input.mousePosition.x, (int)Input.mousePosition.y);
        gameObjectSelected = null;

        //------------------------------Raycast for all events------------------------------
        if (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                worldPosision.Set(hit.point.x, hit.point.y, hit.point.z);
                if (hit.collider.gameObject.GetComponent <RTSGameObject>() != null)                  //If the gameobject is a RTSGameObject
                {
                    gameObjectSelected = hit.collider.gameObject.GetComponent <RTSGameObject>();
                }
            }
        }


        //Left mouse button
        if (Input.GetMouseButton(0))
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (gameObjectSelected != null)
                {
                    MouseClickEvent(new MouseClickEventArgs(ButtonType.LeftButton, ButtonEventType.Down, screenPosision, worldPosision, gameObjectSelected));
                }
                else
                {
                    MouseClickEvent(new MouseClickEventArgs(ButtonType.LeftButton, ButtonEventType.Down, screenPosision, worldPosision));
                }
            }
            else
            {
                MouseClickEvent(new MouseClickEventArgs(ButtonType.LeftButton, ButtonEventType.Holding, screenPosision, worldPosision));
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            MouseClickEvent(new MouseClickEventArgs(ButtonType.LeftButton, ButtonEventType.Up, screenPosision, worldPosision));
        }



        //Middle mouse button
        if (Input.GetMouseButton(2))
        {
            if (Input.GetMouseButtonDown(2))
            {
                MouseClickEvent(new MouseClickEventArgs(ButtonType.MiddleButton, ButtonEventType.Down, screenPosision, worldPosision));
            }
            else
            {
                MouseClickEvent(new MouseClickEventArgs(ButtonType.MiddleButton, ButtonEventType.Holding, screenPosision, worldPosision));
            }
        }
        else if (Input.GetMouseButtonUp(2))
        {
            MouseClickEvent(new MouseClickEventArgs(ButtonType.MiddleButton, ButtonEventType.Up, screenPosision, worldPosision));
        }


        //Right mouse button
        if (Input.GetMouseButton(1))
        {
            if (Input.GetMouseButtonDown(1))
            {
                if (gameObjectSelected != null)
                {
                    MouseClickEvent(new MouseClickEventArgs(ButtonType.RightButton, ButtonEventType.Down, screenPosision, worldPosision, gameObjectSelected));
                }
                else
                {
                    MouseClickEvent(new MouseClickEventArgs(ButtonType.RightButton, ButtonEventType.Down, screenPosision, worldPosision));
                }
            }
            else
            {
                MouseClickEvent(new MouseClickEventArgs(ButtonType.RightButton, ButtonEventType.Holding, screenPosision, worldPosision));
            }
        }
        else if (Input.GetMouseButtonUp(1))
        {
            MouseClickEvent(new MouseClickEventArgs(ButtonType.RightButton, ButtonEventType.Up, screenPosision, worldPosision));
        }

        /*
         * if(Input.GetMouseButtonDown(1)) {
         *      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         *      RaycastHit hit;
         *      if(Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 8 | 1 << 9 | 1 << 12 | 1 << 13)) {
         *              //Right Clicked on unit or building
         *              if(MouseClick != null) {
         *                      //MouseClick(this, new RightButton_Handler((int)Input.mousePosition.x, (int)Input.mousePosition.y, 1, hit.collider.gameObject.GetComponent<RTSObject>()));
         *              }
         *      } else if(Physics.Raycast(ray, out hit, Mathf.Infinity, 1 << 11 | 1 << 18)) {
         *              //Right clicked on terrain
         *              if(MouseClick != null) {
         *                      MouseClick(this, new RightButton_Handler((int)Input.mousePosition.x, (int)Input.mousePosition.y, 1, hit.point));
         *              }
         *      }
         * }
         *
         * if(Input.GetMouseButtonDown(2)) {
         *      if(MouseClick != null) {
         *              MouseClick(this, new MiddleButton_Handler((int)Input.mousePosition.x, (int)Input.mousePosition.y, 2));
         *      }
         * }
         */


        if (checkForDoubleClick)
        {
            if ((DateTime.Now - timeAtFirstClick).Milliseconds >= doubleClickTime)
            {
                checkForDoubleClick = false;
            }
        }
    }