public void AddListener(EventImplPriority priority, System.Action action) { if (Listeners == null) { Listeners = new List <KeyValuePair <EventImplPriority, System.Action> >(); } InternalAddListener(ref Listeners, priority, action); }
protected static void InternalAddListener <T>(ref List <KeyValuePair <EventImplPriority, T> > list, EventImplPriority priority, T action) { int l = 0, r = list.Count - 1; while (l <= r) { int i = l + r >> 1; var listener = list[i]; if (listener.Key < priority) { l = i + 1; } else if (listener.Key > priority) { r = i - 1; } else { break; } } list.Insert(l, new KeyValuePair <EventImplPriority, T>(priority, action)); }
protected static void publicAddListener <T>(ref List <KeyValuePair <EventImplPriority, T> > list, EventImplPriority priority, T action) { int lastIndex = list.Count - 1; int index = 0; while (index < lastIndex) { int tmpIndex = index + lastIndex >> 1; var listener = list[tmpIndex]; if (listener.Key < priority) { index = tmpIndex + 1; } else if (listener.Key > priority) { lastIndex = tmpIndex - 1; } else { break; } } list.Insert(index, new KeyValuePair <EventImplPriority, T>(priority, action)); }