fr.jeanf.scenemanagement 0.6.21 → 0.6.23
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.
|
@@ -12,23 +12,18 @@ namespace jeanf.scenemanagement
|
|
|
12
12
|
// Public getter for the scene name
|
|
13
13
|
public string SceneName => sceneName;
|
|
14
14
|
|
|
15
|
+
public SceneReference(string sceneName)
|
|
16
|
+
{
|
|
17
|
+
this.sceneName = sceneName;
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
#if UNITY_EDITOR
|
|
16
|
-
//
|
|
17
|
-
public void
|
|
21
|
+
// Méthode pour forcer la mise à jour du nom
|
|
22
|
+
public void UpdateSceneName()
|
|
18
23
|
{
|
|
19
|
-
|
|
20
|
-
if (sceneAsset != null)
|
|
24
|
+
if (sceneAsset != null && sceneAsset is SceneAsset)
|
|
21
25
|
{
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
sceneName = sceneAsset.name; // Extract scene name from the asset
|
|
25
|
-
}
|
|
26
|
-
else
|
|
27
|
-
{
|
|
28
|
-
Debug.LogWarning("Assigned object is not a SceneAsset!");
|
|
29
|
-
sceneAsset = null; // Reset if it's not a valid SceneAsset
|
|
30
|
-
sceneName = "";
|
|
31
|
-
}
|
|
26
|
+
sceneName = sceneAsset.name;
|
|
32
27
|
}
|
|
33
28
|
else
|
|
34
29
|
{
|
|
@@ -42,23 +37,28 @@ namespace jeanf.scenemanagement
|
|
|
42
37
|
[CustomPropertyDrawer(typeof(SceneReference))]
|
|
43
38
|
public class SceneReferenceDrawer : PropertyDrawer
|
|
44
39
|
{
|
|
45
|
-
|
|
46
40
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
47
41
|
{
|
|
48
42
|
EditorGUI.BeginProperty(position, label, property);
|
|
49
43
|
|
|
50
|
-
// Get the serialized properties
|
|
51
44
|
SerializedProperty sceneAssetProp = property.FindPropertyRelative("sceneAsset");
|
|
52
45
|
SerializedProperty sceneNameProp = property.FindPropertyRelative("sceneName");
|
|
53
46
|
|
|
54
|
-
//
|
|
47
|
+
// Vérifier si le nom a changé
|
|
48
|
+
if (sceneAssetProp.objectReferenceValue != null)
|
|
49
|
+
{
|
|
50
|
+
string currentName = sceneAssetProp.objectReferenceValue.name;
|
|
51
|
+
if (sceneNameProp.stringValue != currentName)
|
|
52
|
+
{
|
|
53
|
+
sceneNameProp.stringValue = currentName;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
55
57
|
position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);
|
|
58
|
+
|
|
56
59
|
EditorGUI.BeginChangeCheck();
|
|
57
|
-
|
|
58
|
-
// Restrict the object field to accept only SceneAssets
|
|
59
60
|
Object sceneAsset = EditorGUI.ObjectField(position, sceneAssetProp.objectReferenceValue, typeof(SceneAsset), false);
|
|
60
61
|
|
|
61
|
-
// If the scene asset changes, update the scene name
|
|
62
62
|
if (EditorGUI.EndChangeCheck())
|
|
63
63
|
{
|
|
64
64
|
sceneAssetProp.objectReferenceValue = sceneAsset;
|
|
@@ -68,6 +68,80 @@ namespace jeanf.scenemanagement
|
|
|
68
68
|
EditorGUI.EndProperty();
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
#endif
|
|
72
71
|
|
|
72
|
+
// AssetPostprocessor pour détecter les renommages de scènes
|
|
73
|
+
public class SceneReferenceAssetPostprocessor : AssetPostprocessor
|
|
74
|
+
{
|
|
75
|
+
private static void OnPostprocessAllAssets(
|
|
76
|
+
string[] importedAssets,
|
|
77
|
+
string[] deletedAssets,
|
|
78
|
+
string[] movedAssets,
|
|
79
|
+
string[] movedFromAssetPaths)
|
|
80
|
+
{
|
|
81
|
+
bool sceneRenamed = false;
|
|
82
|
+
|
|
83
|
+
// Vérifier si des scènes ont été déplacées/renommées
|
|
84
|
+
for (int i = 0; i < movedAssets.Length; i++)
|
|
85
|
+
{
|
|
86
|
+
if (movedAssets[i].EndsWith(".unity"))
|
|
87
|
+
{
|
|
88
|
+
sceneRenamed = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (sceneRenamed)
|
|
94
|
+
{
|
|
95
|
+
// Forcer la mise à jour de tous les objets contenant des SceneReference
|
|
96
|
+
RefreshAllSceneReferences();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private static void RefreshAllSceneReferences()
|
|
101
|
+
{
|
|
102
|
+
// Trouver tous les MonoBehaviour et ScriptableObject dans le projet
|
|
103
|
+
string[] guids = AssetDatabase.FindAssets("t:MonoBehaviour t:ScriptableObject");
|
|
104
|
+
|
|
105
|
+
foreach (string guid in guids)
|
|
106
|
+
{
|
|
107
|
+
string path = AssetDatabase.GUIDToAssetPath(guid);
|
|
108
|
+
Object obj = AssetDatabase.LoadAssetAtPath<Object>(path);
|
|
109
|
+
|
|
110
|
+
if (obj != null)
|
|
111
|
+
{
|
|
112
|
+
SerializedObject serializedObject = new SerializedObject(obj);
|
|
113
|
+
SerializedProperty property = serializedObject.GetIterator();
|
|
114
|
+
bool hasChanges = false;
|
|
115
|
+
|
|
116
|
+
while (property.NextVisible(true))
|
|
117
|
+
{
|
|
118
|
+
if (property.type == "SceneReference")
|
|
119
|
+
{
|
|
120
|
+
SerializedProperty sceneAssetProp = property.FindPropertyRelative("sceneAsset");
|
|
121
|
+
SerializedProperty sceneNameProp = property.FindPropertyRelative("sceneName");
|
|
122
|
+
|
|
123
|
+
if (sceneAssetProp != null && sceneAssetProp.objectReferenceValue != null)
|
|
124
|
+
{
|
|
125
|
+
string currentName = sceneAssetProp.objectReferenceValue.name;
|
|
126
|
+
if (sceneNameProp.stringValue != currentName)
|
|
127
|
+
{
|
|
128
|
+
sceneNameProp.stringValue = currentName;
|
|
129
|
+
hasChanges = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (hasChanges)
|
|
136
|
+
{
|
|
137
|
+
serializedObject.ApplyModifiedProperties();
|
|
138
|
+
EditorUtility.SetDirty(obj);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
AssetDatabase.SaveAssets();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
#endif
|
|
73
147
|
}
|
|
@@ -147,8 +147,9 @@ namespace jeanf.scenemanagement
|
|
|
147
147
|
|
|
148
148
|
var tempZoneList = new NativeList<FixedString128Bytes>(100, Allocator.Temp);
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
for (var index = 0; index < precomputedBuffer.Length; index++)
|
|
151
151
|
{
|
|
152
|
+
var entry = precomputedBuffer[index];
|
|
152
153
|
switch (entry)
|
|
153
154
|
{
|
|
154
155
|
case { isZoneRegionMapping: true, zoneId: { IsEmpty: false }, regionId: { IsEmpty: false } }:
|
|
@@ -170,8 +171,9 @@ namespace jeanf.scenemanagement
|
|
|
170
171
|
[BurstCompile]
|
|
171
172
|
private void BuildPrecomputedCheckableZones(ref SystemState state, DynamicBuffer<PrecomputedVolumeDataBuffer> precomputedBuffer)
|
|
172
173
|
{
|
|
173
|
-
|
|
174
|
+
for (var index = 0; index < precomputedBuffer.Length; index++)
|
|
174
175
|
{
|
|
176
|
+
var entry = precomputedBuffer[index];
|
|
175
177
|
if (!entry.isHeader || entry.primaryZoneId.IsEmpty) continue;
|
|
176
178
|
var tempList = new NativeList<FixedString128Bytes>(entry.count + _landingZones.Count, Allocator.Temp);
|
|
177
179
|
|
|
@@ -191,11 +193,12 @@ namespace jeanf.scenemanagement
|
|
|
191
193
|
{
|
|
192
194
|
tempList.Add(landingEnumerator.Current);
|
|
193
195
|
}
|
|
196
|
+
|
|
194
197
|
landingEnumerator.Dispose();
|
|
195
198
|
|
|
196
199
|
var checkableArray = tempList.ToArray(Allocator.Persistent);
|
|
197
200
|
tempList.Dispose();
|
|
198
|
-
|
|
201
|
+
|
|
199
202
|
_precomputedCheckableZones.TryAdd(entry.primaryZoneId, checkableArray);
|
|
200
203
|
}
|
|
201
204
|
}
|
|
@@ -207,8 +210,9 @@ namespace jeanf.scenemanagement
|
|
|
207
210
|
|
|
208
211
|
if (currentZone.IsEmpty)
|
|
209
212
|
{
|
|
210
|
-
|
|
213
|
+
for (var index = 0; index < _allZones.Length; index++)
|
|
211
214
|
{
|
|
215
|
+
var t = _allZones[index];
|
|
212
216
|
_checkableZoneIds.Add(t);
|
|
213
217
|
}
|
|
214
218
|
|
|
@@ -217,8 +221,9 @@ namespace jeanf.scenemanagement
|
|
|
217
221
|
|
|
218
222
|
if (_precomputedCheckableZones.TryGetValue(currentZone, out var checkableArray))
|
|
219
223
|
{
|
|
220
|
-
|
|
224
|
+
for (var index = 0; index < checkableArray.Length; index++)
|
|
221
225
|
{
|
|
226
|
+
var t = checkableArray[index];
|
|
222
227
|
_checkableZoneIds.Add(t);
|
|
223
228
|
}
|
|
224
229
|
}
|
|
@@ -363,17 +368,21 @@ namespace jeanf.scenemanagement
|
|
|
363
368
|
entities.Dispose();
|
|
364
369
|
levelInfos.Dispose();
|
|
365
370
|
|
|
366
|
-
|
|
371
|
+
for (var index = 0; index < _toLoadList.Length; index++)
|
|
367
372
|
{
|
|
373
|
+
var toLoad = _toLoadList[index];
|
|
368
374
|
var streamingData = toLoad.Item2;
|
|
369
|
-
streamingData.runtimeEntity =
|
|
375
|
+
streamingData.runtimeEntity =
|
|
376
|
+
SceneSystem.LoadSceneAsync(state.WorldUnmanaged, streamingData.sceneReference);
|
|
370
377
|
state.EntityManager.SetComponentData(toLoad.Item1, streamingData);
|
|
371
378
|
}
|
|
372
379
|
|
|
373
|
-
|
|
380
|
+
for (var index = 0; index < _toUnloadList.Length; index++)
|
|
374
381
|
{
|
|
382
|
+
var toUnload = _toUnloadList[index];
|
|
375
383
|
var streamingData = toUnload.Item2;
|
|
376
|
-
SceneSystem.UnloadScene(state.WorldUnmanaged, streamingData.runtimeEntity,
|
|
384
|
+
SceneSystem.UnloadScene(state.WorldUnmanaged, streamingData.runtimeEntity,
|
|
385
|
+
SceneSystem.UnloadParameters.DestroyMetaEntities);
|
|
377
386
|
streamingData.runtimeEntity = Entity.Null;
|
|
378
387
|
state.EntityManager.SetComponentData(toUnload.Item1, streamingData);
|
|
379
388
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fr.jeanf.scenemanagement",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.23",
|
|
4
4
|
"displayName": "Scene Management",
|
|
5
5
|
"description": "This package contains two scene loading system, one is additive, the other is to load subscenes. \nBoth system are living side-by-side.\nThe dynamic systems handles the loading of all static content (environment) using subscenes.\nThe additive system loads scene additively depending on zone & region and upon scenario load/unload requests. Each region or scenario can have dependency that will remain loaded until either a region or a scenario became irrelevant.",
|
|
6
6
|
"unity": "2021.3",
|