Custom Destroyers are useful if your Asset Chunks have deep hierarchies, as you can control the order and quanity of game objects destroyed. This is most especially useful when there are a great many child/grandchild objects on each root Asset Chunk, as generally you will want to limit the number of them that are destroyed each frame, so as not to negatively affect performance.
In order to create a custom Chunk Destroyer, start by creating a new MonoBehaviour script that derives from the ChunkDestroyer base abstract class.
You should place your class inside of the DeepSpaceLabs.SAM namespace, which will make the ChunkDestroyer class available and also help avoid naming conflicts with 3rd party assets or your own code.
--Special Note--
An easy way to start with your custom class is to hover over your custom class name and choose the option Show potential fixes -> Implement abstract class. This will provide default overrides for all abstract class members.
In addition, we recommend adding the following attribute above your class, which will ensure the custom chunk manager is shown with other Chunk Destroyers in menus:
[AddComponentMenu(GlobalValues.COMPONENT_ROOT_PATH + "Chunk Destroyers/Custom Chunk Destroyer Name")]
When called, this method should destroy all Asset Chunks belonging to the input cells. The MemoryFreeingStrategy set in the Chunk Streamer the Destroyer is assigned to is passed into the method, however it's up to you whether you want to make use of it.
A ChunkStreamer.ChunkStreamerUser object is also passed in, which can give you different information about the LOD Group whose chunks you need to destroy. You may or may not need to make use of this information.
When called, this method should destroy a single Asset Chunk belonging to a cell. A ChunkStreamer.ChunkStreamerUser object passed in, which can give you different information about the LOD Group whose chunk you need to destroy. You may or may not need to make use of this information.
It is perfectly valid for your DestroyChunksOnCells to make use of this DestroyChunk method, though it is not required.
--Special Note--
The return type of these methods is IEnumerator
1) Simply include yield return statements within the method's body where the returned object is either null or an instance of a YieldInstruction.
The compiler will auto generate a state machine class, which will be used to iterate the method's logic. The drawback of this technique is every time the method is called, a new instance of the auto generated class is created, resulting in garbage generation throughout the lifetime of the game.
2) Implement one of the reusable enumerator classes found within the API.
This strategy is harder to implement as you will need to implement the state machine logic yourself, as well as perform some other code related task necessary to use the reusable enumerators. It is recommended for experienced coders only!
If you elect to go with option 2, you can find detailed information on how to use the Reusable Enumerator classes in the Yield Enumerator Section within the Secondary Non Components Chapter.