public static Vector2 TransformPoint(Vector2 p1, Vector2 center, bool flippedH, bool flippedV, TileInstance.Rotation rotation) { for (int i = 0; i < (int)rotation; i++) { p1 = RotatePoint(p1, center); } if (flippedH) { p1.x = (center.x - p1.x) + center.x; } if (flippedV) { p1.y = (center.y - p1.y) + center.y; } return(p1); }
public static Rect TransformRect(Rect rect, Vector2 center, bool flippedH, bool flippedV, TileInstance.Rotation rotation) { Vector2 v1 = new Vector2(rect.x, rect.y); Vector2 v2 = new Vector2(rect.xMax, rect.yMax); for (int i = 0; i < (int)rotation; i++) { v1 = RotatePoint(v1, center); v2 = RotatePoint(v2, center); } if (flippedH) { v1.x = (center.x - v1.x) + center.x; v2.x = (center.x - v2.x) + center.x; } if (flippedV) { v1.y = (center.y - v1.y) + center.y; v2.y = (center.y - v2.y) + center.y; } if (v2.x < v1.x) { float temp = v1.x; v1.x = v2.x; v2.x = temp; } if (v2.y < v1.y) { float temp = v1.y; v1.y = v2.y; v2.y = temp; } rect.x = v1.x; rect.y = v1.y; rect.xMax = v2.x; rect.yMax = v2.y; return(rect); }
public bool CanMergeBoxColliderWith(UniTileTile b, int aX, int aY, int bX, int bY, bool aFlippedH, bool aFlippedV, TileInstance.Rotation aRotation, bool bFlippedH, bool bFlippedV, TileInstance.Rotation bRotation, Vector2 tileSize) { if (b == null) { return(false); } Rect aRect = TileLayerUtil.TransformRect(boxDimensions, tileSize / 2f, aFlippedH, aFlippedV, aRotation); Rect bRect = TileLayerUtil.TransformRect(b.boxDimensions, tileSize / 2f, bFlippedH, bFlippedV, bRotation); return(b != null && b.boxCollider && boxDepth == b.boxDepth && boxLayer == b.boxLayer && boxMaterial == b.boxMaterial && boxTag == b.boxTag && boxPrefab == b.boxPrefab && ( ( !customBoxDimensions && !b.customBoxDimensions ) || ( customBoxDimensions && b.customBoxDimensions && aRect == bRect && ( ( aY == bY && aRect.x == 0 && aRect.xMax == tileSize.x ) || ( aX == bX && aRect.y == 0 && aRect.yMax == tileSize.y ) ) ) )); }