com.wallstop-studios.unity-helpers 2.0.0-rc80 → 2.0.0-rc80.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,6 +5,7 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
5
5
|
using System.Linq;
|
|
6
6
|
using Core.Extension;
|
|
7
7
|
using UnityEngine;
|
|
8
|
+
using UnityEngine.Serialization;
|
|
8
9
|
|
|
9
10
|
[Flags]
|
|
10
11
|
public enum ChildSpawnMethod
|
|
@@ -20,6 +21,10 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
20
21
|
{
|
|
21
22
|
private static readonly HashSet<GameObject> SpawnedPrefabs = new();
|
|
22
23
|
|
|
24
|
+
[FormerlySerializedAs("dontDestroyOnLoad")]
|
|
25
|
+
[SerializeField]
|
|
26
|
+
private bool _dontDestroyOnLoad = true;
|
|
27
|
+
|
|
23
28
|
[SerializeField]
|
|
24
29
|
private ChildSpawnMethod _spawnMethod = ChildSpawnMethod.Start;
|
|
25
30
|
|
|
@@ -58,6 +63,7 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
58
63
|
|
|
59
64
|
private void Spawn()
|
|
60
65
|
{
|
|
66
|
+
TrySetDontDestroyOnLoad();
|
|
61
67
|
if (
|
|
62
68
|
_prefabs
|
|
63
69
|
.Concat(_editorOnlyPrefabs)
|
|
@@ -133,5 +139,13 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
133
139
|
}
|
|
134
140
|
return child;
|
|
135
141
|
}
|
|
142
|
+
|
|
143
|
+
private void TrySetDontDestroyOnLoad()
|
|
144
|
+
{
|
|
145
|
+
if (_dontDestroyOnLoad && Application.isPlaying && !gameObject.IsDontDestroyOnLoad())
|
|
146
|
+
{
|
|
147
|
+
DontDestroyOnLoad(gameObject);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
136
150
|
}
|
|
137
151
|
}
|
package/package.json
CHANGED