|
Swarm Object Manager 1.6
Unity Object Manager
|
The SwarmItemManager handles SwarmItem objects. It actively recycles SwarmItems so that no garbage collection is necessary. It will dynamically add new objects as required, pulling from inactive lists if any recycled SwarmItems are available. You can have multiple SwarmItemManagers in a scene to handle different types of objects. Alternatively, you could handle all your object types within a single SwarmItemManager. More...
Classes | |
| class | PrefabItem |
| This class is used to wrap the prefab so that you can set the maximum count for each item. More... | |
| class | PrefabItemLists |
| This internal class represents the active and inactive lists of a SwarmItem type. Since SwarmItemManager's can handle multiple types of SwarmItems, there is an active and inactive list for each. More... | |
Public Member Functions | |
| virtual void | Initialize () |
| Sets up the lists for each SwarmItem type. Also creates the parent transform for the active and inactive objects. | |
| virtual SwarmItem | ActivateItem () |
| Overloaded form of ActivateItem that assumes you just want the first SwarmItem type (first prefab) | |
| virtual SwarmItem | ActivateItem (int itemPrefabIndex) |
| Activates a SwarmItem base on the prefab index (type). If there is an inactive item, the manager will recycle that first, otherwise it will instantiate a new item. | |
| virtual void | DeactiveItem (SwarmItem item) |
| Moves a SwarmItem from the active list to the inactive list and changes its parent transform. | |
| virtual void | FrameUpdate () |
| This function is called every frame. It will iterate through each SwarmItem type's active list, calling FrameUpdate on each of the items. This method should be called from a central Update() Mono method, or you can add an Update() method here and call it. | |
| void | PruneList (int itemPrefabIndex, float prunePercentage) |
| Removes inactive items from the list after the inactive item count exceeds a threshold and no new items are activated from the list before the prune timer countdown expires. Alternatively, you could call this manually to free up memory at any time. | |
Public Attributes | |
| bool | debugEvents |
| flag to show important events happening in this manager | |
| PrefabItem[] | itemPrefabs |
| the array of prefabs with their maximum item counts. This is set in the editor | |
Protected Member Functions | |
| virtual SwarmItem | InstantiateItem (int itemPrefabIndex) |
| Creates a new gameobject for the SwarmItem and initializes it. | |
Protected Attributes | |
| PrefabItemLists[] | _prefabItemLists |
| the array of prefab item lists. Each prefab gets a set of inactive and active lists | |
The SwarmItemManager handles SwarmItem objects. It actively recycles SwarmItems so that no garbage collection is necessary. It will dynamically add new objects as required, pulling from inactive lists if any recycled SwarmItems are available. You can have multiple SwarmItemManagers in a scene to handle different types of objects. Alternatively, you could handle all your object types within a single SwarmItemManager.
The manager can limit each of its lists to an optional maximum item count. If this limit greater than zero, then the manager won't instantiate any more objects in a list once it has reached the maximum count. If the limit is zero, the manager will keep instantiating new objects as neccessary.
Each item list has its own optional pruning functionality. When an item is pruned it is sent to the garbage collector. If the number of the inactive items of a prefab exceed the set threshold, a pruning timer will kick in. If the number of the inactive items drop back below the threshold, the pruning timer will shut back off. When the pruning timer countdown expires, the inactive list will be pruned to the prune percentage set for the item. You can shut off pruning by setting the inactivePrunePercentage to zero.
| virtual SwarmItem SwarmItemManager.ActivateItem | ( | ) | [virtual] |
| virtual SwarmItem SwarmItemManager.ActivateItem | ( | int | itemPrefabIndex | ) | [virtual] |
| virtual void SwarmItemManager.DeactiveItem | ( | SwarmItem | item | ) | [virtual] |
| virtual void SwarmItemManager.FrameUpdate | ( | ) | [virtual] |
This function is called every frame. It will iterate through each SwarmItem type's active list, calling FrameUpdate on each of the items. This method should be called from a central Update() Mono method, or you can add an Update() method here and call it.
| virtual void SwarmItemManager.Initialize | ( | ) | [virtual] |
Sets up the lists for each SwarmItem type. Also creates the parent transform for the active and inactive objects.
| virtual SwarmItem SwarmItemManager.InstantiateItem | ( | int | itemPrefabIndex | ) | [protected, virtual] |
| void SwarmItemManager.PruneList | ( | int | itemPrefabIndex, |
| float | prunePercentage | ||
| ) |
Removes inactive items from the list after the inactive item count exceeds a threshold and no new items are activated from the list before the prune timer countdown expires. Alternatively, you could call this manually to free up memory at any time.
| itemPrefabIndex | The index of the list to prune |
| prunePercentage | The amount (relative to the number of inactive items) to prune from the inactive list. |
PrefabItemLists [] SwarmItemManager._prefabItemLists [protected] |
the array of prefab item lists. Each prefab gets a set of inactive and active lists
flag to show important events happening in this manager
the array of prefabs with their maximum item counts. This is set in the editor
1.7.4