From 0ba985db5ffc700fd8ebae92dd6e5baacc6fabc8 Mon Sep 17 00:00:00 2001 From: CyanLaser Date: Thu, 9 Dec 2021 10:32:17 -0500 Subject: [PATCH] Added button to respawn all pool objects --- .../Scripts/CyanPoolSetupHelper.cs | 17 +++++++++++++++++ .../Editor/CyanPlayerObjectAssignerEditor.cs | 19 +++++++++++++++---- .../Editor/CyanPlayerObjectPoolEditor.cs | 9 +++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs b/Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs index a9fe732..48d4d39 100644 --- a/Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs +++ b/Cyan/PlayerObjectPool/Scripts/CyanPoolSetupHelper.cs @@ -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() { diff --git a/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectAssignerEditor.cs b/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectAssignerEditor.cs index 5ea0d90..ddd20d8 100644 --- a/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectAssignerEditor.cs +++ b/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectAssignerEditor.cs @@ -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(); @@ -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(); diff --git a/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectPoolEditor.cs b/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectPoolEditor.cs index 8877ffd..49ece70 100644 --- a/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectPoolEditor.cs +++ b/Cyan/PlayerObjectPool/Scripts/Editor/CyanPlayerObjectPoolEditor.cs @@ -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()) + { + helper.RespawnAllPoolObjects(); + } + } + CyanPlayerObjectPoolEditorHelpers.RemoveIndent(); }