Skip to main content

Useful Methods, Camera Projection, Notes

The GetLocator methods allow you to also pass in a Vector2Int dimensions parameter. This lets you create arbitrary-sized Locators. Normally, Locators are the size of a chunk. If you do not pass-in dimensions, that’s the size that’s used. Using a different dimensions value allows you to size a Locator however you want.

Why do that? Let’s say you want to find out which Zones are inside a Camera Viewport, and which are outside. The Viewport is (usually) bigger than a single chunk. Passing in the dimensions of the Viewport creates a Viewport-sized locator. That’s handy for use with GetZoneRegsForRegion and FindRegionalZoneRegs.

GetZoneRegsForRegion takes a Locator for input and returns a list of all the ZoneRegs within the Locator.

FindRegionalZoneRegs takes a Locator for input and populates a HashSet with all the individual Locators within the input Locator and populates a List with all the individual ZoneRegistration instances found outside the input Locator. This is a specialized method that’s used by another component called a ZoneLayout, we’ll discuss that in a later section.

To get individual ZoneRegistrations, use these instance methods:

  • GetZoneRegsForGridPosition
  • GetZoneRegsForWorldPosition
  • HasZoneRegForLocator
  • GetZoneRegForLocator

Camera Projection

A ZM is agnostic to the camera’s projection mode. However, there’s a big difference in how one calculates the viewport bounds for the two types of cameras. This matters for ZM clients such as TpZoneLayout, which only supports Orthographic cameras.

Multiple ZoneManagers

You can have as many as you want. Note the warning about sharing the same Tilemap with different ZMs. Don’t do it. Besides that, ZMs are independent, and can have different chunk sizes, world origins, and so on.

Scene Loading and Unloading

In general, you are responsible for deleting ZMs when a scene that they are in is destroyed. An example of how that’s done can be seen in the TpZoneLayout component’s OnDisable event handler, which handles this for you.