fr.jeanf.scenemanagement 0.1.2 → 0.2.0

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.
Files changed (148) hide show
  1. package/Runtime/AdditiveLoading/Editor/SpawnPosEditor.cs +55 -0
  2. package/Runtime/AdditiveLoading/Editor/SpawnPosEditor.cs.meta +3 -0
  3. package/Runtime/AdditiveLoading/Editor.meta +8 -0
  4. package/Runtime/AdditiveLoading/Region.cs +1 -50
  5. package/Runtime/AdditiveLoading/SceneLoader.cs +39 -36
  6. package/Runtime/DynamicLoading/Editor/VolumeConnectivityVisualizer.cs +797 -0
  7. package/Runtime/DynamicLoading/Editor/VolumeConnectivityVisualizer.cs.meta +2 -0
  8. package/Runtime/DynamicLoading/Editor.meta +8 -0
  9. package/Runtime/DynamicLoading/RegionConnectivity.cs +47 -0
  10. package/Runtime/DynamicLoading/RegionConnectivity.cs.meta +2 -0
  11. package/Runtime/DynamicLoading/RegionConnectivityAuthoring.cs +83 -0
  12. package/Runtime/DynamicLoading/RegionConnectivityAuthoring.cs.meta +2 -0
  13. package/Runtime/DynamicLoading/VolumeSystem.cs +52 -54
  14. package/Samples/Example/RegionConnectivity.asset +25 -0
  15. package/Samples/Example/RegionConnectivity.asset.meta +8 -0
  16. package/Samples/Example/RegionData/Region_00/Region_00_Volumes.prefab +8 -8
  17. package/Samples/Example/RegionData/Region_00/Zones/{Zone_1.asset → Zone_01.asset} +1 -1
  18. package/Samples/Example/RegionData/Region_00/Zones/{Zone_2.asset → Zone_02.asset} +1 -1
  19. package/Samples/Example/RegionData/Region_00/Zones/Zone_03.asset +21 -0
  20. package/Samples/Example/RegionData/Region_00/Zones/{Zone_4.asset → Zone_04.asset} +1 -1
  21. package/Samples/Example/RegionData/Region_00/Zones/{Zone_5.asset → Zone_05.asset} +1 -1
  22. package/Samples/Example/RegionData/Region_00/Zones/{Zone_6.asset → Zone_06.asset} +1 -1
  23. package/Samples/Example/RegionData/Region_00/Zones/{Zone_7.asset → Zone_07.asset} +1 -1
  24. package/Samples/Example/RegionData/Region_00/Zones/{Zone_8.asset → Zone_08.asset} +1 -1
  25. package/Samples/Example/RegionData/Region_01/Region_01.asset +43 -0
  26. package/Samples/Example/RegionData/Region_01/Region_01.asset.meta +8 -0
  27. package/Samples/Example/RegionData/Region_01/Region_01_Volumes.prefab +409 -0
  28. package/Samples/Example/RegionData/Region_01/Region_01_Volumes.prefab.meta +7 -0
  29. package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_1.asset +25 -0
  30. package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_1.asset.meta +8 -0
  31. package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_2.asset +25 -0
  32. package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_2.asset.meta +8 -0
  33. package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_1.asset +16 -0
  34. package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_1.asset.meta +8 -0
  35. package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_2.asset +16 -0
  36. package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_2.asset.meta +8 -0
  37. package/Samples/Example/RegionData/Region_01/Scenarios.meta +8 -0
  38. package/Samples/Example/RegionData/Region_01/Zones/Zone_11.asset +21 -0
  39. package/Samples/Example/RegionData/Region_01/Zones/Zone_11.asset.meta +8 -0
  40. package/Samples/Example/RegionData/Region_01/Zones/Zone_12.asset +22 -0
  41. package/Samples/Example/RegionData/Region_01/Zones/Zone_12.asset.meta +8 -0
  42. package/Samples/Example/RegionData/{Region_00/Zones/Zone_3.asset → Region_01/Zones/Zone_13.asset} +3 -3
  43. package/Samples/Example/RegionData/Region_01/Zones/Zone_13.asset.meta +8 -0
  44. package/Samples/Example/RegionData/Region_01/Zones/Zone_14.asset +21 -0
  45. package/Samples/Example/RegionData/Region_01/Zones/Zone_14.asset.meta +8 -0
  46. package/Samples/Example/RegionData/Region_01/Zones/Zone_15.asset +22 -0
  47. package/Samples/Example/RegionData/Region_01/Zones/Zone_15.asset.meta +8 -0
  48. package/Samples/Example/RegionData/Region_01/Zones/Zone_16.asset +23 -0
  49. package/Samples/Example/RegionData/Region_01/Zones/Zone_16.asset.meta +8 -0
  50. package/Samples/Example/RegionData/Region_01/Zones/Zone_17.asset +21 -0
  51. package/Samples/Example/RegionData/Region_01/Zones/Zone_17.asset.meta +8 -0
  52. package/Samples/Example/RegionData/Region_01/Zones/Zone_18.asset +21 -0
  53. package/Samples/Example/RegionData/Region_01/Zones/Zone_18.asset.meta +8 -0
  54. package/Samples/Example/RegionData/Region_01/Zones.meta +8 -0
  55. package/Samples/Example/RegionData/Region_01.meta +8 -0
  56. package/Samples/Example/RegionData/Region_02/Region_02.asset +43 -0
  57. package/Samples/Example/RegionData/Region_02/Region_02.asset.meta +8 -0
  58. package/Samples/Example/RegionData/Region_02/Region_02_Volumes.prefab +409 -0
  59. package/Samples/Example/RegionData/Region_02/Region_02_Volumes.prefab.meta +7 -0
  60. package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_1.asset +25 -0
  61. package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_1.asset.meta +8 -0
  62. package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_2.asset +25 -0
  63. package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_2.asset.meta +8 -0
  64. package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_1.asset +16 -0
  65. package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_1.asset.meta +8 -0
  66. package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_2.asset +16 -0
  67. package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_2.asset.meta +8 -0
  68. package/Samples/Example/RegionData/Region_02/Scenarios.meta +8 -0
  69. package/Samples/Example/RegionData/Region_02/Zones/Zone_21.asset +21 -0
  70. package/Samples/Example/RegionData/Region_02/Zones/Zone_21.asset.meta +8 -0
  71. package/Samples/Example/RegionData/Region_02/Zones/Zone_22.asset +22 -0
  72. package/Samples/Example/RegionData/Region_02/Zones/Zone_22.asset.meta +8 -0
  73. package/Samples/Example/RegionData/Region_02/Zones/Zone_23.asset +22 -0
  74. package/Samples/Example/RegionData/Region_02/Zones/Zone_23.asset.meta +8 -0
  75. package/Samples/Example/RegionData/Region_02/Zones/Zone_24.asset +21 -0
  76. package/Samples/Example/RegionData/Region_02/Zones/Zone_24.asset.meta +8 -0
  77. package/Samples/Example/RegionData/Region_02/Zones/Zone_25.asset +22 -0
  78. package/Samples/Example/RegionData/Region_02/Zones/Zone_25.asset.meta +8 -0
  79. package/Samples/Example/RegionData/Region_02/Zones/Zone_26.asset +23 -0
  80. package/Samples/Example/RegionData/Region_02/Zones/Zone_26.asset.meta +8 -0
  81. package/Samples/Example/RegionData/Region_02/Zones/Zone_27.asset +21 -0
  82. package/Samples/Example/RegionData/Region_02/Zones/Zone_27.asset.meta +8 -0
  83. package/Samples/Example/RegionData/Region_02/Zones/Zone_28.asset +21 -0
  84. package/Samples/Example/RegionData/Region_02/Zones/Zone_28.asset.meta +8 -0
  85. package/Samples/Example/RegionData/Region_02/Zones.meta +8 -0
  86. package/Samples/Example/RegionData/Region_02.meta +8 -0
  87. package/Samples/Example/Scenes/00.meta +8 -0
  88. package/Samples/Example/Scenes/01/1.unity +375 -0
  89. package/Samples/Example/Scenes/01/1.unity.meta +7 -0
  90. package/Samples/Example/Scenes/01/2.unity +484 -0
  91. package/Samples/Example/Scenes/01/2.unity.meta +7 -0
  92. package/Samples/Example/Scenes/01/3.unity +702 -0
  93. package/Samples/Example/Scenes/01/3.unity.meta +7 -0
  94. package/Samples/Example/Scenes/01/4.unity +375 -0
  95. package/Samples/Example/Scenes/01/4.unity.meta +7 -0
  96. package/Samples/Example/Scenes/01/5.unity +375 -0
  97. package/Samples/Example/Scenes/01/5.unity.meta +7 -0
  98. package/Samples/Example/Scenes/01/6.unity +484 -0
  99. package/Samples/Example/Scenes/01/6.unity.meta +7 -0
  100. package/Samples/Example/Scenes/01/7.unity +484 -0
  101. package/Samples/Example/Scenes/01/7.unity.meta +7 -0
  102. package/Samples/Example/Scenes/01/8.unity +375 -0
  103. package/Samples/Example/Scenes/01/8.unity.meta +7 -0
  104. package/Samples/Example/Scenes/01.meta +8 -0
  105. package/Samples/Example/Scenes/02/1.unity +375 -0
  106. package/Samples/Example/Scenes/02/1.unity.meta +7 -0
  107. package/Samples/Example/Scenes/02/2.unity +484 -0
  108. package/Samples/Example/Scenes/02/2.unity.meta +7 -0
  109. package/Samples/Example/Scenes/02/3.unity +702 -0
  110. package/Samples/Example/Scenes/02/3.unity.meta +7 -0
  111. package/Samples/Example/Scenes/02/4.unity +375 -0
  112. package/Samples/Example/Scenes/02/4.unity.meta +7 -0
  113. package/Samples/Example/Scenes/02/5.unity +375 -0
  114. package/Samples/Example/Scenes/02/5.unity.meta +7 -0
  115. package/Samples/Example/Scenes/02/6.unity +484 -0
  116. package/Samples/Example/Scenes/02/6.unity.meta +7 -0
  117. package/Samples/Example/Scenes/02/7.unity +484 -0
  118. package/Samples/Example/Scenes/02/7.unity.meta +7 -0
  119. package/Samples/Example/Scenes/02/8.unity +375 -0
  120. package/Samples/Example/Scenes/02/8.unity.meta +7 -0
  121. package/Samples/Example/Scenes/02.meta +8 -0
  122. package/Samples/Example/Scenes/Main.unity +0 -119
  123. package/Samples/Example/Scenes/World.unity +1874 -198
  124. package/package.json +1 -1
  125. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_1.asset.meta → Zone_01.asset.meta} +0 -0
  126. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_2.asset.meta → Zone_02.asset.meta} +0 -0
  127. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_3.asset.meta → Zone_03.asset.meta} +0 -0
  128. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_4.asset.meta → Zone_04.asset.meta} +0 -0
  129. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_5.asset.meta → Zone_05.asset.meta} +0 -0
  130. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_6.asset.meta → Zone_06.asset.meta} +0 -0
  131. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_7.asset.meta → Zone_07.asset.meta} +0 -0
  132. /package/Samples/Example/RegionData/Region_00/Zones/{Zone_8.asset.meta → Zone_08.asset.meta} +0 -0
  133. /package/Samples/Example/Scenes/{1.unity → 00/1.unity} +0 -0
  134. /package/Samples/Example/Scenes/{1.unity.meta → 00/1.unity.meta} +0 -0
  135. /package/Samples/Example/Scenes/{2.unity → 00/2.unity} +0 -0
  136. /package/Samples/Example/Scenes/{2.unity.meta → 00/2.unity.meta} +0 -0
  137. /package/Samples/Example/Scenes/{3.unity → 00/3.unity} +0 -0
  138. /package/Samples/Example/Scenes/{3.unity.meta → 00/3.unity.meta} +0 -0
  139. /package/Samples/Example/Scenes/{4.unity → 00/4.unity} +0 -0
  140. /package/Samples/Example/Scenes/{4.unity.meta → 00/4.unity.meta} +0 -0
  141. /package/Samples/Example/Scenes/{5.unity → 00/5.unity} +0 -0
  142. /package/Samples/Example/Scenes/{5.unity.meta → 00/5.unity.meta} +0 -0
  143. /package/Samples/Example/Scenes/{6.unity → 00/6.unity} +0 -0
  144. /package/Samples/Example/Scenes/{6.unity.meta → 00/6.unity.meta} +0 -0
  145. /package/Samples/Example/Scenes/{7.unity → 00/7.unity} +0 -0
  146. /package/Samples/Example/Scenes/{7.unity.meta → 00/7.unity.meta} +0 -0
  147. /package/Samples/Example/Scenes/{8.unity → 00/8.unity} +0 -0
  148. /package/Samples/Example/Scenes/{8.unity.meta → 00/8.unity.meta} +0 -0
@@ -0,0 +1,55 @@
1
+ #if UNITY_EDITOR
2
+ using UnityEditor;
3
+ using UnityEngine;
4
+
5
+ namespace jeanf.scenemanagement
6
+ {
7
+ [CustomEditor(typeof(WorldManager))]
8
+ public class SpawnPosEditor : Editor
9
+ {
10
+ private void OnSceneGUI()
11
+ {
12
+ WorldManager worldManager = (WorldManager) target;
13
+ if (worldManager.ListOfRegions == null) return;
14
+
15
+ foreach (var region in worldManager.ListOfRegions)
16
+ {
17
+ if (region.isUsingOnInitSpawnPos)
18
+ {
19
+ DrawSpawnPosHandle(ref region.SpawnPosOnInit, $"{region.levelName} - Initial Spawn");
20
+ }
21
+ DrawSpawnPosHandle(ref region.SpawnPosOnRegionChangeRequest, $"{region.levelName} - Manual Spawn");
22
+ }
23
+ }
24
+
25
+ private void DrawSpawnPosHandle(ref SpawnPos spawnPos, string label)
26
+ {
27
+ EditorGUI.BeginChangeCheck();
28
+
29
+ float handleSize = HandleUtility.GetHandleSize(spawnPos.position) * .5f;
30
+
31
+ // Draw position handle
32
+ Vector3 newPosition = Handles.PositionHandle(spawnPos.position, Quaternion.identity);
33
+
34
+ // Draw rotation handle (only yaw rotation around Y-axis)
35
+ Quaternion newRotation = Handles.Disc(Quaternion.Euler(spawnPos.rotation), spawnPos.position, Vector3.up, handleSize, false, 1f);
36
+
37
+ // Draw label
38
+ Handles.Label(spawnPos.position, label, new GUIStyle { fontStyle = FontStyle.Bold, normal = new GUIStyleState { textColor = Color.white } });
39
+
40
+ // Draw front marker with scaled size
41
+ Vector3 forward = Quaternion.Euler(spawnPos.rotation) * Vector3.forward * handleSize;
42
+ Handles.color = Color.cyan;
43
+ Handles.ArrowHandleCap(0, spawnPos.position, Quaternion.LookRotation(forward), handleSize, EventType.Repaint);
44
+
45
+ if (EditorGUI.EndChangeCheck())
46
+ {
47
+ Undo.RecordObject(Selection.activeGameObject, "Move Spawn Position");
48
+ spawnPos.position = newPosition;
49
+ spawnPos.rotation = new Vector3(0, newRotation.eulerAngles.y, 0);
50
+ EditorUtility.SetDirty(Selection.activeGameObject);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ #endif
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 57c3746d33c54dd488374a9b9d3eb9b4
3
+ timeCreated: 1748312663
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 1568e5d4a5f1a3e4dbb8adfe07d84b47
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -48,54 +48,5 @@ namespace jeanf.scenemanagement
48
48
  }
49
49
  }
50
50
 
51
-
52
- #if UNITY_EDITOR
53
- [CustomEditor(typeof(WorldManager))]
54
- public class SpawnPosEditor : Editor
55
- {
56
- private void OnSceneGUI()
57
- {
58
- WorldManager worldManager = (WorldManager)target;
59
- if (worldManager.ListOfRegions == null) return;
60
-
61
- foreach (var region in worldManager.ListOfRegions)
62
- {
63
- if (region.isUsingOnInitSpawnPos)
64
- {
65
- DrawSpawnPosHandle(ref region.SpawnPosOnInit, $"{region.levelName} - Initial Spawn");
66
- }
67
- DrawSpawnPosHandle(ref region.SpawnPosOnRegionChangeRequest, $"{region.levelName} - Manual Spawn");
68
- }
69
- }
70
-
71
- private void DrawSpawnPosHandle(ref SpawnPos spawnPos, string label)
72
- {
73
- EditorGUI.BeginChangeCheck();
74
-
75
- float handleSize = HandleUtility.GetHandleSize(spawnPos.position) * .5f;
76
-
77
- // Draw position handle
78
- Vector3 newPosition = Handles.PositionHandle(spawnPos.position, Quaternion.identity);
79
-
80
- // Draw rotation handle (only yaw rotation around Y-axis)
81
- Quaternion newRotation = Handles.Disc(Quaternion.Euler(spawnPos.rotation), spawnPos.position, Vector3.up, handleSize, false, 1f);
82
-
83
- // Draw label
84
- Handles.Label(spawnPos.position, label, new GUIStyle { fontStyle = FontStyle.Bold, normal = new GUIStyleState { textColor = Color.white } });
85
-
86
- // Draw front marker with scaled size
87
- Vector3 forward = Quaternion.Euler(spawnPos.rotation) * Vector3.forward * handleSize;
88
- Handles.color = Color.cyan;
89
- Handles.ArrowHandleCap(0, spawnPos.position, Quaternion.LookRotation(forward), handleSize, EventType.Repaint);
90
-
91
- if (EditorGUI.EndChangeCheck())
92
- {
93
- Undo.RecordObject(Selection.activeGameObject, "Move Spawn Position");
94
- spawnPos.position = newPosition;
95
- spawnPos.rotation = new Vector3(0, newRotation.eulerAngles.y, 0);
96
- EditorUtility.SetDirty(Selection.activeGameObject);
97
- }
98
- }
99
- }
100
- #endif
51
+
101
52
  }
@@ -13,6 +13,7 @@ namespace jeanf.scenemanagement
13
13
  public bool isDebug = false;
14
14
  private CancellationTokenSource _queueCts;
15
15
  [SerializeField] private int maxConcurrentLoads = 2;
16
+
16
17
  public delegate void IsLoadingDelegate(bool loadingState);
17
18
  public static IsLoadingDelegate IsLoading;
18
19
 
@@ -20,22 +21,32 @@ namespace jeanf.scenemanagement
20
21
  public LoadScene LoadSceneRequest;
21
22
  public LoadScene UnLoadSceneRequest;
22
23
 
23
- public delegate void UnloadAllScenesDelegate();
24
- public UnloadAllScenesDelegate UnloadAllScenesRequest;
24
+ public delegate void UnloadAllScenesDelegate();
25
+ public UnloadAllScenesDelegate UnloadAllScenesRequest;
25
26
 
26
27
  public delegate void FlushScenesDelegate();
27
28
  public FlushScenesDelegate FlushScenesRequest;
28
29
 
29
- private record SceneOperation(SceneOperationType Type, string SceneName)
30
+ private readonly struct SceneOperation
30
31
  {
31
- public SceneOperationType Type { get; } = Type;
32
- public string SceneName { get; } = SceneName;
32
+ public readonly SceneOperationType Type;
33
+ public readonly string SceneName;
34
+
35
+ public SceneOperation(SceneOperationType type, string sceneName)
36
+ {
37
+ Type = type;
38
+ SceneName = sceneName;
39
+ }
33
40
  }
34
41
 
35
42
  private readonly ConcurrentQueue<SceneOperation> _loadQueue = new();
36
43
  private readonly ConcurrentQueue<SceneOperation> _unloadQueue = new();
37
44
  private readonly HashSet<string> _loadedScenes = new();
38
45
  private readonly HashSet<string> _processingScenes = new();
46
+
47
+ private readonly List<UniTask> _operationBuffer = new();
48
+ private readonly List<string> _scenesToUnload = new();
49
+
39
50
  private bool _isProcessingLoadQueue = false;
40
51
  private bool _isProcessingUnloadQueue = false;
41
52
 
@@ -75,11 +86,17 @@ namespace jeanf.scenemanagement
75
86
  {
76
87
  if (isDebug) Debug.Log("Unloading all scenes");
77
88
 
78
- _loadQueue.Clear();
89
+ while (_loadQueue.TryDequeue(out _)) { }
79
90
 
80
- foreach (var sceneName in new HashSet<string>(_loadedScenes))
91
+ _scenesToUnload.Clear();
92
+ foreach (var sceneName in _loadedScenes)
81
93
  {
82
- _unloadQueue.Enqueue(new SceneOperation(SceneOperationType.Unload, sceneName));
94
+ _scenesToUnload.Add(sceneName);
95
+ }
96
+
97
+ for (int i = 0; i < _scenesToUnload.Count; i++)
98
+ {
99
+ _unloadQueue.Enqueue(new SceneOperation(SceneOperationType.Unload, _scenesToUnload[i]));
83
100
  }
84
101
 
85
102
  ProcessUnloadQueue().Forget();
@@ -89,7 +106,6 @@ namespace jeanf.scenemanagement
89
106
  {
90
107
  if (isDebug) Debug.Log("Flushing memory");
91
108
 
92
- // Force garbage collection to reclaim memory
93
109
  await Resources.UnloadUnusedAssets().ToUniTask(cancellationToken: cancellationToken);
94
110
  GC.Collect();
95
111
 
@@ -113,25 +129,22 @@ namespace jeanf.scenemanagement
113
129
  {
114
130
  while (_loadQueue.Count > 0 && !token.IsCancellationRequested)
115
131
  {
116
- var operations = new List<UniTask>();
132
+ _operationBuffer.Clear();
117
133
 
118
- while (operations.Count < maxConcurrentLoads && _loadQueue.TryDequeue(out var operation))
134
+ while (_operationBuffer.Count < maxConcurrentLoads && _loadQueue.TryDequeue(out var operation))
119
135
  {
120
136
  if (_processingScenes.Contains(operation.SceneName) || _loadedScenes.Contains(operation.SceneName))
121
137
  continue;
122
138
 
123
139
  _processingScenes.Add(operation.SceneName);
124
-
125
- if (isDebug) Debug.Log($"Loading scene: {operation.SceneName}");
126
- operations.Add(LoadSceneAsync(operation.SceneName, token));
140
+ _operationBuffer.Add(LoadSceneAsync(operation.SceneName, token));
127
141
  }
128
142
 
129
- if (operations.Count > 0)
143
+ if (_operationBuffer.Count > 0)
130
144
  {
131
- await UniTask.WhenAll(operations);
145
+ await UniTask.WhenAll(_operationBuffer);
132
146
  }
133
147
 
134
- // Small delay to prevent overwhelming the system
135
148
  await UniTask.Yield();
136
149
  }
137
150
  }
@@ -162,22 +175,20 @@ namespace jeanf.scenemanagement
162
175
  {
163
176
  while (_unloadQueue.Count > 0 && !token.IsCancellationRequested)
164
177
  {
165
- var operations = new List<UniTask>();
178
+ _operationBuffer.Clear();
166
179
 
167
- while (operations.Count < maxConcurrentLoads && _unloadQueue.TryDequeue(out var operation))
180
+ while (_operationBuffer.Count < maxConcurrentLoads && _unloadQueue.TryDequeue(out var operation))
168
181
  {
169
182
  if (!_loadedScenes.Contains(operation.SceneName) || _processingScenes.Contains(operation.SceneName))
170
183
  continue;
171
184
 
172
185
  _processingScenes.Add(operation.SceneName);
173
-
174
- if (isDebug) Debug.Log($"Unloading scene: {operation.SceneName}");
175
- operations.Add(UnloadSceneAsync(operation.SceneName, token));
186
+ _operationBuffer.Add(UnloadSceneAsync(operation.SceneName, token));
176
187
  }
177
188
 
178
- if (operations.Count > 0)
189
+ if (_operationBuffer.Count > 0)
179
190
  {
180
- await UniTask.WhenAll(operations);
191
+ await UniTask.WhenAll(_operationBuffer);
181
192
  }
182
193
 
183
194
  // Small delay to prevent overwhelming the system
@@ -201,17 +212,14 @@ namespace jeanf.scenemanagement
201
212
 
202
213
  private async UniTask LoadSceneAsync(string sceneName, CancellationToken cancellationToken)
203
214
  {
215
+ AsyncOperation loadOperation = null;
216
+
204
217
  try
205
218
  {
206
- var loadOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
207
- loadOperation!.allowSceneActivation = true;
219
+ loadOperation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
220
+ loadOperation.allowSceneActivation = true;
208
221
  await loadOperation.ToUniTask(cancellationToken: cancellationToken);
209
222
  _loadedScenes.Add(sceneName);
210
- if (isDebug) Debug.Log($"Scene loaded: {sceneName}");
211
- }
212
- catch (Exception e)
213
- {
214
- if (isDebug) Debug.LogError($"Error loading scene {sceneName}: {e}");
215
223
  }
216
224
  finally
217
225
  {
@@ -226,11 +234,6 @@ namespace jeanf.scenemanagement
226
234
  var unloadOperation = SceneManager.UnloadSceneAsync(sceneName);
227
235
  await unloadOperation.ToUniTask(cancellationToken: cancellationToken);
228
236
  _loadedScenes.Remove(sceneName);
229
- if (isDebug) Debug.Log($"Scene unloaded: {sceneName}");
230
- }
231
- catch (Exception e)
232
- {
233
- if (isDebug) Debug.LogError($"Error unloading scene {sceneName}: {e}");
234
237
  }
235
238
  finally
236
239
  {