Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
cjddmut committed Mar 27, 2016
1 parent 6d778ed commit e00ea2e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ To use Unity Pooler for prefabs the PoolableGameObject component must be on the

**Release Objects on Scene Transition** - If an object persists across scenes then should it be released back to the pool when the scene changes?

**Send Creation Message** - Should a creation message be sent to a GameObject when it is created. Calls the function 'OnPooledObjCreated' on every Monobehaviour on the created GameObject and its children. This isn't a cheap operation so populating the pool is advised.
**Send Creation Message** - Should a creation message be sent to a GameObject when it is created. Calls the function 'OnCreate' on every Monobehaviour on the created GameObject and its children. This isn't a cheap operation so populating the pool is advised.

**Use Cap?** - Should the pool be capped at a certain count? If capped and the cap is hit then GameObjects will be recycled and reused to allow getting a new one.

**Cap Amount** - The cap count size.

**Reuse Message Type** - When a GameObject is reused due to hitting the cap. What kind, if any, message should be sent. Possible options are none, EnableDisable (reused GameObject will receive OnDisable message followed by OnEnable), or a the message OnPooledObjReused (which will be invoked on every active MonoBehaviour on the GameObject and its children).

**Desired Population** - This is informational only. The pool does not use this value but allows the desired number to be associated with the object. Call PoolableGameObject.PopulateToDesired() to populate the pool to this value.
**Desired Population** - This is informational only. The pool does not use this value but allows the desired number to be associated with the object. Call gameObject.PopulateToDesired() to populate the pool to this value.

### Populating ###

Expand All @@ -48,13 +48,16 @@ void Start()

// Similar to adding but just one
myGameObjectPrefab.IncrementPool();

// If the Desired Population is set in the inspector then PopulateToDesired can be used.
myGameObjectPrefab.PopulateToDesired();
}
```

If the creation messages are enabled then the following function will be invoked on the created GameObject and its children.
If the creation messages are enabled then the following function will be invoked on the created GameObject and its children. This works similarly to how the Awake and Start functions work. THIS IS NOT CHEAP! Which is why populating at the beginning is important.

```csharp
void OnPooledObjCreated()
void OnCreate()
{
Debug.Log("I was just created!");
}
Expand Down Expand Up @@ -99,7 +102,7 @@ enum ReuseMessageType
EnableDisable,

/// <summary>
/// Send message to invokes function OnPooledObjReused on the
/// Send message to invokes function OnReuse on the
/// object and all active children.
/// </summary>
SendMessage
Expand All @@ -123,6 +126,22 @@ void ReleaseObjBackToPool()
}
```

### Clearing ###

Generally a pool will be cleared when a scene transitions. The live and pooled objects will be destroyed when the scene is teared down. However, if objects are told to persist across scenes then this will not occur. In many cases there may not be a desire to clear a pool ever and the objects can just live on throughout the duration of the game. However, if it is desired to clear the pool then gameObject.ReleaseAndClearPool() can be called.

```csharp
public GameObject myGameObjectPrefab;

void ClearPool()
{
myGameObjectPrefab.ReleaseAndClearPool();

// Now all objects that were live have been released and all the objects that were in the
// pool have been destroyed. The pool population is now zero.
}
```

## C# Class Pool

The C# class pool works very similar to the GameObject pool in functionality. Main difference is interaction with the pool is done through a static class.
Expand Down

0 comments on commit e00ea2e

Please sign in to comment.