示例#1
0
    private CursorType CheckWhatCursorShouldBe()
    {
        var cursorType = CursorType.Default;

        Unit unit = null;
        var  go   = Common.GetObjectUnderMouse(true);

        if (go)
        {
            unit = go.GetComponent <Unit>();
        }

        // From input control tool
        if (inputControlTool.IsInSkillPhase())
        {
            if (inputControlTool.GetCurrentCommand().IsAttack())
            {
                if (unit && unit.team.Equals(selectRectangle.team))
                {
                    cursorType = CursorType.AttackHighlight;
                }
                else
                {
                    cursorType = CursorType.Attack;
                }
            }
            else if (inputControlTool.GetCurrentCommand().IsSkill())
            {
                cursorType = CursorType.Magic;
            }
        }

        // If mouse is over enemy unit show attack icon
        else if (selectRectangle.GetSelectedUnits().Count > 0)
        {
            if (unit && !unit.team.Equals(selectRectangle.team))
            {
                cursorType = CursorType.Attack;
            }
        }

        // if pressing mouse, show highlight
        if (inputControlTool.IsInSkillPhase() && Input.GetKey(KeyCode.Mouse0) ||
            !inputControlTool.IsInSkillPhase() && Input.GetKey(KeyCode.Mouse1))
        {
            timeDisabled = 0.05f;
            if (cursorType.Equals(CursorType.Attack))
            {
                cursorType = CursorType.AttackHighlight;
            }
            if (cursorType.Equals(CursorType.Magic))
            {
                cursorType = CursorType.MagicHighlight;
            }
        }

        return(cursorType);
    }
示例#2
0
    void Update()
    {
        var selectedUnits = selectRectangle.GetSelectedUnits();

        if (selectedUnits.Count > 0)
        {
            // Checks if skill or special keys are pressed
            if (!skillPhase)
            {
                PerformCommand(GetCurrentCommandAccordingToInput());
            }

            if (selectRectangle.excludedScreenAreas.Contains(Input.mousePosition))
            {
                return;
            }

            // Perform actions
            if (skillPhase && Input.GetMouseButtonDown(MouseButton.Left.GetHashCode()))
            {
                SetSelectionEnabled(true);
                skillPhase = false;

                var unitClickedOn = Common.GetObjectUnderMouse().GetComponent <Unit>();
                var topUnit       = selectedUnits[0];
                var commandHash   = currentCommand.type.GetHashCode();

                // Skill on unit
                if (commandHash.IsSkill() && topUnit.skills[commandHash % 4].main.path.Equals(Path.OnUnit))
                {
                    if (unitClickedOn)
                    {
                        selectedUnits.PerformCommand(new Command(currentCommand.type, unitClickedOn.transform.position, unitClickedOn, true), true);
                        moveCross.ShowAt(unitClickedOn.transform.position, true);
                    }
                    else
                    {
                        Debug.Log("This skill must target unit");
                        // play sound or do smth..
                    }
                }
                else
                {
                    // Attack on unit
                    if (unitClickedOn && currentCommand.type.Equals(CommandType.Attack))
                    {
                        selectedUnits.PerformCommand(new Command(currentCommand.type, unitClickedOn.transform.position, unitClickedOn, true), true);
                        moveCross.ShowAt(unitClickedOn.transform.position, true);
                    }
                    // Skill on ground (maybe unit, but not strict), or move
                    else
                    {
                        var commandPos = (unitClickedOn) ? unitClickedOn.pos : Common.GetWorldMousePoint(groundLayer);
                        moveCross.ShowAt(commandPos, !currentCommand.type.Equals(CommandType.Move));
                        currentCommand.pos = commandPos;
                        selectedUnits.PerformCommand(currentCommand, true);
                    }
                }

                // Disable all range projectors
                selectRectangle.GetSelectedUnits().ForEach((u) => u.GetComponent <RangeProjector>().Disable());
            }
            else if (skillPhase && Input.GetMouseButtonDown(MouseButton.Right.GetHashCode()))
            {
                SetSelectionEnabled(true);
                currentCommand = new Command(CommandType.None);
                skillPhase     = false;

                // Disable all range projectors
                selectRectangle.GetSelectedUnits().ForEach((u) => u.GetComponent <RangeProjector>().Disable());
            }
            else if (!skillPhase && Input.GetMouseButtonDown(MouseButton.Right.GetHashCode()))
            {
                // Right click on enemy unit
                var obj = Common.GetObjectUnderMouse();
                if (obj != null)
                {
                    var unitClickedOn = obj.GetComponent <Unit>();
                    if (unitClickedOn != null && !unitClickedOn.team.Equals(selectRectangle.team))
                    {
                        selectedUnits.PerformCommand(new Command(CommandType.Attack, unitClickedOn.transform.position, unitClickedOn, true), true);
                        moveCross.ShowAt(unitClickedOn.transform.position, true);
                    }
                    // Right click on ground or anywhere else
                    else
                    {
                        var mousePos = Common.GetWorldMousePoint(groundLayer);
                        moveCross.ShowAt(mousePos);
                        selectedUnits.PerformCommand(new Command(CommandType.Move, mousePos), true);
                    }
                }
            }
        }
        // Selected unit count less than one
        else
        {
            SetSelectionEnabled(true);
            currentCommand = new Command(CommandType.None);
        }
    }