Beispiel #1
0
    T[] GetCollisionObjectsFromChildren(Vector2 checkPosition, float checkRadius)
    {
        List <T> objs = new List <T>();

        if (_upperRightChild._field.PointToFieldDistance(checkPosition) <= checkRadius)
        {
            objs.AddRange(_upperRightChild.CheckCollision(checkPosition, checkRadius)); //这里用的不是 if else 而是连续存入,因为检测的范围是一个圆,基本不可能只在一个节点范围里,因此要把每个子节点都考虑到
        }
        if (_lowerRightChild._field.PointToFieldDistance(checkPosition) <= checkRadius)
        {
            objs.AddRange(_lowerRightChild.CheckCollision(checkPosition, checkRadius));
        }
        if (_lowerLeftChild._field.PointToFieldDistance(checkPosition) <= checkRadius)
        {
            objs.AddRange(_lowerLeftChild.CheckCollision(checkPosition, checkRadius));
        }
        if (_upperLeftChild._field.PointToFieldDistance(checkPosition) <= checkRadius)
        {
            objs.AddRange(_upperLeftChild.CheckCollision(checkPosition, checkRadius));
        }

        return(objs.ToArray());
    }
Beispiel #2
0
 public static GameObject[] CheckCollision(Vector2 checkPosition, float radius)
 {
     return(_quadtree.CheckCollision(checkPosition, radius));
 }