コード例 #1
0
        public void PublishEvent(string eventName, int count = 0, bool clickClear = false)
        {
            var args = ReferencePool.Take <RedDotEventArgs>();

            args.Name       = eventName;
            args.Count      = count;
            args.ClickClear = clickClear;
            _eventManager.Publish(this, args);
        }
コード例 #2
0
        /// <summary>
        /// 创建有限状态机。
        /// </summary>
        /// <param name="name">有限状态机名称。</param>
        /// <param name="owner">有限状态机持有者。</param>
        /// <param name="states">有限状态机状态集合。</param>
        /// <returns>创建的有限状态机。</returns>
        public static Fsm <T> Create(string name, T owner, params FsmState <T>[] states)
        {
            if (owner == null)
            {
                throw new GameException("FSM owner is invalid.");
            }

            if (states == null || states.Length < 1)
            {
                throw new GameException("FSM states is invalid.");
            }

            Fsm <T> fsm = ReferencePool.Take <Fsm <T> >();

            fsm.Name         = name;
            fsm.Owner        = owner;
            fsm._isDestroyed = false;
            foreach (FsmState <T> state in states)
            {
                if (state == null)
                {
                    throw new GameException("FSM states is invalid.");
                }

                Type stateType = state.GetType();
                if (fsm._states.ContainsKey(stateType))
                {
                    throw new GameException(Utility.Text.Format("FSM '{0}' state '{1}' is already exist.", new TypeNamePair(typeof(T), name).ToString(), stateType));
                }

                fsm._states.Add(stateType, state);
                state.OnInit(fsm);
            }

            return(fsm);
        }
コード例 #3
0
 public void PublishImmediately <TEventArgs>(TEventArgs e = default) where TEventArgs : GameEventArgs, new()
 {
     e = e ?? ReferencePool.Take <TEventArgs>();
     PublishImmediately(this, e);
 }