Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Added button to respawn all pool objects
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanLaser committed Dec 9, 2021
1 parent e16c8a4 commit 0ba985d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ public void ClearChildren()
}
}

public void RespawnAllPoolObjects()
{
if (!ShouldInitialize())
{
return;
}

// No pool object prefab to update size.
if (poolObjectPrefab == null)
{
return;
}

ClearChildren();
UpdatePoolSize();
}

// Verify that the pool's current size matches the Object Pool's size.
public void VerifyPoolSize()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,30 @@ private void RenderHelperSettings()
CyanPlayerObjectPoolEditorHelpers.AddIndent();

int assignerSize = _setupHelper.GetObjectCount();

// Only show Pool options when in a valid scene and not a prefab editor.
if (shouldInitialize)
{
int poolSize = _setupHelper.GetPoolSize();

EditorGUILayout.BeginHorizontal();

if (GUILayout.Button("Ping Object Pool"))
{
EditorGUIUtility.PingObject(_setupHelper.GetPoolUdon().gameObject);
}

GUILayout.Space(5);

if (GUILayout.Button("Respawn All Pool Objects"))
{
_setupHelper.RespawnAllPoolObjects();
}

EditorGUILayout.EndHorizontal();

EditorGUI.BeginDisabledGroup(true);

int poolSize = _setupHelper.GetPoolSize();

EditorGUILayout.IntField("Pool Size", poolSize);

EditorGUI.EndDisabledGroup();
Expand Down Expand Up @@ -133,8 +145,7 @@ private void RenderHelperSettings()
// Only apply changes when the scene is valid and not in a prefab editor.
if (changes && shouldInitialize)
{
_setupHelper.ClearChildren();
_setupHelper.UpdatePoolSize();
_setupHelper.RespawnAllPoolObjects();
}

CyanPlayerObjectPoolEditorHelpers.RemoveIndent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ private void RenderSettings()
_sizeProp.intValue = Mathf.Clamp(value, MinPoolObjects, MaxPoolObjects);
}

// Only display button to respawn objects if the scene can be edited.
if (ShouldCheckScene() && GUILayout.Button("Respawn All Pool Objects"))
{
foreach (var helper in FindObjectsOfType<CyanPoolSetupHelper>())
{
helper.RespawnAllPoolObjects();
}
}

CyanPlayerObjectPoolEditorHelpers.RemoveIndent();
}

Expand Down

0 comments on commit 0ba985d

Please sign in to comment.