Exemple #1
0
    // ====================================================================================================================
    #region input handlers - click unit

    protected override void OnNaviUnitClick(GameObject go)
    {
        base.OnNaviUnitClick(go);

        Unit unit = go.GetComponent <Unit>();

        // jump camera to the unit that was clicked on
        camMover.Follow(go.transform);

        // -----------------------------------------------------------------------
        // using turns sample?
        if (useTurns)
        {
            // is active player's unit that was clicked on?
            if (unit.playerSide == (currPlayerTurn + 1))
            {
                selectedUnit = go.GetComponent <Unit>();

                // move selector to the clicked unit to indicate it's selection
                selectionMarker.Show(go.transform);

                // show the nodes that this unit can move to
                selectedUnit.node.ShowNeighbours(selectedUnit.currMoves, selectedUnit.tileLevel, true, true);

                // show how far this unit can attack at, if unit did not attack yet this turn
                if (!selectedUnit.didAttack && combatOn)
                {
                    attackRangeMarker.Show(selectedUnit.transform.position, selectedUnit.attackRange);
                }
            }

            // else, not active player's unit but his opponent's unit that was clicked on
            else if (selectedUnit != null && combatOn)
            {
                if (selectedUnit.Attack(unit))
                {
                    allowInput = false;
                    attackRangeMarker.HideAll();
                }
            }
        }

        // -----------------------------------------------------------------------
        // not using turns sample
        else
        {
            bool changeUnit = true;

            // first check if opposing unit was clicked on that can be attacked
            if (selectedUnit != null && combatOn)
            {
                if (selectedUnit.Attack(unit))
                {
                    changeUnit = false;
                    allowInput = false;

                    // if not using turns sample, then reset didAttack now so it can attack again if it wanted to
                    selectedUnit.didAttack = false;

                    attackRangeMarker.HideAll();
                }
            }

            if (changeUnit)
            {
                selectedUnit = unit;

                // move selector to the clicked unit to indicate it's selection
                selectionMarker.Show(go.transform);

                // show the nodes that this unit can move to
                selectedUnit.node.ShowNeighbours(selectedUnit.currMoves, selectedUnit.tileLevel, true, true);

                // show how far this unit can attack at, if unit did not attack yet this turn
                if (combatOn)
                {
                    attackRangeMarker.ShowOutline(selectedUnit.transform.position, selectedUnit.attackRange);
                }

                // show how far this unit can attack at, if unit did not attack yet this turn
                if (!selectedUnit.didAttack && combatOn)
                {
                    attackRangeMarker.Show(selectedUnit.transform.position, selectedUnit.attackRange);
                }
            }
        }
    }
Exemple #2
0
    protected override void OnNaviUnitClick(GameObject go)
    {
        base.OnNaviUnitClick(go);

        Unit unit = go.GetComponent <Unit>();

        camMover.Follow(go.transform);

        if (useTurns)
        {
            if (unit.playerSide == (currPlayerTurn + 1))             //判断为移动
            {
                selectedUnit = go.GetComponent <Unit>();
                selectionMarker.Show(go.transform);                                                           //选中

                selectedUnit.node.ShowNeighbours(selectedUnit.currMoves, selectedUnit.tileLevel, true, true); // 展开移动地图

                if (!selectedUnit.didAttack && combatOn)                                                      //攻击范围
                {
                    attackRangeMarker.Show(selectedUnit.transform.position, selectedUnit.attackRange);
                }
            }
            else if (selectedUnit != null && combatOn)           // 判断为攻击
            {
                if (selectedUnit.Attack(unit))
                {
                    allowInput = false;
                    attackRangeMarker.HideAll();
                }
            }
        }
        else
        {
            bool changeUnit = true;

            if (selectedUnit != null && combatOn)             //先检查攻击
            {
                if (selectedUnit.Attack(unit))
                {
                    changeUnit             = false;
                    allowInput             = false;
                    selectedUnit.didAttack = false;
                    attackRangeMarker.HideAll();
                }
            }

            if (changeUnit)
            {
                selectedUnit = unit;
                selectionMarker.Show(go.transform);
                selectedUnit.node.ShowNeighbours(selectedUnit.currMoves, selectedUnit.tileLevel, true, true);
                if (combatOn)
                {
                    attackRangeMarker.ShowOutline(selectedUnit.transform.position, selectedUnit.attackRange);
                }
                if (!selectedUnit.didAttack && combatOn)
                {
                    attackRangeMarker.Show(selectedUnit.transform.position, selectedUnit.attackRange);
                }
            }
        }
    }