/// <summary>
 /// 触发一个事件。
 /// 该操作会将一个事件任务信息实例加入任务队列,实际执行将稍后处理。
 /// 考虑到线程安全,该操作内部将会做加锁操作。
 /// </summary>
 /// <param name="eventCode">Event code.</param>
 /// <param name="onCompleted">On completed.</param>
 /// <param name="data">Data.</param>
 public void TriggerEvent(AiukEventCode eventCode, Action onCompleted = null,
                          object data = null)
 {
     lock (m_EventLock)
     {
         var eventTask = AiukEventFactory.EventTaskPool.Take();
         eventTask.Init(eventCode, onCompleted, data);
         m_TaskQueue.Enqueue(eventTask);
     }
 }
        public AiukEventTask Init
        (
            AiukEventCode eventCode,
            Action action,
            object data = null
        )
        {
            EventCode   = eventCode;
            OnCompelted = action;
            EventData   = data;

            return(this);
        }
        public void RemoveSpecifiedHandler(AiukEventCode eventCode, int handlerId)
        {
            if (!m_EventHandleUnits.ContainsKey(eventCode.EventModuleType))
            {
#if UNITY_EDITOR || DEBUG
                AiukDebugUtility.LogWarning(
                    string.Format("尝试移除一个当前不存在的事件处理器,事件Id为{0}。",
                                  eventCode.EventName));
#endif
                return;
            }

            var unit = m_EventHandleUnits[eventCode.EventModuleType];
            unit.RemoveSpecifiedHandler(eventCode.EventName, handlerId);
        }
 public int WatchEvent(AiukEventCode eventCode, Action <object> action,
                       int executeCount = -1)
 {
     if (!m_EventHandleUnits.ContainsKey(eventCode.EventModuleType))
     {
         var newUnit = new AiukEventHandleUnit();
         m_EventHandleUnits.Add(eventCode.EventModuleType, newUnit);
         var handlerId = newUnit.WatchEvent(eventCode.EventName, action, executeCount);
         return(handlerId);
     }
     else
     {
         var unit      = m_EventHandleUnits[eventCode.EventModuleType];
         var handlerId = unit.WatchEvent(eventCode.EventName, action, executeCount);
         return(handlerId);
     }
 }
Example #5
0
 public void RemoveSpecifiedHandler(AiukEventCode eventCode, int handlerId)
 {
     m_ApiCore.RemoveSpecifiedHandler(eventCode, handlerId);
 }
Example #6
0
 public void RemoveAllHandler(AiukEventCode eventCode)
 {
     m_ApiCore.RemoveEvent(eventCode);
 }
Example #7
0
 public void TriggerEvent(AiukEventCode eventCode, Action onCompelted = null,
                          object data = null)
 {
     m_ApiCore.TriggerEvent(eventCode, onCompelted, data);
 }
Example #8
0
        public int WatchEvent(AiukEventCode eventCode, Action <object> action, int executeCount = -1)
        {
            var handlerId = m_ApiCore.WatchEvent(eventCode, action, executeCount);

            return(handlerId);
        }
        private static AiukEventCode CreateNewEventCode(string moduleType, string id)
        {
            var eventCode = new AiukEventCode(moduleType, id);

            return(eventCode);
        }