예제 #1
0
 private bool IsEnter(StepCollider someOne, StepCollider other)
 {
     if (someOne.shapeType == 1 && other.shapeType == 1)
     {
         return(ShapeTrigger.CheckCubeToCube(new Vector4(someOne.pos.x, someOne.pos.y, someOne.width, someOne.width), new Vector4(other.pos.x, other.pos.y, other.width, other.width)));
     }
     if (someOne.shapeType == 0 && other.shapeType == 0)
     {
         return(ShapeTrigger.CheckSphereToSphere(new Vector3(someOne.pos.x, someOne.pos.y, someOne.r), new Vector3(other.pos.x, other.pos.y, other.r)));
     }
     if (someOne.shapeType == 1)
     {
         return(ShapeTrigger.CheckSphereToCube(new Vector3(other.pos.x, other.pos.y, other.r), new Vector4(someOne.pos.x, someOne.pos.y, someOne.width, someOne.height)));
     }
     return(ShapeTrigger.CheckSphereToCube(new Vector3(someOne.pos.x, someOne.pos.y, someOne.r), new Vector4(other.pos.x, other.pos.y, other.width, other.height)));
 }
예제 #2
0
 public void GetGameObjectByRect(Vector4 rect)
 {
     OnRect.Clear();
     x1 = Mathf.CeilToInt(rect.x - rect.z) - 2;
     x2 = Mathf.CeilToInt(rect.x + rect.z) + 2;
     y1 = Mathf.CeilToInt(rect.y + rect.w) + 2;
     y2 = Mathf.CeilToInt(rect.y - rect.w) - 2;
     for (int i = x1; i <= x2; i++)
     {
         for (int j = y2; j <= y1; j++)
         {
             if (i < 0 || j < 0)
             {
                 continue;
             }
             if (i >= MapX || j >= MapY)
             {
                 continue;
             }
             if (MapDatas[i, j] == null)
             {
                 continue;
             }
             for (int k = 0; k < MapDatas[i, j].Count; k++)
             {
                 Other = StepColliders[MapDatas[i, j][k]];
                 if (Other.shapeType == 0)
                 {
                     if (ShapeTrigger.CheckSphereToCube(new Vector3(Other.pos.x, Other.pos.y, Other.r), rect))
                     {
                         OnRect.Add(MapDatas[i, j][k]);
                     }
                     continue;
                 }
                 if (ShapeTrigger.CheckCubeToCube(rect, new Vector4(Other.pos.x, Other.pos.y, Other.width, Other.height)))
                 {
                     OnRect.Add(MapDatas[i, j][k]);
                 }
             }
         }
     }
     //Debug.Log(OnRect.Count);
 }
예제 #3
0
 //获取圆形范围内的物体
 public void GetGameObjectSphere(Vector3 sphere)
 {
     OnSphere.Clear();
     x1 = Mathf.CeilToInt(sphere.x - sphere.z) - 2;
     x2 = Mathf.CeilToInt(sphere.x + sphere.z) + 2;
     y1 = Mathf.CeilToInt(sphere.y + sphere.z) + 2;
     y2 = Mathf.CeilToInt(sphere.y - sphere.z) - 2;
     for (int i = x1; i <= x2; i++)
     {
         for (int j = y2; j <= y1; j++)
         {
             if (i < 0 || j < 0)
             {
                 continue;
             }
             if (i >= MapX || j >= MapY)
             {
                 continue;
             }
             if (MapDatas[i, j] == null)
             {
                 continue;
             }
             for (int k = 0; k < MapDatas[i, j].Count; k++)
             {
                 Other = StepColliders[MapDatas[i, j][k]];
                 if (Other.shapeType == 1)
                 {
                     if (ShapeTrigger.CheckSphereToCube(new Vector3(sphere.x, sphere.y, sphere.z), new Vector4(Other.pos.x, Other.pos.y, Other.width, Other.height)))
                     {
                         OnSphere.Add(MapDatas[i, j][k]);
                     }
                     continue;
                 }
                 if (ShapeTrigger.CheckSphereToSphere(sphere, new Vector3(Other.pos.x, Other.pos.y, Other.r)))
                 {
                     OnSphere.Add(MapDatas[i, j][k]);
                 }
             }
         }
     }
 }