Exemple #1
0
 public void LeaveManor()
 {
     if (mInnerState == EInnerState.MOVE_AROUND)
     {
         mInnerState = EInnerState.MOVE_TO_OUT_POINT;
     }
 }
Exemple #2
0
 public void Init()
 {
     mDeltaDesPos = Vector3.zero;
     mDesPos      = Vector3.zero;
     mLastPos     = transform.position;
     mInnerState  = EInnerState.FALL_OFF;
     mFallspeed   = 0;
 }
Exemple #3
0
    void Update()
    {
        switch (mInnerState)
        {
        case EInnerState.FALL_OFF: {
            if (transform.position.y > -0.1f)
            {
                Gravity();
            }
            else
            {
                mInnerState = EInnerState.MOVE_AROUND;
                mMove_timer = new Timer(2f, true);
            }
            break;
        }

        case EInnerState.MOVE_AROUND: {
            if (transform.position.y > -0.1f)         //地面高度约为-0.1f
            {
                mInnerState = EInnerState.FALL_OFF;
                return;
            }
            if (mMove_timer.Ready())
            {
                mDeltaDesPos = new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-1f, 1f)).normalized;
                mDesPos      = transform.position + mDeltaDesPos * mMoveLength;
                mMove_timer.Do();
                //mAni.CrossFade("run", 0.1f);
            }
            Move();
            break;
        }

        case EInnerState.MOVE_TO_OUT_POINT: {
            Vector3 dir = jumpStartObject.transform.position - transform.position;
            dir.y        = 0f;
            mDesPos      = transform.position + dir;
            mDeltaDesPos = dir.normalized;
            //mAni.CrossFade("run", 0.1f);
            TransMove();
            //Move();
            if ((transform.position - mDesPos).sqrMagnitude < 0.01f)
            {
                mInnerState     = EInnerState.JUMP_OUT;
                mCurrentUpSpeed = jumpStartSpeed;
                //AppFacade.GetInstance().SendNotification(NotiConst.CAT_LEAVE_ADD_GOLD);
            }
            break;
        }

        case EInnerState.JUMP_OUT: {
            Vector3 dir = jumpEndObject.transform.position - transform.position;
            dir.y        = 0f;
            mDesPos      = transform.position + dir;
            mDeltaDesPos = dir.normalized;
            //mAni.CrossFade("run", 0.1f);
            TransMove();
            //Move();
            if (mCurrentUpSpeed > -jumpStartSpeed)         //落地
            {
                transform.Translate(Vector3.up * mCurrentUpSpeed * Time.deltaTime);
                mCurrentUpSpeed -= g;
            }
            if ((transform.position - mDesPos).sqrMagnitude < 0.001f)
            {
                mRandomGoAwayIndex = Random.Range(0, goAwayObjects.Length);
                if (goAwayObjects[mRandomGoAwayIndex].name == "GoAway")         //除了第一个路口 都需要先走到中间然后拐一下
                {
                    mInnerState = EInnerState.GO_AWAY;
                }
                else
                {
                    mInnerState = EInnerState.GO_CENTER;
                }
            }
            break;
        }

        case EInnerState.GO_CENTER: {
            Vector3 dir = centerObject.transform.position - transform.position;
            dir.y        = 0f;
            mDesPos      = transform.position + dir;
            mDeltaDesPos = dir.normalized;
            //mAni.CrossFade("run", 0.1f);
            TransMove();
            //Move();
            if ((transform.position - mDesPos).sqrMagnitude < 0.001f)
            {
                mInnerState = EInnerState.GO_AWAY;
            }
            break;
        }

        case EInnerState.GO_AWAY: {
            Vector3 dir = goAwayObjects[mRandomGoAwayIndex].transform.position - transform.position;
            dir.y        = 0f;
            mDesPos      = transform.position + dir;
            mDeltaDesPos = dir.normalized;
            //mAni.CrossFade("run", 0.1f);
            TransMove();
            //Move();
            if ((transform.position - mDesPos).sqrMagnitude < 0.001f)
            {
                gameObject.SetActive(false);         //隐掉 回收
            }
            break;
        }
        }
    }