com.wallstop-studios.unity-helpers 2.0.0-rc79.7 → 2.0.0-rc79.8
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.
|
@@ -83,7 +83,7 @@ namespace WallstopStudios.UnityHelpers.Core.Extension
|
|
|
83
83
|
bool foundAny = false;
|
|
84
84
|
foreach (Direction singleDirection in Directions)
|
|
85
85
|
{
|
|
86
|
-
if (direction.
|
|
86
|
+
if (direction.HasFlagNoAlloc(singleDirection))
|
|
87
87
|
{
|
|
88
88
|
foundAny = true;
|
|
89
89
|
yield return singleDirection;
|
|
@@ -1,25 +1,62 @@
|
|
|
1
1
|
namespace WallstopStudios.UnityHelpers.Utils
|
|
2
2
|
{
|
|
3
|
+
using System;
|
|
3
4
|
using System.Collections.Generic;
|
|
4
5
|
using System.Linq;
|
|
5
6
|
using Core.Extension;
|
|
6
7
|
using UnityEngine;
|
|
7
8
|
|
|
9
|
+
[Flags]
|
|
10
|
+
public enum ChildSpawnMethod
|
|
11
|
+
{
|
|
12
|
+
None = 0,
|
|
13
|
+
Awake = 1 << 0,
|
|
14
|
+
OnEnabled = 1 << 1,
|
|
15
|
+
Start = 1 << 2,
|
|
16
|
+
}
|
|
17
|
+
|
|
8
18
|
[DisallowMultipleComponent]
|
|
9
19
|
public sealed class ChildSpawner : MonoBehaviour
|
|
10
20
|
{
|
|
11
21
|
private static readonly HashSet<GameObject> SpawnedPrefabs = new();
|
|
12
22
|
|
|
13
23
|
[SerializeField]
|
|
14
|
-
private
|
|
24
|
+
private ChildSpawnMethod _spawnMethod = ChildSpawnMethod.Start;
|
|
25
|
+
|
|
26
|
+
[SerializeField]
|
|
27
|
+
private GameObject[] _prefabs = Array.Empty<GameObject>();
|
|
15
28
|
|
|
16
29
|
[SerializeField]
|
|
17
|
-
private GameObject[] _editorOnlyPrefabs;
|
|
30
|
+
private GameObject[] _editorOnlyPrefabs = Array.Empty<GameObject>();
|
|
18
31
|
|
|
19
32
|
[SerializeField]
|
|
20
|
-
private GameObject[] _developmentOnlyPrefabs;
|
|
33
|
+
private GameObject[] _developmentOnlyPrefabs = Array.Empty<GameObject>();
|
|
34
|
+
|
|
35
|
+
private void Awake()
|
|
36
|
+
{
|
|
37
|
+
if (_spawnMethod.HasFlagNoAlloc(ChildSpawnMethod.Awake))
|
|
38
|
+
{
|
|
39
|
+
Spawn();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private void OnEnable()
|
|
44
|
+
{
|
|
45
|
+
if (_spawnMethod.HasFlagNoAlloc(ChildSpawnMethod.OnEnabled))
|
|
46
|
+
{
|
|
47
|
+
Spawn();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
21
50
|
|
|
22
51
|
private void Start()
|
|
52
|
+
{
|
|
53
|
+
if (_spawnMethod.HasFlagNoAlloc(ChildSpawnMethod.Start))
|
|
54
|
+
{
|
|
55
|
+
Spawn();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
private void Spawn()
|
|
23
60
|
{
|
|
24
61
|
if (
|
|
25
62
|
_prefabs
|
|
@@ -41,13 +41,9 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
41
41
|
|
|
42
42
|
Type type = typeof(T);
|
|
43
43
|
GameObject instance = new($"{type.Name}-Singleton", type);
|
|
44
|
-
if (
|
|
45
|
-
instance.TryGetComponent(out _instance)
|
|
46
|
-
&& _instance.Preserve
|
|
47
|
-
&& Application.isPlaying
|
|
48
|
-
)
|
|
44
|
+
if (_instance == null)
|
|
49
45
|
{
|
|
50
|
-
|
|
46
|
+
_ = instance.TryGetComponent(out _instance);
|
|
51
47
|
}
|
|
52
48
|
|
|
53
49
|
return _instance;
|
|
@@ -61,6 +57,11 @@ namespace WallstopStudios.UnityHelpers.Utils
|
|
|
61
57
|
{
|
|
62
58
|
_instance = this as T;
|
|
63
59
|
}
|
|
60
|
+
|
|
61
|
+
if (Preserve && Application.isPlaying)
|
|
62
|
+
{
|
|
63
|
+
DontDestroyOnLoad(gameObject);
|
|
64
|
+
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
protected virtual void Start()
|
package/package.json
CHANGED