Esempio n. 1
0
        /// <summary>
        /// 处理事件结点。
        /// </summary>
        /// <param name="sender">事件源。</param>
        /// <param name="e">事件参数。</param>
        private void HandleEvent(object sender, T e)
        {
            bool noHandlerException = false;
            GameFrameworkLinkedListRange <EventHandler <T> > range = default(GameFrameworkLinkedListRange <EventHandler <T> >);

            if (m_EventHandlers.TryGetValue(e.Id, out range))
            {
                LinkedListNode <EventHandler <T> > current = range.First;
                while (current != null && current != range.Terminal)
                {
                    m_CachedNodes[e] = current.Next != range.Terminal ? current.Next : null;
                    current.Value(sender, e);
                    current = m_CachedNodes[e];
                }

                m_CachedNodes.Remove(e);
            }
            else if (m_DefaultHandler != null)
            {
                m_DefaultHandler(sender, e);
            }
            else if ((m_EventPoolMode & EventPoolMode.AllowNoHandler) == 0)
            {
                noHandlerException = true;
            }

            ReferencePool.Release(e);

            if (noHandlerException)
            {
                throw new GameFrameworkException(Utility.Text.Format("Event '{0}' not allow no handler.", e.Id.ToString()));
            }
        }
        /// <summary>
        /// 从指定的主键中移除指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        /// <returns>是否移除成功。</returns>
        public bool Remove(TKey key, TValue value)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                for (LinkedListNode <TValue> current = range.First; current != null && current != range.Terminal; current = current.Next)
                {
                    if (current.Value.Equals(value))
                    {
                        if (current == range.First)
                        {
                            LinkedListNode <TValue> next = current.Next;
                            if (next == range.Terminal)
                            {
                                m_LinkedList.Remove(next);
                                m_Dictionary.Remove(key);
                            }
                            else
                            {
                                m_Dictionary[key] = new GameFrameworkLinkedListRange <TValue>(next, range.Terminal);
                            }
                        }

                        m_LinkedList.Remove(current);
                        return(true);
                    }
                }
            }

            return(false);
        }
 /// <summary>
 /// 获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <returns>指定主键的范围。</returns>
 public GameFrameworkLinkedListRange <TValue> this[TKey key]
 {
     get
     {
         GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);
         m_Dictionary.TryGetValue(key, out range);
         return(range);
     }
 }
        /// <summary>
        /// 检查多值字典中是否包含指定值。
        /// </summary>
        /// <param name="key">要检查的主键。</param>
        /// <param name="value">要检查的值。</param>
        /// <returns>多值字典中是否包含指定值。</returns>
        public bool Contains(TKey key, TValue value)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                return(range.Contains(value));
            }

            return(false);
        }
            internal Enumerator(GameFrameworkLinkedListRange <T> range)
            {
                if (!range.IsValid)
                {
                    throw new GameFrameworkException("Range is invalid.");
                }

                m_GameFrameworkLinkedListRange = range;
                m_Current      = m_GameFrameworkLinkedListRange.m_First;
                m_CurrentValue = default(T);
            }
Esempio n. 6
0
        /// <summary>
        /// 获取事件处理函数的数量。
        /// </summary>
        /// <param name="id">事件类型编号。</param>
        /// <returns>事件处理函数的数量。</returns>
        public int Count(int id)
        {
            GameFrameworkLinkedListRange <EventHandler <T> > range = default(GameFrameworkLinkedListRange <EventHandler <T> >);

            if (m_EventHandlers.TryGetValue(id, out range))
            {
                return(range.Count);
            }

            return(0);
        }
        /// <summary>
        /// 向指定的主键增加指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        public void Add(TKey key, TValue value)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                m_LinkedList.AddBefore(range.Terminal, value);
            }
            else
            {
                LinkedListNode <TValue> first    = m_LinkedList.AddLast(value);
                LinkedListNode <TValue> terminal = m_LinkedList.AddLast(default(TValue));
                m_Dictionary.Add(key, new GameFrameworkLinkedListRange <TValue>(first, terminal));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 向指定的主键增加指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        public void Add(TKey key, TValue value)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                LinkedListNode <TValue> last = m_LinkedList.AddAfter(range.Last, value);
                m_Dictionary[key] = new GameFrameworkLinkedListRange <TValue>(range.First, last);
            }
            else
            {
                LinkedListNode <TValue> node = m_LinkedList.AddLast(value);
                m_Dictionary.Add(key, new GameFrameworkLinkedListRange <TValue>(node));
            }
        }
        /// <summary>
        /// 从指定的主键中移除所有的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <returns>是否移除成功。</returns>
        public bool RemoveAll(TKey key)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                m_Dictionary.Remove(key);

                LinkedListNode <TValue> current = range.First;
                while (current != null)
                {
                    LinkedListNode <TValue> next = current != range.Terminal ? current.Next : null;
                    m_LinkedList.Remove(current);
                    current = next;
                }

                return(true);
            }

            return(false);
        }
Esempio n. 10
0
        /// <summary>
        /// 从指定的主键中移除指定的值。
        /// </summary>
        /// <param name="key">指定的主键。</param>
        /// <param name="value">指定的值。</param>
        /// <returns>是否移除成功。</returns>
        public bool Remove(TKey key, TValue value)
        {
            GameFrameworkLinkedListRange <TValue> range = default(GameFrameworkLinkedListRange <TValue>);

            if (m_Dictionary.TryGetValue(key, out range))
            {
                LinkedListNode <TValue> current = range.First;
                while (current != null)
                {
                    if (current.Value.Equals(value))
                    {
                        if (current == range.First)
                        {
                            if (current == range.Last)
                            {
                                m_Dictionary.Remove(key);
                            }
                            else
                            {
                                m_Dictionary[key] = new GameFrameworkLinkedListRange <TValue>(current.Next, range.Last);
                            }
                        }
                        else if (current == range.Last)
                        {
                            m_Dictionary[key] = new GameFrameworkLinkedListRange <TValue>(range.First, current.Previous);
                        }

                        m_LinkedList.Remove(current);
                        return(true);
                    }

                    current = current != range.Last ? current.Next : null;
                }
            }

            return(false);
        }
 /// <summary>
 /// 尝试获取多值字典中指定主键的范围。
 /// </summary>
 /// <param name="key">指定的主键。</param>
 /// <param name="range">指定主键的范围。</param>
 /// <returns>是否获取成功。</returns>
 public bool TryGetValue(TKey key, out GameFrameworkLinkedListRange <TValue> range)
 {
     return(m_Dictionary.TryGetValue(key, out range));
 }