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)); }
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()); }
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. } }
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); }