Пример #1
0
    private void UpdateUnitAngle()
    {
        int moveMask = 0;

        float angle = CAngleUtil.GetAngle(mMoveDirection);

        if ((angle >= 315 && angle < 360) || (angle >= 0 && angle <= 45))
        {
            moveMask = 1;
        }
        else if (angle >= 45 && angle <= 135)
        {
            moveMask = 2;
        }
        else if (angle >= 135 && angle <= 225)
        {
            moveMask = 3;
        }
        else if (angle >= 225 && angle <= 315)
        {
            moveMask = 4;
        }

        if (moveMask != mMoveMask)
        {
            mMoveMask = moveMask;

            switch (moveMask)
            {
            case 1:
                PlayAnimation("cavemanup");
                break;

            case 2:
                PlayAnimation("cavemanright");
                break;

            case 3:
                PlayAnimation("cavemandown");
                break;

            case 4:
                PlayAnimation("cavemanleft");
                break;
            }
        }
    }
Пример #2
0
    //----------------------------------------
    private void ProcessKey()
    {
        if (Input.GetMouseButtonUp(0))
        {
            if (DoAttack())
            {
                return;
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Vector3Int pos      = CGameManager.GetInstance().GetTilemap().WorldToCell(GetPos());
            TileBase   tileBase = CGameManager.GetInstance().GetTilemap().GetTile(pos);

            Debug.Log(string.Format("tile map pos {0}, {1}, {2} => {3}", pos.x, pos.y, pos.z, tileBase != null ? tileBase.name : "notile"));
        }

        if (Input.GetKeyDown(KeyCode.A))
        {
            mLeftOn = true;
        }
        if (Input.GetKeyUp(KeyCode.A))
        {
            mLeftOn = false;
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            mRightOn = true;
        }
        if (Input.GetKeyUp(KeyCode.D))
        {
            mRightOn = false;
        }

        if (Input.GetKeyDown(KeyCode.W))
        {
            mUpOn = true;
        }
        if (Input.GetKeyUp(KeyCode.W))
        {
            mUpOn = false;
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            mDownOn = true;
        }
        if (Input.GetKeyUp(KeyCode.S))
        {
            mDownOn = false;
        }

        bool moving = mLeftOn || mRightOn || mUpOn || mDownOn;

        if (!moving)
        {
            mMoveMask = 0;

            if (IsMoving())
            {
                SetStatus(UNIT_STATUS.US_IDLE);
            }

            return;
        }

        int lastMask = mMoveMask;

        mMoveMask = 0;

        mMoveDirection = Vector3.zero;

        if (mLeftOn)
        {
            mRightOn        = false;
            mMoveDirection += Vector3.left;

            mMoveMask |= 0x00000001;
        }
        else if (mRightOn)
        {
            mMoveDirection += Vector3.right;
            mMoveMask      |= 0x00000002;
        }

        if (mUpOn)
        {
            mDownOn         = false;
            mMoveDirection += Vector3.up;
            mMoveMask      |= 0x00000004;
        }
        else if (mDownOn)
        {
            mMoveDirection += Vector3.down;
            mMoveMask      |= 0x00000008;
        }

        mMoveDirection.Normalize();

        if (lastMask != mMoveMask)
        {
            float angle = CAngleUtil.GetAngle(mMoveDirection);

            if ((angle >= 315 && angle < 360) || (angle >= 0 && angle <= 45))
            {
                PlayAnimation("cavemanup");
            }
            else if (angle >= 45 && angle <= 135)
            {
                PlayAnimation("cavemanright");
            }
            else if (angle >= 135 && angle <= 225)
            {
                PlayAnimation("cavemandown");
            }
            else if (angle >= 225 && angle <= 315)
            {
                PlayAnimation("cavemanleft");
            }
        }

        if (CheckMoveable())
        {
            SetStatus(UNIT_STATUS.US_MOVE);
        }
        //Debug.Log(string.Format("angle : {0}", CAngleUtil.GetAngle(mMoveDirection)));
    }