Ejemplo n.º 1
0
        void RunStackAction(StackAction action, List <T> stack, Action onComplete)
        {
            if (stack.Count == 0)
            {
                ListPool <T> .Release(stack);

                onComplete.Invoke();
                return;
            }

            var applicationState = stack.Last();

            stack.RemoveAt(stack.Count - 1);

            var changeEvent = StackChangeEvent <T> .GetPooled(action, applicationState);

            var changeStateRequest = new ProgressListenerRequest();

            changeStateRequest.OnProgressChange += () => InvokeProgressChange(changeStateRequest.Progress, changeEvent);
            changeStateRequest.OnComplete       += () =>
            {
                RunStackAction(action, stack, onComplete);
                StackChangeEvent <T> .Release(changeEvent);
            };

            GetStateFromEnum(applicationState).ChangeState(changeEvent, changeStateRequest);
        }
Ejemplo n.º 2
0
        public static StackChangeEvent <TEnum> GetPooled(StackAction action, TEnum state)
        {
            var e = s_EventsPool.Get();

            e.Action = action;
            e.State  = state;

            return(e);
        }
Ejemplo n.º 3
0
        public static StackChangeEvent <T> GetPooled(StackAction action, IReadOnlyList <T> oldStackValue, IReadOnlyList <T> newStackValue)
        {
            var e = s_EventsPool.Get();

            e.Action        = action;
            e.OldStackValue = oldStackValue;
            e.NewStackValue = newStackValue;

            return(e);
        }
Ejemplo n.º 4
0
 public override void OnEnter(StackAction stackAction)
 {
     if (stackAction == StackAction.Push)
     {
         gameObject.SetActive(true);
     }
     else
     {
         canvasGroup.interactable = true;
         background.color         = GameSettings.instance.enabledUIColor;
     }
 }
Ejemplo n.º 5
0
 public override void OnExit(StackAction stackAction)
 {
     if (stackAction == StackAction.Pop)
     {
         gameObject.SetActive(false);
     }
     else
     {
         canvasGroup.interactable = false;
         background.color         = GameSettings.instance.disabledUIColor;
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Change the current state of the state manager. Add it to the state stack.
        /// Will trigger state changing events and transitions.
        /// Any additional state changes that happened in the meantime will be queued and executed after the current change finishes.
        /// </summary>
        public void ChangeState(TState state, object param, StackAction stackAction)
        {
            // Already in this state, do nothing.
            // Only if change is the same.
            if (CurrentState.CompareTo(state) == 0 && Equals(CurrentStateParam, param))
            {
                return;
            }

            // Sanity check.
            if (m_StackedStates.Count > 7 && stackAction == StackAction.Push)
            {
                UnityEngine.Debug.LogWarning($"You're stacking too many states down. Are you sure? Stacked state: {state}.");
            }

            // TODO: Validate State Event. Give chance users to reject the next state.

            if (m_ChangingStates)
            {
                m_PendingStateChanges.Enqueue(new StateEventArgs <TState>(default(TState), null, state, param, stackAction, this));
                return;
            }
            else
            {
                m_ChangingStates = true;
            }


            TState prevState      = CurrentState;
            object prevStateParam = CurrentStateParam;

            // Can access while inside event handler.
            CurrentEventArgs = new StateEventArgs <TState>(prevState, prevStateParam, state, param, stackAction, this);

            // HACK: User may start and finish transition while on this call. Prevent him from finishing the transition, I'll do it here after that.
            m_ExecutingTransitionEffect = true;

            TransitionStarts?.Invoke(CurrentEventArgs);
            m_TransitionStartsSubscribers[state]?.Invoke();

            m_ExecutingTransitionEffect = false;

            if (CurrentEventArgs.TransitionsPending.Count == 0)
            {
                OnTransitionFinished();
            }
        }
Ejemplo n.º 7
0
    void PushAction(int id, StackAction type, float t = 0.0f, string text = "", int param = 0)
    {
        if (!UnitActKey.Contains(id))
        {
            UnitActKey.Add(id);
        }
        if (!UnitActionStack.ContainsKey(id))
        {
            UnitActionStack.Add(id, new ActionConfig());
            UnitActionStack[id].id = id;
        }
        ActionItem it = new ActionItem();

        it.text       = text;
        it.pause_time = t;
        it.type       = type;//say = 1 pause = 2 skill = 3;crouch = 4, block=5
        it.param      = param;
        UnitActionStack[id].action.Add(it);
    }
Ejemplo n.º 8
0
 protected StackQueueEventArgs(StackAction order, object obj)
 {
     this.Order  = order;
     this.time   = DateTime.Now.ToBinary();
     this.Object = obj;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// 作为子状态机使用时需要实现此方法
 /// </summary>
 public virtual void OnExit(StackAction stackAction)
 {
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 作为子状态机使用时需要实现此方法
 /// </summary>
 public virtual void OnEnter(StackAction stackAction)
 {
 }
 public override void OnExit(StackAction stackAction)
 {
     _onExit?.Invoke(stackAction);
 }
 public override void OnEnter(StackAction stackAction)
 {
     _onEnter?.Invoke(stackAction);
 }
 public abstract void OnExit(StackAction stackAction);
 public abstract void OnEnter(StackAction stackAction);
Ejemplo n.º 15
0
 protected StackQueueEventArgs(bool Empty)
 {
     this.Order  = StackAction.None;
     this.Object = null;
     this.time   = DateTime.Now.ToBinary();
 }
Ejemplo n.º 16
0
 public StackQueueEventArgs(StackAction order)
     : this(order, null)
 {
 }
Ejemplo n.º 17
0
 public ParseItem(StackAction stackAction, string value = null)
 {
     StackAction = stackAction;
     Value       = value;
 }
Ejemplo n.º 18
0
 public StackRequest(StackAction action, int sceneID = 0)
 {
     Action = action;
     SceneID = sceneID;
 }
Ejemplo n.º 19
0
 public void TypeStack(string type, int index, StackAction action)
 {
     string innerMessage = $"{action}: \"{type}\", Index: {index}";
     WriteEntry("TYPE STACK", innerMessage);
 }