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

Commit 0ba985d

Browse files
committed
Added button to respawn all pool objects
1 parent e16c8a4 commit 0ba985d

3 files changed

Lines changed: 41 additions & 4 deletions

File tree

Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ public void ClearChildren()
139139
}
140140
}
141141

142+
public void RespawnAllPoolObjects()
143+
{
144+
if (!ShouldInitialize())
145+
{
146+
return;
147+
}
148+
149+
// No pool object prefab to update size.
150+
if (poolObjectPrefab == null)
151+
{
152+
return;
153+
}
154+
155+
ClearChildren();
156+
UpdatePoolSize();
157+
}
158+
142159
// Verify that the pool's current size matches the Object Pool's size.
143160
public void VerifyPoolSize()
144161
{

Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectAssignerEditor.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,30 @@ private void RenderHelperSettings()
9494
CyanPlayerObjectPoolEditorHelpers.AddIndent();
9595

9696
int assignerSize = _setupHelper.GetObjectCount();
97+
9798
// Only show Pool options when in a valid scene and not a prefab editor.
9899
if (shouldInitialize)
99100
{
101+
int poolSize = _setupHelper.GetPoolSize();
102+
103+
EditorGUILayout.BeginHorizontal();
104+
100105
if (GUILayout.Button("Ping Object Pool"))
101106
{
102107
EditorGUIUtility.PingObject(_setupHelper.GetPoolUdon().gameObject);
103108
}
109+
110+
GUILayout.Space(5);
111+
112+
if (GUILayout.Button("Respawn All Pool Objects"))
113+
{
114+
_setupHelper.RespawnAllPoolObjects();
115+
}
116+
117+
EditorGUILayout.EndHorizontal();
104118

105119
EditorGUI.BeginDisabledGroup(true);
106120

107-
int poolSize = _setupHelper.GetPoolSize();
108-
109121
EditorGUILayout.IntField("Pool Size", poolSize);
110122

111123
EditorGUI.EndDisabledGroup();
@@ -133,8 +145,7 @@ private void RenderHelperSettings()
133145
// Only apply changes when the scene is valid and not in a prefab editor.
134146
if (changes && shouldInitialize)
135147
{
136-
_setupHelper.ClearChildren();
137-
_setupHelper.UpdatePoolSize();
148+
_setupHelper.RespawnAllPoolObjects();
138149
}
139150

140151
CyanPlayerObjectPoolEditorHelpers.RemoveIndent();

Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectPoolEditor.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ private void RenderSettings()
133133
_sizeProp.intValue = Mathf.Clamp(value, MinPoolObjects, MaxPoolObjects);
134134
}
135135

136+
// Only display button to respawn objects if the scene can be edited.
137+
if (ShouldCheckScene() && GUILayout.Button("Respawn All Pool Objects"))
138+
{
139+
foreach (var helper in FindObjectsOfType<CyanPoolSetupHelper>())
140+
{
141+
helper.RespawnAllPoolObjects();
142+
}
143+
}
144+
136145
CyanPlayerObjectPoolEditorHelpers.RemoveIndent();
137146
}
138147

0 commit comments

Comments
 (0)