public abstract class ChunkStreamer : MonoBehaviour
Provides a base implementation for Chunk Streamers. Chunk Streamers should be able
to load objects over several frames and depending on the asset type, in a single frame.
When single frame loading is impossible
(as is the case with some load methods) pre-loading will be used (pre-loading occurs
in one frame, then
the actual single frame load occurs in the next).
In order to accomplish this, the
IsSingleFrameAttachmentPreloadRequired property must be
overridden in the derived class to indicate whether pre-loading is required.
If one or two frame loading is impossible, THAT'S OKAY!. However, you will need to
ensure that 'Initialize On Awake' is disabled on your Component Manager, and manually
initialize the
everything over multiple frames via the InitializeGradually method (also via the Component
Manager).
The Chunk Streamer class is also responsible for unloading asset chunks from the scene
as well! In addition,
you can use a custom Chunk Streamer to load and unload non Game Objects, by creating
a custom Chunk Manager
that makes use of your custom objects. These non game objects can be stored on World
Cells just as Game Objects, however
you will need to ensure that the Chunk Type on your LODs that use these objects are
set to Custom Objects (on your Streamable Grid asset).
Additional Note: This component contains its own special class (ChunkStreamerUser)
which enables multiple
users to use the Chunk Streamer at the same time. The data associated with each user
is stored in
this user object and retrieved using the userID passed into each method. A user can
effectively be thought of as a specific LOD from a
specific Streamable Grid. The utlization of users allows the same streamer to be used
with multiple LODs, so long as these LODs are setup to work
with the settings configured on the streamer.
This user object contains a Cell String, which you are
free to use in your own derived Chunk Streamer component. You can access the user
object and cell string via the
RegisteredUsers property and userID, like so: RegisteredUsers[userID] (accesses the user object)
or RegisteredUsers[userID].CellString.
You may also create your own custom user object class which
derives from ChunkStreamerUser, in order to store custom data or add custom methods.
In fact, this strategy is utilized by some of the other Chunk Streamers in the kit.
Simply override the
CreateNewUser method and return your custom user object.
The properties, methods, and constructors of this ChunkStreamerUser class have been
included on this webpage along side
the other members of the ChunkStreamer class. You can easily identify them as their
member names include a ChunkStreamerrUser prefix. You can
use these as a reference when creating custom ChunkStreamerUser classes.
You should never have to interact directly with this component, as the methods/properties
are called/used
as needed by the Streamable Assets Manager.
Name | Type | Description |
---|---|---|
ChunkStreamerUser.CellString | CellString |
A Cell String object created via the CreateCellString method. |
ChunkStreamerUser.ChunkStreamer | ChunkStreamer |
The ChunkStreamer that created the user object. Think of it as the parent of the object. |
ChunkStreamerUser.LODGroup | ILODGroup |
The ILODGroup info passed in by the user. This contains useful information related to the user. |
ChunkStreamerUser.UserScene |
The scene associated with the user. If the user's World makes use of a Hierarchy Organizer, this will be the scene that the Organizer is in, otherwise it will be the scene that the World component is in. Keep in mind that in most instances, both the Organizer and World will be in the same scene. |
|
CompatibleWithHiearchyOrganizer | bool |
Gets a value indicating whether the Chunk Streamer is compatible with Hiearchy Organizers.
|
ConstantDataToAppend | string |
Normally, the names used to load chunks are constructed using three or four components.
The naming convention assigned to each user
(via Streamable Grid LODs), the Group Name associated with the user, the Streamable
Grid Cell Index of the cell whose chunks/objects are being loaded,
and optionally the chunk index of the chunk being loaded (if multi chunking is being
used). The output name is known as the Cell String, and is
generated using the CellString class.
|
ExtraDataToAppendKey | string |
Normally, the names used to load chunks are constructed using three or four components.
The naming convention assigned to each user
(via Streamable Grid LODs), the Group Name associated with the user, the Streamable
Grid Cell Index of the cell whose chunks/objects are being loaded,
and optionally the chunk index of the chunk being loaded (if multi chunking is being
used). The output name is known as the Cell String, and is
generated using the CellString class.
|
ExtraDataToPrependKey | string |
Normally, the names used to load chunks are constructed using three or four components.
The naming convention assigned to each LOD Group
(via Streamable Grid LODs), the Group Name associated with the LOD Group, the Streamable
Grid Cell Index of the cell whose chunks/objects are being loaded,
and optionally the chunk index of the chunk being loaded (if multi chunking is being
used). The output name is known as the Cell String, and is
generated using the CellString class.
|
IsSingleFrameAttachmentPreloadRequired | bool |
When overridden in derived class, gets a bool value indicating whether the derived
class
requires pre loading in order to execute the PerformSingleFrameAttachmentPreload method
successfully.
|
LoadProgress | float |
Tracks the progress of this Chunk Streamer's current LoadAndAttachChunksToCells method
call as a value between 0 (nothing loading) and 1 (all chunks loaded).
When LoadAndAttachChunksToCells is called, you should set this value to 0f, gradually
incrementing it
as you load a new chunk. At the methods end, it should be set to 1f. This is automatically
done by the built in Chunk Streamer implementations, however
you will need to do this manually if creating a custom Chunk Streamer.
|
RegisteredUsers | RegistrationHandler<ChunkStreamerUser> (protected) |
The users registered with the Chunk Streamer. |
public ChunkStreamerUser(ChunkStreamer streamer, ILODGroup LODGroup)
Creates a new instance of the Chunk Streamer User object. If you are overriding the
ChunkStreamer class and
not overriding the ChunkStreamerUser, you can create a new instance of this user object
via this
constructor, which can be returned in the ChunkStreamer's CreateNewUser method.
If you are overriding ChunkStreamerUser, your custom user class will need constructors
with at least these parameters
(but can also have more), and they must also call the base constructor, which is accomplished
by placing
: (streamer, LODGroup) after your constructor declaration.
Note, this constructor can only be used from a class deriving from ChunkStreamer or
ChunkStreamerUser.
Name | Type | Description |
---|---|---|
LODGroup | ILODGroup |
The LODGroup associated with the user. |
streamer | ChunkStreamer |
The Chunk Streamer that created the instance of the ChunkStreamerUser. |
protected virtual CellString CreateCellString(ILODGroup LODGroup, string extraDataToPrepend, string extraDataToAppend)
The method used to create the CellString object. By default it uses the Group Name from the ILODGroup objet, as well as the Naming Convention, UtilizesCellChunking, and StreamableGrid.IsStreamableGrid3D fields from the GridLODDetails property of the ILODGroup object. You can override to use different information, however do so with extreme caution only if you know what you are doing. The ILODGroup object passed in is the one passed to the ChunkStreamerUser constructor. To use a different group, call this method manually and pass in a different group, then use the returned CellString rather than the one from the CellString property.
Name | Type | Description |
---|---|---|
LODGroup | ILODGroup |
The ILODGroup to use to create the Cell String object. |
extraDataToPrepend | string |
Extra data to prepend to the strings generated with the Cell String. Pass this into your CellString object, and don't worry about whether it is null or blank, as those cases are handled automatically by the CellString. |
extraDataToAppend | string |
Extra data to append to the strings generated with the Cell String. Pass this into your CellString object, and don't worry about whether it is null or blank, as those cases are handled automatically by the CellString. |
CellString
A Cell String object
protected void Awake()
Awake method for all Chunk Streamers. This method is where the background loading
priority is
set, if the Global Runtime Settings asset is configured to set it.
If you need to implement Awake related logic in your custom Chunk Streamers, override
the
AwakeExtended method.
protected virtual void AwakeExtended()
Override to implement Awake related logic in your custom Chunk Streamers.
protected virtual ChunkStreamerUser CreateNewUser(ILODGroup LODGroup)
Method used to create a new user object during user registration. This can and usually should be overridden to return a custom user object. Each user represents a single LODGroup on a single World World Grouping.
Name | Type | Description |
---|---|---|
LODGroup | ILODGroup |
The lod group being registered. |
ChunkStreamerUser
A new user object created using the LODGroup as input.
public void DeRegister(int userID)
A user can call this method to de register with the Chunk Streamer.
Name | Type | Description |
---|---|---|
userID | int |
The ID of the user to de register. |
public abstract IEnumerator<YieldInstruction> DetachAndUnloadChunksFromCells(List<WorldCell> cells, int userID)
When overridden in a derived class, detaches and unloads the objects associated with
the input cells over a period of frames.
Please note that the list of World Cells passed in may need to be used by the calling
method after this method finishes executing; as such,
you should not remove World Cells or otherwise manipulate the list, as that will result
in errors.
Also note that in some instances, the Chunk Set on the World Cell may have been re-used/taken
from another World Cell, so if you need to access some data
related to the chunk set, it is better to use an identifier from the underlying objects
in the chunk set rather than data from the World Cell. This is
especially true because the Endless Grid Cell value on the World Cell may not be accurate,
therefore you should never use it as a key to store data.
Name | Type | Description |
---|---|---|
cells | List<WorldCell> |
The cells whose chunks need to be detached and unloaded. |
userID | int |
The ID of the user requesting the unload and detachment. |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
public abstract IEnumerator<YieldInstruction> LoadAndAttachChunksToCells(List<WorldCell> cells, int userID)
When overridden in a derived class, loads and attaches the chunks associated with
the input
cells to the cells over a period of frames.
If you need to store some data about chunks in order to properly unload them later
using DetachAndUnloadChunksFromCells, you should use a
key related to the underlying chunk objects themselves rather than the World Cell.
This is because the chunks may be passed between
World Cells (if using Chunk Reuse or Pooling), so the World Cell the chunks were originally
loaded for may not be the World Cells
they are attached to when DetachAndUnloadChunksFromCells is called.
Name | Type | Description |
---|---|---|
cells | List<WorldCell> |
The cells whose chunks need to be loaded and attached. |
userID | int |
The ID of the user requesting the load and attachment. |
IEnumerator<YieldInstruction>
An IEnumerator<YieldInstruction> that can be iterated over or used as a coroutine.
See the
YieldInstruction page for more info.
public abstract void LoadAndAttachChunksToCellsInSingleFrame(List<WorldCell> cells, int userID)
When overridden in a derived class, loads and attaches the chunks associated with
the input cells to the cells in a single frame.
If you need to store some data about chunks in order to properly unload them later
using DetachAndUnloadChunksFromCells, you should use a
key related to the underlying chunk objects themselves rather than the World Cell.
This is because the chunks may be passed between
World Cells (if using Chunk Reuse or Pooling), so the World Cell the chunks were originally
loaded for may not be the World Cells
they are attached to when DetachAndUnloadChunksFromCells is called.
Name | Type | Description |
---|---|---|
cells | List<WorldCell> |
The cells whose chunks need to be attached. |
userID | int |
The ID of the user requesting the attachment. |
public virtual void PerformSingleFrameAttachmentPreload(List<WorldCell> cells, int userID)
Certain types of load methods require a frame to pass before objects are added to
the scene
(LoadLevelAdditive for example). In order to successfully execute the
LoadAndAttachChunksToCellsInSingleFrame method,
these load methods must "pre load" the objects in the frame before.
This method is used to do that, but should only be called by the registered user
when IsSingleFrameAttachmentPreloadRequired is true.
By default, this method does nothing, and you only need to provide your own implementation
if pre loading is required (in
which case,
IsSingleFrameAttachmentPreloadRequired
must also be overridden to return true.
If you need to store some data about chunks in order to properly unload them later
using DetachAndUnloadChunksFromCells, you should use a
key related to the underlying chunk objects themselves rather than the World Cell.
This is because the chunks may be passed between
World Cells (if using Chunk Reuse or Pooling), so the World Cell the chunks were originally
loaded for may not be the World Cells
they are attached to when DetachAndUnloadChunksFromCells is called.
Name | Type | Description |
---|---|---|
cells | List<WorldCell> |
The cells whose objects need to be pre loaded. |
userID | int |
The ID of the user requesting the pre load. |
public void Register(ILODGroup LODGroup, out int userID)
A user can call this method to register with the Chunk Streamer. The userID must be stored by the user and passed in when calling the methods of the Chunk Streamer.
Name | Type | Description |
---|---|---|
LODGroup | ILODGroup |
The lod group being registered. |
userID | int |
An ID that is assigned to the user when this method is called. Each user has its own ChunkStreamerUser object created for it. |