コード例 #1
0
    public override void OnEnterState(IStateMachineOwner owner)
    {
        if (owner.GetType() != typeof(Customer))
        {
            Object ownerObject = owner as Object;
            Debug.LogError(string.Format("{0} is not customer, cannot use ExitInnState", ownerObject.name));
            throw new System.Exception("Wrong State Usage");
        }

        Customer customer = owner as Customer;

        Debug.Log(string.Format("{0} Enter PayBillState", customer.Data.CharacterName));
    }
コード例 #2
0
    public override void OnEnterState(IStateMachineOwner owner)
    {
        if (owner.GetType() != typeof(Customer))
        {
            Object ownerObject = owner as Object;
            Debug.LogError(string.Format("{0} is not customer, cannot use ExitInnState", ownerObject.name));
            throw new System.Exception("Wrong State Usage");
        }

        Customer customer = owner as Customer;

        Debug.Log(string.Format("{0} Enter ExitInnState", customer.Data.CharacterName));

        InnManager inn = Utils.GetGameManager().GetInnManager();

        customer.MoveToLocation(inn.GetExitLocation());
    }
コード例 #3
0
    public override void OnEnterState(IStateMachineOwner owner)
    {
        if (owner.GetType() != typeof(Customer))
        {
            Object ownerObject = owner as Object;
            Debug.LogError(string.Format("{0} is not customer, cannot use GotoSeatsState", ownerObject.name));
            throw new System.Exception("Wrong State Usage");
        }

        Customer customer = owner as Customer;

        Debug.Log(string.Format("{0} Enter GotoSeatsState", customer.Data.CharacterName));
        Utils.GetGameManager().GetUIManager().PopoutNewMessage(customer.gameObject, "Enter GotoSeatsState");

        if (customer.GetIsLeader())
        {
            InnManager innManager = Utils.GetGameManager().GetInnManager();

            Table table;
            if (innManager.QueryTable(customer, out table))
            {
                Vector3 des = table.PopOutSeats(customer);

                Blackboard leader_bb = customer.GetComponent <Blackboard>();
                leader_bb.AddOrModifyBBValue <Table>("Table", table);

                CustomerGroup group = CustomerGroup.GetGroupViaLeader(customer);

                foreach (Customer member in group._Members)
                {
                    Blackboard member_bb = member.GetComponent <Blackboard>();
                    member_bb.AddOrModifyBBValue <Table>("Table", table);
                }

                customer.MoveToLocation(des);
                _destinationSettled = true;
            }
        }
        else
        {
            //non-leader should follow leader decisions.
        }
    }
コード例 #4
0
    public static StateMachine CreateStateMachine(IStateMachineOwner smOwner)
    {
        StateMachine newSM = new StateMachine();

        newSM.Owner = smOwner;
        //TODO:
        //使用可在Editor内编辑的StateMachineInfo类来创建StateMachine,当前暂时使用hardcode

        if (smOwner.GetType() == typeof(Customer))
        {
            //创建EnterInnState - State itself
            EnterInnState enterInn = new EnterInnState();
            newSM.InitialState = enterInn;
            newSM.States.Add(enterInn);

            //创建GotoSeatsState
            GotoSeatsState gotoSeats = new GotoSeatsState();
            newSM.States.Add(gotoSeats);

            //创建PayBillState
            PayBillState payBill = new PayBillState();
            newSM.States.Add(payBill);

            //创建ExitInnState
            ExitInnState exitInn = new ExitInnState();
            newSM.States.Add(exitInn);



            //创建Transition
            List <TransitionBase> enterInnTransitions = new List <TransitionBase>();
            ExpressionTransition  enterInnSCTransit   = new ExpressionTransition();
            enterInnSCTransit.NextState = gotoSeats;
            TimerCondition _2sTimerCondition = new TimerCondition();
            _2sTimerCondition.SetTimeDuration(2);
            Expression enterInnSCTransitExp = new Expression();
            enterInnSCTransitExp.PushUnit(_2sTimerCondition);
            enterInnSCTransit.SetExpression(enterInnSCTransitExp);
            enterInnTransitions.Add(enterInnSCTransit);
            enterInn.Transitions = enterInnTransitions;

            List <TransitionBase> gotoSeatsTransitions = new List <TransitionBase>();
            ExpressionTransition  gotoSeatsSCTransit   = new ExpressionTransition();
            gotoSeatsSCTransit.NextState = payBill;
            IsReachDestination isReachDestination = new IsReachDestination();
            isReachDestination.SetDistanceThreshold(0.2f);
            Expression gotoSeatsSCTransitExp = new Expression();
            gotoSeatsSCTransitExp.PushUnit(isReachDestination);
            gotoSeatsSCTransit.SetExpression(gotoSeatsSCTransitExp);
            gotoSeatsTransitions.Add(gotoSeatsSCTransit);
            gotoSeats.Transitions = gotoSeatsTransitions;

            List <TransitionBase> payBillTransitions  = new List <TransitionBase>();
            ExpressionTransition  payBillSCTransit    = new ExpressionTransition();
            Expression            payBillSCTransitExp = new Expression();
            payBillSCTransitExp.PushUnit(new NoCondition());
            payBillSCTransit.NextState = exitInn;
            payBillSCTransit.SetExpression(payBillSCTransitExp);
            payBillTransitions.Add(payBillSCTransit);
            payBill.Transitions = payBillTransitions;

            List <TransitionBase> exitInnTransitions  = new List <TransitionBase>();
            ExpressionTransition  exitInnSCTransit    = new ExpressionTransition();
            Expression            exitInnSCTransitExp = new Expression();
            exitInnSCTransitExp.PushUnit(isReachDestination);
            exitInnSCTransit.SetExpression(exitInnSCTransitExp);
            exitInnTransitions.Add(exitInnSCTransit);
            exitInn.Transitions = exitInnTransitions;
        }

        return(newSM);
    }