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))); }
//获取圆形范围内的物体 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]); } } } } }