Exemple #1
0
        public void ForEach(QTAction action, bool isFirstSelf)
        {
            if (action == null)
            {
                return;
            }
            if (isFirstSelf)
            {
                action(this);
            }

            if (m_Childs != null)
            {
                for (int i = m_Childs.Count - 1; i >= 0; --i)
                {
                    var node = m_Childs[i];
                    node.ForEach(action, isFirstSelf);
                }
            }

            if (!isFirstSelf)
            {
                action(this);
            }
        }
Exemple #2
0
        /// <summary>
        /// onCombineAction 性能不太好,不要频繁,不带onCombineAction不会合并Child
        /// </summary>
        /// <param name="item">格子内物品</param>
        /// <param name="onCombineAction">合并格子的回调</param>
        /// <returns></returns>
        public bool RemoveItem(T item, QTAction onCombineAction = null)
        {
            if (item == null)
            {
                return(false);
            }
            if (!m_bounds.IsContains(item.Rectangle))
            {
                return(false);
            }

            if (m_Childs != null && m_bounds.IsChildsContains(item.Rectangle))
            {
                for (int i = 0; i < m_Childs.Count; ++i)
                {
                    var node = m_Childs[i];
                    if (node.Bounds.IsContains(item.Rectangle))
                    {
                        bool ret = node.RemoveItem(item, onCombineAction);
                        if (ret && (onCombineAction != null))
                        {
                            if (IsChildsMustCombine())
                            {
                                onCombineAction(node);
                            }
                        }
                        return(ret);
                    }
                }
            }

            if (m_Contents != null)
            {
                for (int i = 0; i < m_Contents.Count; ++i)
                {
                    var content = m_Contents[i];
                    if (content.Equals(item))
                    {
                        m_Contents.RemoveAt(i);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #3
0
 /// <summary>
 /// Do the specified action for each item in the quadtree
 /// </summary>
 /// <param name="action"></param>
 public void ForEach(QTAction action)
 {
     m_root.ForEach(action);
 }
Exemple #4
0
		/// <summary>
		/// Do the specified action for each item in the quadtree
		/// </summary>
		/// <param name="action"></param>
		public void ForEach(QTAction action)
		{
			m_root.ForEach(action);
		}