Ejemplo n.º 1
0
 private void LeaveChildren(StateEventArg arg)
 {
     foreach (var region in regions)
     {
         region.Value.Leave(arg);
     }
 }
Ejemplo n.º 2
0
 private void EnterChildren(StateEventArg arg)
 {
     foreach (var region in regions)
     {
         region.Value.Enter(arg);
     }
 }
Ejemplo n.º 3
0
        public void Enter(StateEventArg arg)
        {
            Assert.IsNotNull(initial);

            ChangeActive(initial, initial, null);
            rootActive.EnterFromParent(arg);
        }
Ejemplo n.º 4
0
        public void Leave(StateEventArg arg)
        {
            Assert.IsNotNull(rootActive);

            rootActive.LeaveFromParent(arg);
            ChangeActiveImpl(null, null, null);
        }
Ejemplo n.º 5
0
 private void ChangeActive(Vertex v, Vertex rootState, StateEventArg arg)
 {
     if (v is State)
     {
         ChangeActiveImpl(v as State, rootState as State, arg);
     }
 }
Ejemplo n.º 6
0
    private void RemoveSreen( object sender, StateEventArg arg) 
    {
		if ((GameState)arg.currentState == GameState.Playing)
        {
            isLoading = false;
        }
    }
Ejemplo n.º 7
0
    protected override void LeaveProcedure(StateEventArg arg)
    {
        ProcedureStateMachine?.Destroy();
        m_systems.TearDown();
        EventRoute.Dispose();
        m_contexts.game.DestroyAllEntities();
        m_contexts.Reset();
        Object.Destroy(m_rootNode.gameObject);

#if (!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
        Object.Destroy(m_systems.gameObject);

        var contextObserverBehaviours = Object.FindObjectsOfType <Entitas.VisualDebugging.Unity.ContextObserverBehaviour>();
        var allContexts = m_contexts.allContexts;
        foreach (var ob in contextObserverBehaviours)
        {
            if (System.Array.IndexOf(allContexts, ob.contextObserver.context) != -1)
            {
                Object.Destroy(ob.gameObject);
            }
        }
#endif

        m_blackboard            = null;
        m_procedureStateMachine = null;
        m_systems     = null;
        m_contexts    = null;
        m_rootNode    = null;
        m_eventRoute  = null;
        m_schedulable = null;
    }
Ejemplo n.º 8
0
    protected override void EnterProcedure(StateEventArg arg)
    {
        m_contexts = new Contexts();

        m_eventRoute = new EntitasEventRoute(m_contexts);

        m_rootNode = new GameObject(GetRootNodeName()).transform;
        RootNodeService.RootNode = m_rootNode;

        m_blackboard = new Blackboard();

        m_procedureStateMachine = CreateStateMachine();

        m_schedulable = new Schedulable();

        m_systems = new Feature("Systems");
        EntitasSystemEnvironment parameters = new EntitasSystemEnvironment(m_contexts.game, EventRoute, Blackboard, ProcedureStateMachine, m_schedulable);

        CreateSystems(m_systems, parameters);
        m_systems.Initialize();

        if (ProcedureStateMachine != null)
        {
            ProcedureStateMachine.EnterStateEvent += OnEnterState;
            RequireStateTransitionDelay("__Start");
        }
    }
Ejemplo n.º 9
0
 protected void RequireStateTransitionDelay(string transition, StateEventArg arg = null)
 {
     EventRoute.SendEvent(EventSendType.OneTime, new SystemStateTransitionEvent()
     {
         transition = transition,
         eventArg   = arg
     });
 }
Ejemplo n.º 10
0
 internal override bool HandleEvent(string transitionName, StateEventArg arg)
 {
     foreach (var region in regions)
     {
         if (region.Value.HandleEvent(transitionName, arg))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 11
0
 internal override void EnterFromChild(Region r, StateEventArg arg)
 {
     base.EnterFromChild(r, arg);
     foreach (var region in regions)
     {
         if (region.Value != r)
         {
             region.Value.Enter(arg);
         }
     }
 }
Ejemplo n.º 12
0
        public void LeaveChild(State child, Region lca, StateEventArg arg)
        {
            Assert.IsNotNull(child);
            Assert.AreEqual(child.Container, this);

            if (this != lca)
            {
                if (State != null)
                {
                    State.LeaveFromChild(lca, arg);
                }
            }
        }
Ejemplo n.º 13
0
        public void EnterChild(State child, StateEventArg arg)
        {
            Assert.IsNotNull(child);
            Assert.AreEqual(child.Container, this);

            if (rootActive != child)
            {
                if (State != null)
                {
                    State.EnterFromChild(this, arg);
                    ChangeActiveImpl(child, child, null);
                }
            }
        }
Ejemplo n.º 14
0
 private void OnLeaveProcedure(StateEventArg arg)
 {
     if (Running)
     {
         if (suspendable && !m_paused && arg is ProcedurePauseEvent)
         {
             m_paused = true;
             PauseProcedure(arg as ProcedurePauseEvent);
         }
         else
         {
             Running = false;
             LeaveProcedure(arg);
         }
     }
 }
    protected override void EnterProcedure(StateEventArg arg)
    {
        m_blackboard = new Blackboard();

        m_procedureStateMachine = CreateStateMachine();

        m_systems = new Feature("Systems");
        CreateSystems(m_systems);
        m_systems.Initialize();

        if (m_procedureStateMachine != null)
        {
            m_procedureStateMachine.EnterStateEvent += OnEnterState;
            m_procedureStateMachine.Start();
        }
    }
Ejemplo n.º 16
0
 private void ChangeActiveImpl(State state, State rootState, StateEventArg arg)
 {
     if (active != null)
     {
         StateMachine.OnLeaveState(active.Name);
     }
     active     = state;
     rootActive = rootState;
     StateMachine.OnEnterState(rootActive != null ? rootActive.Name : "", arg);
     //Debug.Log(string.Format("Region {0} Active: {1}", Name, rootActive != null ? rootActive.Name : "null"));
     if (rootActive is FinalState)
     {
         IsFinal = true;
         FinalEvent?.Invoke();
     }
 }
Ejemplo n.º 17
0
 public void FireEvent(string transitionName, StateEventArg arg = null)
 {
     if (transitionName == "__Start")
     {
         Start();
     }
     else
     {
         foreach (var region in regions)
         {
             if (region.Value.HandleEvent(transitionName, arg))
             {
                 break;
             }
         }
     }
 }
    protected override void LeaveProcedure(StateEventArg arg)
    {
        m_procedureStateMachine?.Destroy();
        m_systems.TearDown();
        EventRoute.Dispose();

#if (!ENTITAS_DISABLE_VISUAL_DEBUGGING && UNITY_EDITOR)
        Object.Destroy(m_systems.gameObject);
#endif

        m_blackboard            = null;
        m_procedureStateMachine = null;
        m_systems    = null;
        m_contexts   = null;
        m_rootNode   = null;
        m_eventRoute = null;
    }
Ejemplo n.º 19
0
    protected override void OnEnter(StateEventArg arg)
    {
        base.OnEnter(arg);
        if (!Running)
        {
            if (suspendable && m_paused)
            {
                ResumeProcedure(arg);
            }
            else
            {
                EnterProcedure(arg);
            }

            m_paused = false;
            Running  = true;
        }
    }
Ejemplo n.º 20
0
    protected override void EnterProcedure(StateEventArg userData)
    {
        m_contexts = new Contexts();

        m_eventRoute = new EntitasEventRoute(m_contexts);

        m_rootNode = new GameObject(GetRootNodeName()).transform;
        RootNodeService.RootNode = m_rootNode;

        m_procedureStateMachine = CreateStateMachine();

        foreach (var v in Region.Subvertices)
        {
            EntitasSubProcedure p = v as EntitasSubProcedure;
            if (p == null)
            {
                continue;
            }
            p.InitialSubProcedure(m_contexts, m_rootNode, EventRoute);
        }
    }
Ejemplo n.º 21
0
        public bool HandleEvent(string transitionName, StateEventArg arg)
        {
            TransitionList list;
            Transition     t;

            if (!transitions.TryGetValue(transitionName, out list))
            {
                if (rootActive != null && rootActive.HandleEvent(transitionName, arg))
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                if (!list.TryGetValue(active, out t))
                {
                    return(false);
                }
            }

            if (t.RootSource != rootActive)
            {
                return(false);
            }

            if (t.Guard != null && !t.Guard())
            {
                return(true);
            }

            Assert.AreEqual(this, StateMachine.LCA(t.Source, t.Target));

            rootActive.LeaveImmediate(this, arg);
            t.Effect?.Invoke();
            ChangeActive(t.Target, t.RootTarget, arg);
            ((State)t.Target).EnterImmediate(arg);

            return(true);
        }
 protected virtual void LeaveProcedure(StateEventArg arg)
 {
 }
 protected virtual void OnEnterState(string state, StateEventArg arg)
 {
     EventRoute.SendEvent(EventSendType.OneFrame, new SystemSwitchStateEvent {
         state = state, arg = arg
     });
 }
Ejemplo n.º 24
0
    private void OnGameHandlerChangeState(object sender, StateEventArg arg)
    {
		GameState newState = (GameState)arg.currentState;
		if (newState == GameState.Playing)
        {
			this.spriteRenderer.enabled = true;
            ChangeCurrentState(CatState.Starting);
        }
		else if (newState == GameState.Transit)
        {
			ChangeCurrentState(CatState.Pause);
        }
		else if (newState == GameState.GameLost)
        {
			ChangeCurrentState(CatState.Dead);
        }
    }
Ejemplo n.º 25
0
 internal override void EnterImmediate(StateEventArg arg)
 {
     base.EnterImmediate(arg);
     EnterChildren(arg);
 }
Ejemplo n.º 26
0
	protected void OnChangeState(StateEventArg arg){
		if (RaiseChangeState != null) {
			RaiseChangeState(this, arg);		
		}
	}
Ejemplo n.º 27
0
 internal override void EnterFromParent(StateEventArg arg)
 {
     base.EnterFromParent(arg);
     EnterChildren(arg);
 }
Ejemplo n.º 28
0
 internal void OnEnterState(string state, StateEventArg arg)
 {
     EnterStateEvent?.Invoke(state, arg);
 }
 protected virtual void EnterProcedure(StateEventArg arg)
 {
 }
Ejemplo n.º 30
0
 internal override void LeaveFromParent(StateEventArg arg)
 {
     LeaveChildren(arg);
     base.LeaveFromParent(arg);
 }
 protected void RequireSwitchState(string transition, StateEventArg arg = null)
 {
     SystemEnvironment.StateMachine.FireEvent(transition, arg);
 }
Ejemplo n.º 32
0
 internal override void LeaveImmediate(Region lca, StateEventArg arg)
 {
     LeaveChildren(arg);
     base.LeaveImmediate(lca, arg);
 }
 public virtual void Enter(StateEventArg arg)
 {
 }