cz.xprees.scene-management 1.0.2 → 1.0.3

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.
@@ -0,0 +1,19 @@
1
+ using Xprees.SceneManagement.ScriptableObjects;
2
+
3
+ namespace Xprees.SceneManagement.Extensions
4
+ {
5
+ public static class SceneSOExtensions
6
+ {
7
+ /// Thread-safe method to set the IsBeingProcessed property of the SceneSO
8
+ public static void SetAsProcessed(this SceneSO scene, bool isProcessed)
9
+ {
10
+ lock (scene) scene.IsBeingProcessed = isProcessed;
11
+ }
12
+
13
+ /// Thread-safe method to set the IsLoaded property of the SceneSO
14
+ public static void SetAsLoaded(this SceneSO scene, bool isLoaded)
15
+ {
16
+ lock (scene) scene.IsLoaded = isLoaded;
17
+ }
18
+ }
19
+ }
@@ -0,0 +1,3 @@
1
+ fileFormatVersion: 2
2
+ guid: 85ed896f5c9f4e8f8bcd0775005d0606
3
+ timeCreated: 1734784842
@@ -62,7 +62,7 @@ namespace Xprees.SceneManagement.Initialization
62
62
 
63
63
  private async UniTask InitializeHandlers(CancellationToken cancellationToken)
64
64
  {
65
- var initTasks = initializationHandlers
65
+ var initTasks = initializationHandlers // Initialize all handlers - some need to initialize to decide if they are active
66
66
  .Select(handler => handler.InitializeHandlerAsync(cancellationToken))
67
67
  .ToList();
68
68
 
@@ -97,10 +97,8 @@ namespace Xprees.SceneManagement.Initialization
97
97
  var managersScene = await managersSceneDataReference.LoadAssetAsync<SceneSO>()
98
98
  .ToUniTask(cancellationToken: cancellationToken);
99
99
 
100
- var managersSceneInstance = await managersScene.sceneReference.LoadSceneAsync(LoadSceneMode.Additive, true)
101
- .ToUniTask(cancellationToken: cancellationToken);
102
100
  // Set as active to make sure if there are any created objects they are in the right scene and initialization scene
103
- managersSceneInstance.SetAsActiveScene();
101
+ await LoadSceneIfNotProcessed(managersScene, true, LoadSceneMode.Additive, cancellationToken);
104
102
 
105
103
  await UniTask.WaitUntil(IsManagersSceneReady, cancellationToken: cancellationToken);
106
104
  return;
@@ -118,5 +116,24 @@ namespace Xprees.SceneManagement.Initialization
118
116
  $"Only {ActiveHandlers.Count()} are active.");
119
117
  }
120
118
  }
119
+
120
+ private async UniTask LoadSceneIfNotProcessed(
121
+ SceneSO scene,
122
+ bool setActive = false,
123
+ LoadSceneMode loadMode = LoadSceneMode.Additive,
124
+ CancellationToken token = default
125
+ )
126
+ {
127
+ if (scene.IsBeingProcessed || scene.IsLoaded) return;
128
+
129
+ scene.SetAsProcessed(true);
130
+ var sceneInstance = await scene.sceneReference
131
+ .LoadSceneAsync(loadMode, true)
132
+ .ToUniTask(cancellationToken: token);
133
+
134
+ if (setActive) sceneInstance.SetAsActiveScene();
135
+
136
+ scene.SetAsProcessed(false);
137
+ }
121
138
  }
122
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cz.xprees.scene-management",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "displayName": "Scene Management",
5
5
  "description": "Scene Management package for multi-scene workflow. Adds wrapper for addressable scenes and provides event-driven scene loader.",
6
6
  "unity": "2021.3",