TilePlus Version 5
Unity3D Tilemap Extension
Loading...
Searching...
No Matches
TilePlus.TpZoneManager Class Reference

TpZoneManager is used to manage square areas of tilemaps called Zones. More...

Inheritance diagram for TilePlus.TpZoneManager:
Collaboration diagram for TilePlus.TpZoneManager:

Public Member Functions

void ResetInstance (bool resetEvents=true)
 Reset all registrations, reset registrationIndex.
bool AddRegistration (ZoneReg reg, AssetGuidPositionHash hash)
 Add a registration. Only use if you're not using AddZone and creating your own ZoneRegs.
bool HasZone (ZoneReg reg)
 Is there a registration for this ZoneReg?
bool UnloadZones (List< ZoneReg > regs, bool destroyTiles=true, bool destroyPrefabs=true)
 Unload a list of Zones.
async Awaitable< bool > UnloadZonesAsync (List< ZoneReg > regs, bool destroyTiles=true, bool destroyPrefabs=true)
 Unload a list of Zones, Async Does one reg per frame.
bool UnloadAllZones ()
 Unload ALL zones, including all parented prefabs.
bool UnloadZone (ZoneReg? reg, bool destroyTiles=true, bool destroyPrefabs=true)
 Unload a chunk.
void Initialize (int size, Vector3Int? origin=null, int initialMaxNumChunks=64)
 Required if you want to use chunking. No chunking data is accumulated and chunking will not work if this isn't used. Note that you should use this again for every new scene. WIPES OUT ANY EXISTING TILEFAB REGISTRATION DATA WHEN USED!!
List< ZoneRegGetZoneRegsForRegion (RectInt? locator)
 Get the ZoneRegs for a Zone locator RectInt.
bool FindRegionalZoneRegs (RectInt? locator, ref HashSet< RectInt > inside, ref List< ZoneReg > outside)
 Obtain two datasets: one is a List of ZoneRegs that are outside of an area and another is a HashSet of ZoneRegs that are inside the area.
List< ZoneRegGetZoneRegsForGridPosition (Vector3Int gridPosition, Vector2Int? dimensions=null, bool align=true)
 Get the ZoneRegs for a chunk located at a Grid position.
List< ZoneRegGetZoneRegsForWorldPosition (Vector3 worldPosition, Tilemap? map, Vector2Int? dimensions=null, bool align=true)
 Get the Zone registration for a chunk located at a World position.
RectInt GetLocatorForGridPosition (Vector3Int gridPosition, Vector2Int ?dimensions=null, bool align=true)
 Create an Zone registration locator from a grid position.
RectInt GetLocatorForWorldPosition (Vector3 position, Tilemap? map, Vector2Int? dimensions=null, bool align=true)
 Create an Zone registration locator from a world position.
bool HasZoneRegForLocator (RectInt locator)
 Is there a Zone registration associated with a RectInt locator?
bool GetZoneRegForLocator (RectInt locator, out ZoneReg? reg)
 Get a Zone Reg for a locator RectInt.
RectInt GetLocatorForSgridPosition (Vector2Int sGridPosition, Vector2Int? dimensions=null)
 Convert a super-grid position to a locator.
Vector3Int GetGridPositionForSgridPosition (Vector2Int sGridPosition)
 Get a Tilemap grid position from a sGrid position.
string GetZoneRegJson (bool prettyPrint=true)
 Get a JSON version of the Zone registrations.
List< TilefabLoadResults >? RestoreFromZoneRegJson (string jsonString, Dictionary< string, Tilemap >? targetMap=null, Func< FabOrBundleFilterType, BoundsInt, object, bool >? filter=null, bool filterOnlyTilePlusTiles=true)
 Restore all Tilefabs or Bundles based on a json-archived dataset.
bool DeleteZoneRegistration (ZoneReg reg)
 Remove an Zone registration given an instance of one.
IEnumerable< ZoneRegGetLastRegistrations (int numResults=1)
 Get the last N Zone registrations.
ZoneRegGetLastRegistration ()
 Get the very last Zone Reg. Handy when you know there is only one.
IEnumerable< ZoneRegGetAllZoneRegistrationsFiltered (bool orderByIndex=false, Func< ZoneReg, bool >? filter=null)
 Get all zone registrations with optional filtering and ordering.
bool IsAlignedToGrid (Vector3Int position)
 Is this grid position aligned to the super-grid?
Vector3Int AlignToGrid (Vector3Int position)
 Align a position to the super-grid. Note: positions are aligned to the lower-left corner of a rectint.

Properties

IEnumerable< ZoneRegGetAllZoneRegistrations [get]
 Get the all loading results.
bool ChunkingConfigured [get]
 Is chunking configured?
int ChunkSize [get]
 Size of a chunk as set during initialization.
int NumChunksInUse [get]
 The number of chunks in the chunkmap.
Dictionary< string, Tilemap >.ValueCollection MonitoredTilemaps [get]
 Get a collection of the MonitoredTilemaps dictionary values: Tilemap instances. These are the only ones that clients of this instance should be using.
Dictionary< string, Tilemap > MonitoredTilemapDict [get]
 Access to the Monitored Tilemaps for this instance. DO NOT ALTER THIS DICTIONARY. DON'T SAVE A REFERENCE.
RectInt DefaultLocator [get]
 Get the default locator. This is the value used when you don't specify a dimensions value when GetZoneReg or GetLocator with dimensions = null.
Vector2Int WorldOrigin [get]
 Get the ChunkMapAnchorPosition. This is the base or startingPosition from where all Chunks begin. You can find the center of a chunk by adding multiples of ChunkMapAnchorSize to ChunkMapAnchorPosition.
string InstanceName [get]
 The name of this instance. Read only.
TpZoneLayoutZoneLayoutComponent [get, set]
 A ref to the ZoneLayout, if used with chunking system. Null otherwise.

Events

Action< ZoneReg, TpZoneManager >? OnZoneRegAdded
 Notify me when a Zone Reg is added.
Action< ZoneReg, TpZoneManager >? OnZoneRegDeleted
 Notify me when a Zone Reg is deleted.
Action< Tilemap, List< TilePlusBase > >? OnTptTilesWillBeDeleted
 Notify me that a list of TPT tiles will be deleted.

Detailed Description

TpZoneManager is used to manage square areas of tilemaps called Zones.

Member Function Documentation

◆ AddRegistration()

bool TilePlus.TpZoneManager.AddRegistration ( ZoneReg reg,
AssetGuidPositionHash hash )

Add a registration. Only use if you're not using AddZone and creating your own ZoneRegs.

Parameters
regThe ZoneReg
hashAn AssetGuidPositionHash instance
Returns
false for failure: means that there was an entry already existing for this locator.

◆ AlignToGrid()

Vector3Int TilePlus.TpZoneManager.AlignToGrid ( Vector3Int position)

Align a position to the super-grid. Note: positions are aligned to the lower-left corner of a rectint.

Parameters
positionposition to adjust
Returns
Adjusted position. Won't change if already aligned.

◆ DeleteZoneRegistration()

bool TilePlus.TpZoneManager.DeleteZoneRegistration ( ZoneReg reg)

Remove an Zone registration given an instance of one.

Parameters
regZoneReg instance
Returns
true if found

◆ FindRegionalZoneRegs()

bool TilePlus.TpZoneManager.FindRegionalZoneRegs ( RectInt? locator,
ref HashSet< RectInt > inside,
ref List< ZoneReg > outside )

Obtain two datasets: one is a List of ZoneRegs that are outside of an area and another is a HashSet of ZoneRegs that are inside the area.

Parameters
locatorthe RectInt Locator describing the area.
insideref HashSet for inside
outsideref List for outside
Returns
false if any error occurs

◆ GetAllZoneRegistrationsFiltered()

IEnumerable< ZoneReg > TilePlus.TpZoneManager.GetAllZoneRegistrationsFiltered ( bool orderByIndex = false,
Func< ZoneReg, bool >? filter = null )

Get all zone registrations with optional filtering and ordering.

Parameters
orderByIndexorder by ZoneReg index if true
filterFunc of ZoneReg returning bool. If ret val true then zm returned else it is skipped.
Returns
IEnumerable of ZoneReg instances. DON'T HOLD REFERENCES TO THESE!!! will make a memory leak.

◆ GetGridPositionForSgridPosition()

Vector3Int TilePlus.TpZoneManager.GetGridPositionForSgridPosition ( Vector2Int sGridPosition)

Get a Tilemap grid position from a sGrid position.

Parameters
sGridPositiona sGrid position
Returns
a Tilemap grid position

◆ GetLastRegistration()

ZoneReg? TilePlus.TpZoneManager.GetLastRegistration ( )

Get the very last Zone Reg. Handy when you know there is only one.

Returns
the last zone reg used or a new one (index will be 0) if there aren't any regs in the ChunkMap for this ZM.

◆ GetLastRegistrations()

IEnumerable< ZoneReg > TilePlus.TpZoneManager.GetLastRegistrations ( int numResults = 1)

Get the last N Zone registrations.

Parameters
numResults# of results desired. For a tilefab that should be 1
Returns
Enumerable of registrations, which could be empty.

◆ GetLocatorForGridPosition()

RectInt TilePlus.TpZoneManager.GetLocatorForGridPosition ( Vector3Int gridPosition,
Vector2Int ? dimensions = null,
bool align = true )

Create an Zone registration locator from a grid position.

Parameters
gridPositionposition on a Tilemap
dimensions[Nullable] optional size of locator. If null, ChunkMapAnchorPosition as set by Initialize
alignAlign to grid. Default=true
Returns
RectInt Zone registration locator

◆ GetLocatorForSgridPosition()

RectInt TilePlus.TpZoneManager.GetLocatorForSgridPosition ( Vector2Int sGridPosition,
Vector2Int? dimensions = null )

Convert a super-grid position to a locator.

Parameters
sGridPositions sGrid postion
dimensionsdimensions of locator or null for default
Returns
a Locator.

◆ GetLocatorForWorldPosition()

RectInt TilePlus.TpZoneManager.GetLocatorForWorldPosition ( Vector3 position,
Tilemap? map,
Vector2Int? dimensions = null,
bool align = true )

Create an Zone registration locator from a world position.

Parameters
positionworld position
mapTilemap to use for translating world to grid positions. If null, new RectInt() is returned.
dimensions[Nullable] optional size of locator. If null, ChunkMapAnchorPosition as set by Initialize
alignAlign to grid. Default=true
Returns
RectInt Zone registration locator

◆ GetZoneRegForLocator()

bool TilePlus.TpZoneManager.GetZoneRegForLocator ( RectInt locator,
out ZoneReg? reg )

Get a Zone Reg for a locator RectInt.

Parameters
locatora locator
rega registration
Returns
true if reg was found. Note: if false the reg is default

◆ GetZoneRegJson()

string TilePlus.TpZoneManager.GetZoneRegJson ( bool prettyPrint = true)

Get a JSON version of the Zone registrations.

Parameters
prettyPrint
Returns

◆ GetZoneRegsForGridPosition()

List< ZoneReg > TilePlus.TpZoneManager.GetZoneRegsForGridPosition ( Vector3Int gridPosition,
Vector2Int? dimensions = null,
bool align = true )

Get the ZoneRegs for a chunk located at a Grid position.

Parameters
gridPositionThe position to use when searching for Zone registrations
dimensions[Nullable] if not null, this is the search area. If null, ChunkMapAnchorPosition as set by Initialize
alignAlign to grid. Default=true
Returns
a list of ZoneRegs. Empty list is valid and means error or nothing found.

◆ GetZoneRegsForRegion()

List< ZoneReg > TilePlus.TpZoneManager.GetZoneRegsForRegion ( RectInt? locator)

Get the ZoneRegs for a Zone locator RectInt.

Parameters
locatorthe RectInt chunk locator
Returns
ZoneReg List, list is Empty for error

return empty list if chunking not enabled or chunklocator is null. Note that the same list is cleared and re-used every time that this is called.

◆ GetZoneRegsForWorldPosition()

List< ZoneReg > TilePlus.TpZoneManager.GetZoneRegsForWorldPosition ( Vector3 worldPosition,
Tilemap? map,
Vector2Int? dimensions = null,
bool align = true )

Get the Zone registration for a chunk located at a World position.

Parameters
worldPositionThe position to use when searching for Zone registrations
mapTilemap to use for translating world to grid positions. If null, an empty list is returned.
dimensions[Nullable] if not null, this is the search area. If null, ChunkMapAnchorPosition as set by Initialize
alignAlign to grid. Default=true
Returns
a list of ZoneRegs. Empty list is valid and means error or nothing found.

◆ HasZone()

bool TilePlus.TpZoneManager.HasZone ( ZoneReg reg)

Is there a registration for this ZoneReg?

Parameters
regA ZoneReg
Returns

◆ HasZoneRegForLocator()

bool TilePlus.TpZoneManager.HasZoneRegForLocator ( RectInt locator)

Is there a Zone registration associated with a RectInt locator?

Parameters
locatorthe RectInt to check
Returns
true if there's already a locator there.

◆ Initialize()

void TilePlus.TpZoneManager.Initialize ( int size,
Vector3Int? origin = null,
int initialMaxNumChunks = 64 )

Required if you want to use chunking. No chunking data is accumulated and chunking will not work if this isn't used. Note that you should use this again for every new scene. WIPES OUT ANY EXISTING TILEFAB REGISTRATION DATA WHEN USED!!

Parameters
sizeSize of a chunk. Must be even, rounded up if not. Min=4. 4x4, 6x6, 8x8 ... 16x16 chunks etc
originThe origin position, the base position, such as Vector3Int.zero, where the chunk numbers should be centered. If null then Vector3Int.zero is used.
initialMaxNumChunkssets certain data structures' initial size. Base this on the total number of chunks of 'size' that would be in your camera's FOV at one time (for example). There's no problem if the max num chunks is exceeded, this just allocates memory early on given your best estimate of what's required as set in this method.

◆ IsAlignedToGrid()

bool TilePlus.TpZoneManager.IsAlignedToGrid ( Vector3Int position)

Is this grid position aligned to the super-grid?

Parameters
positionposition to test
Returns
true if aligned

◆ ResetInstance()

void TilePlus.TpZoneManager.ResetInstance ( bool resetEvents = true)

Reset all registrations, reset registrationIndex.

Parameters
resetEventsReset event descriptions (default=true)

◆ RestoreFromZoneRegJson()

List< TilefabLoadResults >? TilePlus.TpZoneManager.RestoreFromZoneRegJson ( string jsonString,
Dictionary< string, Tilemap >? targetMap = null,
Func< FabOrBundleFilterType, BoundsInt, object, bool >? filter = null,
bool filterOnlyTilePlusTiles = true )

Restore all Tilefabs or Bundles based on a json-archived dataset.

Parameters
jsonStringdata string to decode
targetMapoptional mapping from tilemap name to Tilemap instance. Speeds tilemap lookups greatly
filtera Func of [(enum)FilterDataSource, object] returning a bool. See also LoadTileFab.
filterOnlyTilePlusTilesif true (default) only applies filters to TilePLus tiles, which is usually sufficient and saves much time.
Returns
A list of the TilefabLoadResults from however many Bundles are in the TileFab. Null is returned for errors

The list of TilefabLoadResults is cleared the next time that this method is used.

◆ UnloadAllZones()

bool TilePlus.TpZoneManager.UnloadAllZones ( )

Unload ALL zones, including all parented prefabs.

Returns

◆ UnloadZone()

bool TilePlus.TpZoneManager.UnloadZone ( ZoneReg? reg,
bool destroyTiles = true,
bool destroyPrefabs = true )

Unload a chunk.

Parameters
regcorresponding ZoneReg for the chunk you want to delete.
destroyTilesdestroy tiles if true (default)
destroyPrefabsdestroy prefabs if true (default)
Returns
true if successful.

runtime use ONLY

◆ UnloadZones()

bool TilePlus.TpZoneManager.UnloadZones ( List< ZoneReg > regs,
bool destroyTiles = true,
bool destroyPrefabs = true )

Unload a list of Zones.

Parameters
regsList of ZoneRegs to delete
destroyTilesdestroy tiles (default)
destroyPrefabsdestroy prefabs (default)
Returns
false if failed

◆ UnloadZonesAsync()

async Awaitable< bool > TilePlus.TpZoneManager.UnloadZonesAsync ( List< ZoneReg > regs,
bool destroyTiles = true,
bool destroyPrefabs = true )

Unload a list of Zones, Async Does one reg per frame.

Parameters
regsList of ZoneRegs to delete
destroyTilesdestroy tiles (default)
destroyPrefabsdestroy prefabs (default)
Returns
false if failed

Property Documentation

◆ ChunkingConfigured

bool TilePlus.TpZoneManager.ChunkingConfigured
get

Is chunking configured?

◆ ChunkSize

int TilePlus.TpZoneManager.ChunkSize
get

Size of a chunk as set during initialization.

◆ DefaultLocator

RectInt TilePlus.TpZoneManager.DefaultLocator
get

Get the default locator. This is the value used when you don't specify a dimensions value when GetZoneReg or GetLocator with dimensions = null.

◆ GetAllZoneRegistrations

IEnumerable<ZoneReg> TilePlus.TpZoneManager.GetAllZoneRegistrations
get

Get the all loading results.

◆ InstanceName

string TilePlus.TpZoneManager.InstanceName
get

The name of this instance. Read only.

◆ MonitoredTilemapDict

Dictionary<string, Tilemap> TilePlus.TpZoneManager.MonitoredTilemapDict
get

Access to the Monitored Tilemaps for this instance. DO NOT ALTER THIS DICTIONARY. DON'T SAVE A REFERENCE.

◆ MonitoredTilemaps

Dictionary<string, Tilemap>.ValueCollection TilePlus.TpZoneManager.MonitoredTilemaps
get

Get a collection of the MonitoredTilemaps dictionary values: Tilemap instances. These are the only ones that clients of this instance should be using.

◆ NumChunksInUse

int TilePlus.TpZoneManager.NumChunksInUse
get

The number of chunks in the chunkmap.

◆ WorldOrigin

Vector2Int TilePlus.TpZoneManager.WorldOrigin
get

Get the ChunkMapAnchorPosition. This is the base or startingPosition from where all Chunks begin. You can find the center of a chunk by adding multiples of ChunkMapAnchorSize to ChunkMapAnchorPosition.

◆ ZoneLayoutComponent

TpZoneLayout? TilePlus.TpZoneManager.ZoneLayoutComponent
getset

A ref to the ZoneLayout, if used with chunking system. Null otherwise.

Event Documentation

◆ OnTptTilesWillBeDeleted

Action<Tilemap,List<TilePlusBase> >? TilePlus.TpZoneManager.OnTptTilesWillBeDeleted

Notify me that a list of TPT tiles will be deleted.

Be aware that when the ZoneManager instance is deleted this subscription expires

◆ OnZoneRegAdded

Action<ZoneReg, TpZoneManager>? TilePlus.TpZoneManager.OnZoneRegAdded

Notify me when a Zone Reg is added.

Be aware that when the ZoneManager instance is deleted this subscription expires

◆ OnZoneRegDeleted

Action<ZoneReg,TpZoneManager>? TilePlus.TpZoneManager.OnZoneRegDeleted

Notify me when a Zone Reg is deleted.

Be aware that when the ZoneManager instance is deleted this subscription expires


The documentation for this class was generated from the following file:
  • /Users/jms/Documents/Tpt_55/TPT55/Assets/Plugins/TilePlus/Runtime/FabAndZone/ScriptableObjects/TpZoneManager.cs