![]() |
TilePlus Version 5
Unity3D Tilemap Extension
|
Some static utility methods for tile math. More...
Public Types | |
| enum | DirectionType4 { None , Up , Right , Down , Left } |
| Direction of movement, swipe direction, etc. This is for a 4-way direction type: up,right,down,left. More... | |
| enum | DirectionType8 { None , Up , RightUp , Right , RightDown , Down , LeftDown , Left , LeftUp } |
| Direction of movement, swipe direction, etc. This is for a 8-way direction type: up,up-right,right,right-down,down,left-down,left.left-up. More... | |
Static Public Member Functions | |
| static Matrix4x4 | RotatationMatixZ (float angle) |
| Get a Matrix4x4 for an angle. | |
| static Matrix4x4 | ScaleMatrix (Vector3 scale, Vector3 position) |
| Get a Matrix4x4 for scaling. | |
| static Vector3 | RoundVector3 (Vector3 input, int digits) |
| Round an input Vector3 to n digits. | |
| static void | GetTransformComponents (Tilemap map, Vector3Int position, out Vector3 tPosition, out Vector3 tRotation, out Vector3 tScale) |
| Get the transform components for a tile. Convenience Function. | |
| static void | GetTransformComponents (Matrix4x4 transform, out Vector3 tPosition, out Vector3 tRotation, out Vector3 tScale) |
| Get the transform components for a tile from its transform (not the same as a GameObj Transform!). Convenience Function. | |
| static Vector3 | GetTransformRotation (Tilemap map, Vector3Int position) |
| Get the rotation of a tile's sprite. | |
| static Vector3 | GetTransformPosition (Tilemap map, Vector3Int position) |
| Get the position of a tile's sprite. | |
| static Vector3 | GetTransformScale (Tilemap map, Vector3Int position) |
| Get the scale of a tile's sprite. | |
| static Matrix4x4 | SetTransform (Tilemap map, Vector3Int position, Vector3 tPosition, Vector3 tRotation, Vector3 tScale) |
| Set the transform for a tile. Convenience function. | |
| static Matrix4x4 | MakeMatrix2D (Vector3 position, Vector3 rotation, Vector3 scale) |
| Convience function to create Matrix 4x4 from position, rotation (Z only), scale, but optimized for tile sprites which don't support Z for position and scale. | |
| static Vector3 | GetTileSpriteRotation (TilePlusBase tpb) |
| Get a Tile sprite rotation. | |
| static void | SetTileSpriteRotation (TilePlusBase tpb, Vector3 value, bool constantScaleAndPosition=true) |
| Set a Tile sprite rotation. | |
| static Vector3 | GetTileSpritePosition (TilePlusBase tpb) |
| Get a Tile sprite position. | |
| static void | SetTileSpritePosition (TilePlusBase tpb, Vector3 value, bool constantRotationAndScale=true) |
| Set a Tile sprite position. | |
| static Color | GetTileSpriteColor (TilePlusBase tpb) |
| Get a Tile sprite Color. | |
| static void | SetTileSpriteColor (TilePlusBase tpb, Color value) |
| Set a Tile sprite color. | |
| static Vector3 | GetTileSpriteScale (TilePlusBase tpb) |
| Get a Tile sprite scale. | |
| static void | SetTileSpriteScale (TilePlusBase tpb, Vector3 value, bool constantPositionAndRotation=true) |
| Set a Tile sprite scale. | |
| static BoundsInt | CreateBoundsInt (Vector3Int position, Vector3Int size, bool forceZto1=true) |
| Create a BoundsInt given a center position and a size. | |
| static BoundsInt | BoundsIntFromBounds (Bounds bounds, bool ceiling=true) |
| Create BoundsInt from Bounds. Use ceiling or floor. | |
| static Vector3 | RandomPosInBounds (Bounds bounds) |
| Get a random world position within bounds. | |
| static Bounds | BoundsFromOrthoCamera (Camera? camera, bool square=true, float scale=1f, bool zeroZ=true) |
| Get a bounds representing the Camera's viewport. | |
| static BoundsInt | LargestBoundsInt (IEnumerable< BoundsInt > input) |
| Get the largest BoundsInt from a list of BoundsInts. | |
| static DirectionType4 | NextDirectionType4 (DirectionType4 d) |
| clockwide direction movement for four directions | |
| static Vector3Int[] | Get4WayAdjacent (Vector3Int center) |
| Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in a 4-way coordinate space. In the same order as DirectionType4 (except for None: Up/Right/Down/Left) | |
| static void | Get4WayAdjacentHashSet (Vector3Int center, HashSet< Vector3Int >? hashSet, bool clear=true) |
| Get an HashSet of Vector3Int objects with row/col coords adjacent to the provided centerpoint in a 4-way coordinate space. | |
| static DirectionType4 | Get4WayRandomDirection () |
| Get a random direction in a 4-way coordinate space. | |
| static void | Get4WayPerpendicular (Vector3Int center, DirectionType4 dir, Vector3Int[]? output) |
| Get the two locations next to the current location in a perpendicular orientation eg if dir == down or up then the two locations to the right and left of the 'center' are provided. Note: 4 way coordinate space. | |
| static Vector3Int | Get4WayNextInOppositeDir (Vector3Int position, DirectionType4 dir) |
| Get the grid position that's 'get next in opposite direction' in a 4-way coordinate space. | |
| static DirectionType4 | Get4WayOppositeDirectionType (DirectionType4 dir) |
| Get the DirectionType4 that's opposite from the input in a 4-way coordinate space. | |
| static Vector3Int | Get4WayAdjacent (Vector3Int position, DirectionType4 dir) |
| Get adjacent position to input position. Or "get next in same direction" in a 4-way coordinate space. | |
| static DirectionType8 | NextDirectionType8 (DirectionType8 d) |
| clockwide direction movement for 8 direction coordinate space. | |
| static Vector3Int | Get8WayAdjacent (Vector3Int position, DirectionType8 dir) |
| Get a Vector3Int with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space. | |
| static Vector3Int[] | Get8WayAdjacent (Vector3Int center) |
| Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space. Same order as DirectionType8. | |
| static HashSet< Vector3Int > | Get8WayAdjacentHashSet (Vector3Int center) |
| Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space. | |
| static DirectionType8 | GetRandomDirection () |
| Get a random direction. | |
| static void | DeleteTilesFromPositionList (Tilemap map, Vector3Int[] positions) |
| Helper: Delete all tiles from a list/array of positions. | |
| static void | DeleteTilesFromPositionList (Tilemap map, IEnumerable< Vector3Int > positions) |
| Helper: Delete all tiles from an IEnumerable of positions. | |
| static void | DeleteTilePlusBaseBlock (Tilemap map, IEnumerable< TilePlusBase > tiles) |
| Helper: Delete a block of TilePlus tiles. | |
| static float | GetOneShotTimeOut (int numSpritesInAnimation, float animationSpeed, Tilemap? map) |
| [DEPRECATED in V5] Get a timeout for rewinding a one-shot animation when it completes | |
| static Bounds | GetTrueBoundsForTileSprite (Tilemap? map, Vector3Int position) |
| Get the true bounds for a Tile's sprite. Takes into account transform scaling. | |
| static Vector2Int | GetTileSpriteIntegerSize (Tilemap map, Vector3Int position) |
| Get a Vector2Int with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale. | |
| static Vector2 | GetTileSpriteSize (Tilemap map, Vector3Int position) |
| Get a Vector2 with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale. | |
| static Vector2 | GetTileSpriteSize (TilePlusBase tpb) |
| Get a Vector2 with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale. Convenience overload. | |
| static RectInt | GridPositionsSurrounding (Vector3Int gridPosition) |
| Get a RectInt of size 3x3 with the passed gridPostion as the center. | |
| static RectInt | RectIntFromBoundsInt (BoundsInt boundsInt, Vector3Int offset) |
| Create a RectInt from a BoundsInt. Ignores the BoundsInt Position. | |
| static bool | SwapTiles (TilePlusBase a, TilePlusBase b, bool tween=false, TpTweenSpec.Tween? tweenSpec=null, float tweenDuration=0.25f, TpEasingFunction.Ease easeFunction=TpEasingFunction.Ease.Linear, bool debug=false) |
| Swap two TilePlus tiles. Optional tweening. | |
Some static utility methods for tile math.
|
static |
Get a bounds representing the Camera's viewport.
| camera | a Camera |
| square | Normally TRUE, for use with chunking/layout system. ALWAYS returns a square bounds. |
| scale | Scale the bounds if square is FALSE. Not used when square=true. |
| zeroZ | If square is FALSE and zeroZ is TRUE then the bounds center Z is forced to zero. Default=true. |
|
static |
Create BoundsInt from Bounds. Use ceiling or floor.
| bounds | A Bounds |
| ceiling | true to use ceiling (round up) or false to use floor (round down) if needed |
Designed for showing positionDb surface: may not work well for other uses.
|
static |
Create a BoundsInt given a center position and a size.
| position | position @ CENTER |
| size | size |
| forceZto1 | default true: force size.z to 1 |
|
static |
Helper: Delete a block of TilePlus tiles.
| map | Tilemap to affect |
| tiles | Ienumerable of TilePlusBase |
For TilepLus tiles only.
|
static |
Helper: Delete all tiles from an IEnumerable of positions.
| map | tilemap |
| positions | position array |
For any type of tile
|
static |
Helper: Delete all tiles from a list/array of positions.
| map | tilemap |
| positions | position array |
For any type of tile
|
static |
Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in a 4-way coordinate space. In the same order as DirectionType4 (except for None: Up/Right/Down/Left)
| center | Centerpoint |
|
static |
Get adjacent position to input position. Or "get next in same direction" in a 4-way coordinate space.
| position | input grid position |
| dir | direction to consider |
|
static |
Get an HashSet of Vector3Int objects with row/col coords adjacent to the provided centerpoint in a 4-way coordinate space.
| center | Centerpoint |
| hashSet | HashSet for returned values. order is up,down,right,left |
| clear | clear hashset. Default=true |
due to copying of 'center', allocs about 80 bytes
|
static |
Get the grid position that's 'get next in opposite direction' in a 4-way coordinate space.
| position | A grid position |
| dir | Direction to consider |
|
static |
Get the DirectionType4 that's opposite from the input in a 4-way coordinate space.
| dir | Input DirectionType4 |
|
static |
Get the two locations next to the current location in a perpendicular orientation eg if dir == down or up then the two locations to the right and left of the 'center' are provided. Note: 4 way coordinate space.
| center | Target |
| dir | direction |
| output | to Vector3Int[2] |
If the length of output is LT 2 then an indexing exception error will be thrown. Declare a private var to avoid allocations.
|
static |
Get a random direction in a 4-way coordinate space.
|
static |
Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space. Same order as DirectionType8.
| center | Centerpoint |
|
static |
Get a Vector3Int with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space.
| position | Origin |
| dir | A value from the DirectionType8 enum |
|
static |
Get an array of Vector3Int objects with row/col coords adjacent to the provided centerpoint in an 8-way coordinate space.
| center | Centerpoint |
|
static |
[DEPRECATED in V5] Get a timeout for rewinding a one-shot animation when it completes
| numSpritesInAnimation | Number of sprites being animated |
| animationSpeed | The animation speed we want to use |
| map | The parent Tilemap: used to get the Tilemap's animation speed |
|
static |
Get a random direction.
|
static |
Get a Tile sprite Color.
| tpb | tile instance |
|
static |
Get a Vector2Int with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale.
| map | Tilemap |
| position | position |
|
static |
Get a Tile sprite position.
| tpb | tile instance |
|
static |
Get a Tile sprite rotation.
| tpb | tile instance |
|
static |
Get a Tile sprite scale.
| tpb | tile instance |
|
static |
Get a Vector2 with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale.
| map | Tilemap |
| position | position |
|
static |
Get a Vector2 with the TRUE size of a tile's sprite; ie, including any effect of the tile's transform scale. Convenience overload.
| tpb | TilePlusBase instance |
|
static |
Get the transform components for a tile from its transform (not the same as a GameObj Transform!). Convenience Function.
| transform | a Tilemap sprite transform. |
| tPosition | transform's position placed here |
| tRotation | transform's rotation placed here |
| tScale | transform's scale placed here |
Handy for tweening the transform (pos,scale,rot) of a tile
No checking for whether or not a tile exists at that position
|
static |
Get the transform components for a tile. Convenience Function.
| map | Tilemap |
| position | position on map |
| tPosition | transform's position placed here |
| tRotation | transform's rotation placed here |
| tScale | transform's scale placed here |
Handy for tweening the transform (pos,scale,rot) of a tile
No checking for whether or not a tile exists at that position
|
static |
Get the position of a tile's sprite.
| map | the tilemap |
| position | position of tile |
|
static |
Get the rotation of a tile's sprite.
| map | The tilemap |
| position | the position of the tile |
|
static |
Get the scale of a tile's sprite.
| map | the tilemap |
| position | position of tile |
|
static |
Get the true bounds for a Tile's sprite. Takes into account transform scaling.
| map | Source tilemap |
| position | position |
|
static |
Get a RectInt of size 3x3 with the passed gridPostion as the center.
| gridPosition | Center for returned RectInt |
|
static |
Get the largest BoundsInt from a list of BoundsInts.
|
static |
Convience function to create Matrix 4x4 from position, rotation (Z only), scale, but optimized for tile sprites which don't support Z for position and scale.
| position | position (X and Y only, Z forced to zero) |
| rotation | rotation (Z only) |
| scale | scale(x and Y only, Z forced to 1) |
|
static |
clockwide direction movement for four directions
| d | a direction type enum value |
up->right, right->down, down->left, left->up
If d == DirectionType4.None then the value of d is returned.
|
static |
clockwide direction movement for 8 direction coordinate space.
| d | a direction type 8 enum value |
If d == DirectionType8.None then the value of d is returned.
|
static |
Get a random world position within bounds.
| bounds | a bounds |
|
static |
Create a RectInt from a BoundsInt. Ignores the BoundsInt Position.
| boundsInt | Input BoundsInt |
| offset | This is added to the boundsInt's offset. Useful as an offset from that position: e.g., a tile's offset. If not needed just use Vector3Int.zero |
Normally this is intended for use when processing a tile's ZoneBoundsInt when a zone is being used. In these cases, you always want to offset the ZoneBoundInt's position with the tile's position so that the resultant RectInt returned from this position is positioned properly relative to the tile.
|
static |
Get a Matrix4x4 for an angle.
| angle | The angle. |
|
static |
Round an input Vector3 to n digits.
| input | value to round |
| digits | number of digits of precision |
|
static |
Get a Matrix4x4 for scaling.
| scale | scale |
| position | position |
|
static |
Set a Tile sprite color.
|
static |
Set a Tile sprite position.
| tpb | tile instance |
| value | new position |
| constantRotationAndScale | Default = true. Keep existing rotation and scale |
|
static |
Set a Tile sprite rotation.
| tpb | tile instance |
| value | rotation value |
| constantScaleAndPosition | default = true. Don't change scale and position |
|
static |
Set a Tile sprite scale.
| tpb | tile instance |
| value | new scale |
| constantPositionAndRotation | default=true. Keep existing position and rotation. |
|
static |
Set the transform for a tile. Convenience function.
| map | tilemap |
| position | position on map |
| tPosition | position for the tile transform |
| tRotation | rotation for the tile transform |
| tScale | scale for the tile transform |
Handy for tweening the transform (pos,scale,rot) of a tile's sprite
No checking for whether or not a tile exists at that position
|
static |
Swap two TilePlus tiles. Optional tweening.
| a | TPT Tile A |
| b | TPT Tile B |
| tween | do a tween if true |
| tweenSpec | Optional TweenSpec.Tween. If not null then tweenDuration and easeFunction IGNORED. |
| tweenDuration | if tweening, the duration |
| easeFunction | if tweening, the ease function. |
| debug | set true for debug info -> console. |
Fails if the tiles' parent Tilemaps are not the same