private static object _OverlapBox(FPVector2 point, FPVector2 size, FP angle, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { size *= FP.Half; angle *= FP.Deg2Rad; return(OverlapGeneric(new Physics2D.PolygonShape(Physics2D.PolygonTools.CreateRectangle(size.x, size.y, point, angle * -1), 1), point, sensorType, layerMask)); }
private static object _OverlapBox(TSVector2 point, TSVector2 size, FP angle, Physics2D.BodySpecialSensor sensorType) { size *= FP.Half; angle *= FP.Deg2Rad; return(OverlapGeneric(new Physics2D.PolygonShape(Physics2D.PolygonTools.CreateRectangle(size.x, size.y, point, angle * -1), 1), point, sensorType)); }
/** * @brief Returns the first {@link TSCollider2D} within a rectangular area. Returns null if there is none. * * @param pointA Top-left corner of the rectangle. * @param radius Bottom-right corner of the rectangle. * @param layerMask Unity's layer mask to filter objects. **/ public static object _OverlapArea(FPVector2 pointA, FPVector2 pointB, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { FPVector2 center; center.x = (pointA.x + pointB.x) * FP.Half; center.y = (pointA.y + pointB.y) * FP.Half; Physics2D.Vertices vertices = new Physics2D.Vertices(4); vertices.Add(new FPVector2(pointA.x, pointA.y) - center); vertices.Add(new FPVector2(pointB.x, pointA.y) - center); vertices.Add(new FPVector2(pointB.x, pointB.y) - center); vertices.Add(new FPVector2(pointA.x, pointB.y) - center); return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, sensorType, layerMask)); }
public static object _OverlapArea(TSVector2 i_PointA, TSVector2 i_PointB, Physics2D.BodySpecialSensor i_SensorType, int i_Mask) { TSVector2 center; center.x = (i_PointA.x + i_PointB.x) * FP.Half; center.y = (i_PointA.y + i_PointB.y) * FP.Half; Physics2D.Vertices vertices = new Physics2D.Vertices(4); vertices.Add(new TSVector2(i_PointA.x, i_PointA.y) - center); vertices.Add(new TSVector2(i_PointB.x, i_PointA.y) - center); vertices.Add(new TSVector2(i_PointB.x, i_PointB.y) - center); vertices.Add(new TSVector2(i_PointA.x, i_PointB.y) - center); return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, i_SensorType, i_Mask)); }
/** * @brief Returns the first {@link TSCollider2D} within a rectangular area. Returns null if there is none. * * @param pointA Top-left corner of the rectangle. * @param radius Bottom-right corner of the rectangle. **/ public static object _OverlapArea(TSVector2 pointA, TSVector2 pointB, Physics2D.BodySpecialSensor sensorType) { TSVector2 center; center.x = (pointA.x + pointB.x) * FP.Half; center.y = (pointA.y + pointB.y) * FP.Half; Physics2D.Vertices vertices = new Physics2D.Vertices(4); vertices.Add(new TSVector2(pointA.x, pointA.y) - center); vertices.Add(new TSVector2(pointB.x, pointA.y) - center); vertices.Add(new TSVector2(pointB.x, pointB.y) - center); vertices.Add(new TSVector2(pointA.x, pointB.y) - center); return(OverlapGeneric(new Physics2D.PolygonShape(vertices, 1), center, sensorType)); }
private static object _OverlapCircle(FPVector2 point, FP radius, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { return(OverlapGeneric(new Physics2D.CircleShape(radius, 1), point, sensorType, layerMask)); }
public static object _CircleCast(FPVector2 origin, FP radius, FPVector2 direction, FP distance, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { if (distance + radius > FP.MaxValue) { distance = FP.MaxValue - radius; } direction.Normalize(); FPVector2 offsetToCenter = ((direction * distance) * FP.Half); offsetToCenter.x = FP.Abs(offsetToCenter.x); offsetToCenter.y = FP.Abs(offsetToCenter.y); FP angle = FPVector2.Angle(direction, FPVector2.right); if (direction.x <= 0 && direction.y >= 0) { offsetToCenter.x = -offsetToCenter.x; } else if (direction.x <= 0 && direction.y <= 0) { offsetToCenter.x = -offsetToCenter.x; offsetToCenter.y = -offsetToCenter.y; angle = -angle; } else if (direction.x >= 0 && direction.y <= 0) { offsetToCenter.y = -offsetToCenter.y; angle = -angle; } FPVector2 center = origin + offsetToCenter; object result = _OverlapCapsule(center, new FPVector2(distance + radius * 2, radius * 2), TSCapsuleDirection2D.HORIZONTAL, -angle, sensorType, layerMask); if (result is FPCollider2D) { return(new FPRaycastHit2D((FPCollider2D)result)); } else { FPCollider2D[] resultAux = (FPCollider2D[])result; FPRaycastHit2D[] resultHit = new FPRaycastHit2D[resultAux.Length]; for (int index = 0; index < resultHit.Length; index++) { resultHit[index] = new FPRaycastHit2D(resultAux[index]); } return(resultHit); } }
private static object _OverlapCapsule(FPVector2 point, FPVector2 size, TSCapsuleDirection2D direction, FP angle, Physics2D.BodySpecialSensor sensorType, int layerMask = UnityEngine.Physics.DefaultRaycastLayers) { if (direction == TSCapsuleDirection2D.HORIZONTAL) { FP aux = size.y; size.y = size.x; size.x = aux; angle += 90; } FP radius = size.x * FP.Half; Physics2D.Vertices capVerts = Physics2D.PolygonTools.CreateCapsule(size.y, radius, 8, radius, 8); Physics2D.PolygonTools.TransformVertices(capVerts, point, angle * FP.Deg2Rad * -1); return(OverlapGeneric(new Physics2D.PolygonShape(capVerts, 1), point, sensorType, layerMask)); }
private static object OverlapGeneric(Physics2D.Shape shape, FPVector2 position, Physics2D.BodySpecialSensor sensorType, int layerMask) { Physics2D.World world = (Physics2D.World)Physics2DWorldManager.instance.GetWorld(); Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world); body.CreateFixture(shape); body.BodyType = Physics2D.BodyType.Static; body.IsSensor = true; body.CollidesWith = Physics2D.Category.All; body.SpecialSensor = sensorType; body.SpecialSensorMask = layerMask; body.Position = position; world.RemoveBody(body); world.ProcessRemovedBodies(); if (body._specialSensorResults.Count > 0) { if (sensorType == Physics2D.BodySpecialSensor.ActiveOnce) { return(Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[0]).GetComponent <FPCollider2D>()); } else { FPCollider2D[] result = new FPCollider2D[body._specialSensorResults.Count]; for (int i = 0; i < body._specialSensorResults.Count; i++) { result[i] = Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[i]).GetComponent <FPCollider2D>(); } return(result); } } return(null); }
private static object _OverlapCircle(TSVector2 i_Point, FP i_Radius, Physics2D.BodySpecialSensor i_SensorType, int i_Mask) { return(OverlapGeneric(new Physics2D.CircleShape(i_Radius, 1), i_Point, i_SensorType, i_Mask)); }
private static object OverlapGeneric(Physics2D.Shape i_Shape, TSVector2 i_Position, Physics2D.BodySpecialSensor i_SensorType, int i_Mask) { Physics2D.World world = (Physics2D.World)PhysicsManager.GetWorld(); Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world); body.CreateFixture(i_Shape); body.BodyType = Physics2D.BodyType.Static; body.CollisionCategories = Physics2D.Category.All; // Category.All is used for sweep test objects. body.CollidesWith = (Physics2D.Category)i_Mask; body.CollisionGroup = 0; body.IsSensor = true; body.SpecialSensor = i_SensorType; body.SpecialSensorMask = (int)Physics2D.Category.All; body.Position = i_Position; world.RemoveBody(body); world.ProcessRemovedBodies(); if (body._specialSensorResults.Count > 0) { if (i_SensorType == Physics2D.BodySpecialSensor.ActiveOnce) { return(PhysicsManager.GetGameObject(body._specialSensorResults[0]).GetComponent <TSCollider2D>()); } else { TSCollider2D[] result = new TSCollider2D[body._specialSensorResults.Count]; for (int i = 0; i < body._specialSensorResults.Count; i++) { result[i] = PhysicsManager.GetGameObject(body._specialSensorResults[i]).GetComponent <TSCollider2D>(); } return(result); } } return(null); }
private static object _OverlapBox(TSVector2 i_Point, TSVector2 i_Size, FP i_Angle, Physics2D.BodySpecialSensor i_SensorType, int i_Mask) { i_Size *= FP.Half; i_Angle *= FP.Deg2Rad; return(OverlapGeneric(new Physics2D.PolygonShape(Physics2D.PolygonTools.CreateRectangle(i_Size.x, i_Size.y, i_Point, i_Angle * -1), 1), i_Point, i_SensorType, i_Mask)); }
private static object _OverlapCircle(TSVector2 point, FP radius, Physics2D.BodySpecialSensor sensorType) { return(OverlapGeneric(new Physics2D.CircleShape(radius, 1), point, sensorType)); }