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.
- package/Runtime/AdditiveLoading/Editor/SpawnPosEditor.cs +55 -0
- package/Runtime/AdditiveLoading/Editor/SpawnPosEditor.cs.meta +3 -0
- package/Runtime/AdditiveLoading/Editor.meta +8 -0
- package/Runtime/AdditiveLoading/Region.cs +1 -50
- package/Runtime/AdditiveLoading/SceneLoader.cs +39 -36
- package/Runtime/DynamicLoading/Editor/VolumeConnectivityVisualizer.cs +797 -0
- package/Runtime/DynamicLoading/Editor/VolumeConnectivityVisualizer.cs.meta +2 -0
- package/Runtime/DynamicLoading/Editor.meta +8 -0
- package/Runtime/DynamicLoading/RegionConnectivity.cs +47 -0
- package/Runtime/DynamicLoading/RegionConnectivity.cs.meta +2 -0
- package/Runtime/DynamicLoading/RegionConnectivityAuthoring.cs +83 -0
- package/Runtime/DynamicLoading/RegionConnectivityAuthoring.cs.meta +2 -0
- package/Runtime/DynamicLoading/VolumeSystem.cs +52 -54
- package/Samples/Example/RegionConnectivity.asset +25 -0
- package/Samples/Example/RegionConnectivity.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_00/Region_00_Volumes.prefab +8 -8
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_1.asset → Zone_01.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_2.asset → Zone_02.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/Zone_03.asset +21 -0
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_4.asset → Zone_04.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_5.asset → Zone_05.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_6.asset → Zone_06.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_7.asset → Zone_07.asset} +1 -1
- package/Samples/Example/RegionData/Region_00/Zones/{Zone_8.asset → Zone_08.asset} +1 -1
- package/Samples/Example/RegionData/Region_01/Region_01.asset +43 -0
- package/Samples/Example/RegionData/Region_01/Region_01.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Region_01_Volumes.prefab +409 -0
- package/Samples/Example/RegionData/Region_01/Region_01_Volumes.prefab.meta +7 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_1.asset +25 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_1.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_2.asset +25 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/Scenario_2.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_1.asset +16 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_1.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_2.asset +16 -0
- package/Samples/Example/RegionData/Region_01/Scenarios/ZoneOverride_2.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Scenarios.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_11.asset +21 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_11.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_12.asset +22 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_12.asset.meta +8 -0
- package/Samples/Example/RegionData/{Region_00/Zones/Zone_3.asset → Region_01/Zones/Zone_13.asset} +3 -3
- package/Samples/Example/RegionData/Region_01/Zones/Zone_13.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_14.asset +21 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_14.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_15.asset +22 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_15.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_16.asset +23 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_16.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_17.asset +21 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_17.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_18.asset +21 -0
- package/Samples/Example/RegionData/Region_01/Zones/Zone_18.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_01/Zones.meta +8 -0
- package/Samples/Example/RegionData/Region_01.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Region_02.asset +43 -0
- package/Samples/Example/RegionData/Region_02/Region_02.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Region_02_Volumes.prefab +409 -0
- package/Samples/Example/RegionData/Region_02/Region_02_Volumes.prefab.meta +7 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_1.asset +25 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_1.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_2.asset +25 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/Scenario_2.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_1.asset +16 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_1.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_2.asset +16 -0
- package/Samples/Example/RegionData/Region_02/Scenarios/ZoneOverride_2.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Scenarios.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_21.asset +21 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_21.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_22.asset +22 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_22.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_23.asset +22 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_23.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_24.asset +21 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_24.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_25.asset +22 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_25.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_26.asset +23 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_26.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_27.asset +21 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_27.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_28.asset +21 -0
- package/Samples/Example/RegionData/Region_02/Zones/Zone_28.asset.meta +8 -0
- package/Samples/Example/RegionData/Region_02/Zones.meta +8 -0
- package/Samples/Example/RegionData/Region_02.meta +8 -0
- package/Samples/Example/Scenes/00.meta +8 -0
- package/Samples/Example/Scenes/01/1.unity +375 -0
- package/Samples/Example/Scenes/01/1.unity.meta +7 -0
- package/Samples/Example/Scenes/01/2.unity +484 -0
- package/Samples/Example/Scenes/01/2.unity.meta +7 -0
- package/Samples/Example/Scenes/01/3.unity +702 -0
- package/Samples/Example/Scenes/01/3.unity.meta +7 -0
- package/Samples/Example/Scenes/01/4.unity +375 -0
- package/Samples/Example/Scenes/01/4.unity.meta +7 -0
- package/Samples/Example/Scenes/01/5.unity +375 -0
- package/Samples/Example/Scenes/01/5.unity.meta +7 -0
- package/Samples/Example/Scenes/01/6.unity +484 -0
- package/Samples/Example/Scenes/01/6.unity.meta +7 -0
- package/Samples/Example/Scenes/01/7.unity +484 -0
- package/Samples/Example/Scenes/01/7.unity.meta +7 -0
- package/Samples/Example/Scenes/01/8.unity +375 -0
- package/Samples/Example/Scenes/01/8.unity.meta +7 -0
- package/Samples/Example/Scenes/01.meta +8 -0
- package/Samples/Example/Scenes/02/1.unity +375 -0
- package/Samples/Example/Scenes/02/1.unity.meta +7 -0
- package/Samples/Example/Scenes/02/2.unity +484 -0
- package/Samples/Example/Scenes/02/2.unity.meta +7 -0
- package/Samples/Example/Scenes/02/3.unity +702 -0
- package/Samples/Example/Scenes/02/3.unity.meta +7 -0
- package/Samples/Example/Scenes/02/4.unity +375 -0
- package/Samples/Example/Scenes/02/4.unity.meta +7 -0
- package/Samples/Example/Scenes/02/5.unity +375 -0
- package/Samples/Example/Scenes/02/5.unity.meta +7 -0
- package/Samples/Example/Scenes/02/6.unity +484 -0
- package/Samples/Example/Scenes/02/6.unity.meta +7 -0
- package/Samples/Example/Scenes/02/7.unity +484 -0
- package/Samples/Example/Scenes/02/7.unity.meta +7 -0
- package/Samples/Example/Scenes/02/8.unity +375 -0
- package/Samples/Example/Scenes/02/8.unity.meta +7 -0
- package/Samples/Example/Scenes/02.meta +8 -0
- package/Samples/Example/Scenes/Main.unity +0 -119
- package/Samples/Example/Scenes/World.unity +1874 -198
- package/package.json +1 -1
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_1.asset.meta → Zone_01.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_2.asset.meta → Zone_02.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_3.asset.meta → Zone_03.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_4.asset.meta → Zone_04.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_5.asset.meta → Zone_05.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_6.asset.meta → Zone_06.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_7.asset.meta → Zone_07.asset.meta} +0 -0
- /package/Samples/Example/RegionData/Region_00/Zones/{Zone_8.asset.meta → Zone_08.asset.meta} +0 -0
- /package/Samples/Example/Scenes/{1.unity → 00/1.unity} +0 -0
- /package/Samples/Example/Scenes/{1.unity.meta → 00/1.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{2.unity → 00/2.unity} +0 -0
- /package/Samples/Example/Scenes/{2.unity.meta → 00/2.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{3.unity → 00/3.unity} +0 -0
- /package/Samples/Example/Scenes/{3.unity.meta → 00/3.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{4.unity → 00/4.unity} +0 -0
- /package/Samples/Example/Scenes/{4.unity.meta → 00/4.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{5.unity → 00/5.unity} +0 -0
- /package/Samples/Example/Scenes/{5.unity.meta → 00/5.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{6.unity → 00/6.unity} +0 -0
- /package/Samples/Example/Scenes/{6.unity.meta → 00/6.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{7.unity → 00/7.unity} +0 -0
- /package/Samples/Example/Scenes/{7.unity.meta → 00/7.unity.meta} +0 -0
- /package/Samples/Example/Scenes/{8.unity → 00/8.unity} +0 -0
- /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
|
|
@@ -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
|
-
|
|
24
|
-
|
|
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
|
|
30
|
+
private readonly struct SceneOperation
|
|
30
31
|
{
|
|
31
|
-
public SceneOperationType Type
|
|
32
|
-
public string 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.
|
|
89
|
+
while (_loadQueue.TryDequeue(out _)) { }
|
|
79
90
|
|
|
80
|
-
|
|
91
|
+
_scenesToUnload.Clear();
|
|
92
|
+
foreach (var sceneName in _loadedScenes)
|
|
81
93
|
{
|
|
82
|
-
|
|
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
|
-
|
|
132
|
+
_operationBuffer.Clear();
|
|
117
133
|
|
|
118
|
-
while (
|
|
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 (
|
|
143
|
+
if (_operationBuffer.Count > 0)
|
|
130
144
|
{
|
|
131
|
-
await UniTask.WhenAll(
|
|
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
|
-
|
|
178
|
+
_operationBuffer.Clear();
|
|
166
179
|
|
|
167
|
-
while (
|
|
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 (
|
|
189
|
+
if (_operationBuffer.Count > 0)
|
|
179
190
|
{
|
|
180
|
-
await UniTask.WhenAll(
|
|
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
|
-
|
|
207
|
-
loadOperation
|
|
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
|
{
|