Beispiel #1
0
 /// <summary>
 /// 派发事件,这是线程安全的
 /// </summary>
 /// <param name="sender">事件发送者,一般填this即可</param>
 /// <param name="gameEventBase"></param>
 public void Dispatch(object sender, GameEventBase gameEventBase)
 {
     lock (m_Events)
     {
         gameEventBase.Sender = sender;
         m_Events.Enqueue(gameEventBase);
     }
 }
Beispiel #2
0
 /// <summary>
 /// 事件轮询
 /// </summary>
 internal void OnUpdate(float deltaTime, float unscaledDeltaTime)
 {
     lock (m_Events)
     {
         while (m_Events.Count > 0)
         {
             GameEventBase gameEventBase = m_Events.Dequeue();
             DispatchNow(gameEventBase.Sender, gameEventBase);
         }
     }
 }
Beispiel #3
0
        private void OnLoadDataTableFailure(GameEventBase gameEventBase)
        {
            LoadDataTableFailureGameEvent loadDataTableFailureGameEvent = (LoadDataTableFailureGameEvent)gameEventBase;

            if (loadDataTableFailureGameEvent.UserData != this)
            {
                return;
            }
            GameEntry.Event.CommonEvent.Dispatch(this, GameEntry.Pool.SpawnClassObject <ILRuntimePreloadGameEvent>().Fill(false, this));
            Log.Error("Can not load data table '{0}' from '{1}' with error message '{2}'.", loadDataTableFailureGameEvent.DataTableName, loadDataTableFailureGameEvent.DataTableAssetName, loadDataTableFailureGameEvent.ErrorMessage);
        }
Beispiel #4
0
        private void OnLoadDataTableSuccess(GameEventBase gameEventBase)
        {
            LoadDataTableSuccessGameEvent loadDataTableSuccessGameEvent = (LoadDataTableSuccessGameEvent)gameEventBase;

            if (loadDataTableSuccessGameEvent.UserData != this)
            {
                return;
            }

            Log.Info("Load data table '{0}' OK.", loadDataTableSuccessGameEvent.DataTableName);
            m_PreloadCount++;
            if (m_PreloadCount >= m_TotalCount)
            {
                GameEntry.Event.CommonEvent.Dispatch(this, GameEntry.Pool.SpawnClassObject <ILRuntimePreloadGameEvent>().Fill(true, this));
            }
        }
Beispiel #5
0
        /// <summary>
        /// 立刻派发事件,这不是线程安全的
        /// </summary>
        /// <param name="sender">事件发送者,一般填this即可</param>
        /// <param name="gameEventBase">事件内容</param>
        public void DispatchNow(object sender, GameEventBase gameEventBase)
        {
            List <OnActionHandler> lstHandler = null;

            m_EventHandlers.TryGetValue(gameEventBase.Id, out lstHandler);
            gameEventBase.Sender = sender;

            if (lstHandler != null)
            {
                int lstCount = lstHandler.Count; //获取集合数量 只调用一次
                for (int i = 0; i < lstCount; i++)
                {
                    //获取索引数据 只调用一次
                    OnActionHandler handele = lstHandler[i];

                    if (handele != null)
                    {
                        handele(gameEventBase);
                    }
                }
            }

            HotfixEntry.Pool.UnSpawnClassObject(gameEventBase);
        }