コード例 #1
0
 public EventTask Init(EventCode _eventCode, Action action, object data = null)
 {
     eventCode   = _eventCode;
     onCompelted = action;
     eventData   = data;
     return(this);
 }
コード例 #2
0
 /// <summary>
 /// 触发一个事件。
 /// 该操作会将一个事件任务信息实例加入任务队列,实际执行将稍后处理。
 /// 考虑到线程安全,该操作内部将会做加锁操作。
 /// </summary>
 public void TriggerEvent(EventCode eventCode, object data = null, Action onCompleted = null)
 {
     lock (lockObj)
     {
         var eventTask = EventFactory.EventTaskPool.Take();
         eventTask.Init(eventCode, onCompleted, data);
         waitTasks.Enqueue(eventTask);
     }
 }
コード例 #3
0
        /// <summary>
        /// 立即触发一个事件。
        /// </summary>
        public void TriggerEventSync <T1, T2>(EventCode eventCode, T1 data1, T2 data2, Action onCompleted = null)
        {
            List <Delegate> actionList;

            if (eventHandlerList.TryGetValue(eventCode.EventID, out actionList))
            {
                foreach (var action in actionList)
                {
                    ((Action <T1, T2>)action)(data1, data2);
                }
            }
        }
コード例 #4
0
        public int WatchEvent <T1, T2>(EventCode eventCode, Action <T1, T2> action)
        {
            if (!eventHandlerList.ContainsKey(eventCode.EventID))
            {
                var newList = new List <Delegate>();
                eventHandlerList.Add(eventCode.EventID, newList);
            }
            var list      = eventHandlerList[eventCode.EventID];
            var handlerId = TallyEventHandlerCounter.GetEventHandlerId();

            list.Add(action);
            return(handlerId);
        }
コード例 #5
0
        public void RemoveHandlerById(EventCode eventCode, int handlerId)
        {
            if (!eventHandleUnits.ContainsKey(eventCode.EventModuleType))
            {
#if UNITY_EDITOR
                Debug.LogWarning(
                    $"尝试移除一个当前不存在的事件处理器,事件Id为{eventCode.EventID}。");
#endif
                return;
            }

            var unit = eventHandleUnits[eventCode.EventModuleType];
            unit.RemoveHandler(eventCode.EventID, handlerId);
        }
コード例 #6
0
 public int WatchEvent(EventCode eventCode, Action <object> action)
 {
     if (!eventHandleUnits.ContainsKey(eventCode.EventModuleType))
     {
         var newUnit = new EventHandleUnit();
         eventHandleUnits.Add(eventCode.EventModuleType, newUnit);
         var handlerId = newUnit.WatchEvent(eventCode.EventID, action);
         return(handlerId);
     }
     else
     {
         var unit      = eventHandleUnits[eventCode.EventModuleType];
         var handlerId = unit.WatchEvent(eventCode.EventID, action);
         return(handlerId);
     }
 }
コード例 #7
0
        /// <summary>
        /// 立即触发一个事件。
        /// </summary>
        public void TriggerEventSync(EventCode eventCode, Action onCompleted = null,
                                     object data = null)
        {
            var eventTask = EventFactory.EventTaskPool.Take();

            eventTask.Init(eventCode, onCompleted, data);
            if (!eventHandleUnits.ContainsKey(eventTask.eventCode.EventModuleType))
            {
#if UNITY_EDITOR
                Debug.LogWarning("尝试触发一个没有响应处理器的事件,"
                                 + $"事件Id为{eventTask.eventCode.EventID}");
#endif
                EventFactory.EventTaskPool.Restore(eventTask);
                return;
            }

            var unit = eventHandleUnits[eventTask.eventCode.EventModuleType];
            unit.ExecuteEvent(eventTask.eventCode.EventID, eventTask.eventData);
            eventTask.onCompelted?.Invoke();
            EventFactory.EventTaskPool.Restore(eventTask);
        }
コード例 #8
0
        private static EventCode CreateNewEventCode(string moduleType, string id)
        {
            var eventCode = new EventCode(moduleType, id);

            return(eventCode);
        }
コード例 #9
0
 public void TriggerEventSync <T1>(EventCode eventCode, T1 data, Action onCompelted = null)
 {
     eventDispatcher.TriggerEventSync(eventCode, data, onCompelted);
 }
コード例 #10
0
        //public void TriggerEvent<T1>(EventCode eventCode, T1 eventData1, Action onCompelted = null)
        //{
        //    eventDispatcher.TriggerEvent(eventCode, eventData1, onCompelted);
        //}

        //public void TriggerEvent<T1, T2>(EventCode eventCode, T1 eventData1, T2 eventData2, Action onCompelted = null)
        //{
        //    eventDispatcher.TriggerEvent(eventCode, eventData1, eventData2,onCompelted);
        //}

        public void TriggerEventSync(EventCode eventCode, object data = null, Action onCompelted = null)
        {
            eventDispatcher.TriggerEventSync(eventCode, onCompelted, data);
        }
コード例 #11
0
 public void TriggerEvent(EventCode eventCode, object eventData, Action onCompelted = null)
 {
     eventDispatcher.TriggerEvent(eventCode, eventData, onCompelted);
 }
コード例 #12
0
 public int WatchEvent <T1, T2>(EventCode eventCode, Action <T1, T2> action)
 {
     return(eventDispatcher.WatchEvent(eventCode, action));
 }
コード例 #13
0
 public int WatchEvent(EventCode eventCode, Action <object> action)
 {
     return(eventDispatcher.WatchEvent(eventCode, action));
 }
コード例 #14
0
 public void RemoveEventHandler(EventCode eventCode, int handlerId)
 {
     eventDispatcher.RemoveHandlerById(eventCode, handlerId);
 }
コード例 #15
0
 public void RemoveAllHandlers(EventCode eventCode)
 {
     eventDispatcher.RemoveAllHandler(eventCode);
 }