示例#1
0
        void StateUpdate(float perHour)
        {
            switch (state)
            {
            case MSTATE.MOVE:
                Vector3 velocity = goalPoint - body.tform.position;
                velocity = velocity.normalized * speed;
                //velocity += BoidAdjust(velocity);
                body.tform.LookAt(body.tform.position + velocity);
                dayExercise += Time.deltaTime;
                print("move, motive is " + (goalMousePoint ? goalMousePoint.type : motive));
                if (Vector3.Distance(body.tform.position, goalPoint) < scale * 1.5f)
                {
                    velocity = Vector3.zero;
                    if (goalMousePoint)
                    {
                        switch (goalMousePoint.Availability(index))
                        {
                        case MPRESPONSE.AVAILABLE:
                            goalMousePoint.Engage(this);
                            break;

                        case MPRESPONSE.FULL:
                            foreach (int m in goalMousePoint.occupants)
                            {
                                IncreaseAffection(m, -0.2f);
                            }
                            ChangeState(MSTATE.WAIT);
                            break;

                        case MPRESPONSE.REJECTED:
                            MouseBody mb = goalMousePoint.GetComponent <MouseBody>();
                            if (mb)
                            {
                                int i = mb.index;
                                IncreaseAffection(i, -0.2f);
                            }
                            ChangeState(MSTATE.WAIT);
                            break;
                        }
                    }
                    else
                    {
                        print("no mouse point, change to wait");
                        ChangeState(MSTATE.WAIT);
                    }
                }
                body.rbody.velocity = velocity;
                break;

            case MSTATE.HELD:
                body.rbody.velocity = Vector3.zero;
                goalMousePoint      = null;
                break;

            case MSTATE.WAIT:
                break;

            case MSTATE.USEMP:
                if (!callbackMousePoint)
                {
                    ChangeState(MSTATE.WAIT);
                }
                else
                {
                    callbackMousePoint.Access(this);

                    if (motives[(int)callbackMousePoint.type].isFull())
                    {
                        DisengageMousePoint(false);
                        ChangeState(MSTATE.WAIT);
                    }
                }
                break;
            }
        }