private void Tick()
        {
            if (m_ActionsQueue.Count == 0)
            {
                return;
            }

            for (int i = 0; i < m_MaxActionsPerFrame; i++)
            {
                if (m_ActionsQueue.Count == 0)
                {
                    break;
                }

                using (CascadeUpdateEvent.SuppressCascadeInvokeScope())
                {
                    try
                    {
                        m_ActionsQueue[0]?.Invoke();
                    }
                    catch (Exception e)
                    {
                        Debug.LogError("Error in cascade action: " + e);
                    }
                    m_ActionsQueue.RemoveAt(0);
                }
            }
        }
예제 #2
0
        private static IEnumerable <Action> ConstructActionsQueue(CascadeUpdateEvent cascadeUpdateEvent)
        {
            List <CascadeUpdateEvent>  eventsQueue   = new List <CascadeUpdateEvent>();
            Queue <CascadeUpdateEvent> eventsToVisit = new Queue <CascadeUpdateEvent>();

            eventsToVisit.Enqueue(cascadeUpdateEvent);

            while (eventsToVisit.Count > 0)
            {
                CascadeUpdateEvent evt = eventsToVisit.Dequeue();
                if (eventsQueue.Contains(evt))
                {
                    eventsQueue.Remove(evt);
                }
                eventsQueue.Add(evt);

                foreach (CascadeUpdateEvent subscriber in evt.m_Subscribers)
                {
                    eventsToVisit.Enqueue(subscriber);
                }
            }

            List <Action> actionsQueue = new List <Action>();

            foreach (CascadeUpdateEvent updateEvent in eventsQueue)
            {
                if (updateEvent.m_UpdateActions == null || updateEvent.m_UpdateActions.Count == 0)
                {
                    continue;
                }

                foreach (Action action in updateEvent.m_UpdateActions)
                {
                    if (actionsQueue.Contains(action))
                    {
                        actionsQueue.Remove(action);
                    }

                    actionsQueue.Add(action);
                }
            }

            return(actionsQueue);
        }
예제 #3
0
 public void Unsubscribe(CascadeUpdateEvent cascadeUpdateEvent)
 {
     m_Subscribers.Remove(cascadeUpdateEvent);
 }
예제 #4
0
 public IDisposable Subscribe(CascadeUpdateEvent cascadeUpdateEvent)
 {
     m_Subscribers.Add(cascadeUpdateEvent);
     return(Disposable.Create(() => Unsubscribe(cascadeUpdateEvent)));
 }