Ejemplo n.º 1
0
    void SetLeafToChildren(QuadtreeBasicLeaf <T> leaf)
    {
        Debug.Log("位置在(" + _field.top + "," + _field.right + "," + _field.bottom + "," + _field.left + ")的树枝节点向子节点存入位置在" + leaf.position + "的叶子");

        /*
         *  如果叶子在子节点的范围里,向这个子节点里存入叶子
         *  用 else if 的原因是 Field.Contains 把边缘处的点也算在范围里,这如果一个叶子在两个节点的交界处只用一个 if 就会重复存入
         */
        if (_upperRightChild._field.Contains(leaf.position))
        {
            _upperRightChild.SetLeaf(leaf);
        }
        else if (_lowerRightChild._field.Contains(leaf.position))
        {
            _lowerRightChild.SetLeaf(leaf);
        }
        else if (_lowerLeftChild._field.Contains(leaf.position))
        {
            _lowerLeftChild.SetLeaf(leaf);
        }
        else if (_upperLeftChild._field.Contains(leaf.position))
        {
            _upperLeftChild.SetLeaf(leaf);
        }
    }
Ejemplo n.º 2
0
 /*
  *  存入。移除。检测三个方法都是 static ,因为static方法可以通过类名调用,这样就省去了每个检测器都要 Find 一次四叉树物体的工作
  */
 public static void SetLeaf(QuadtreeBasicLeaf <GameObject> leaf)
 {
     _quadtree.SetLeaf(leaf);
 }