Skip to content

Commit f6185fd

Browse files
committed
Fix displaying SceneDetails for disabled scenes; fix minor issues while loading empty SceneAssets
1 parent 0386bd3 commit f6185fd

3 files changed

Lines changed: 31 additions & 20 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Regular/SerializedSceneDrawer.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,24 @@ public static SceneData GetSceneData(SerializedProperty property)
103103
var sceneAsset = property.objectReferenceValue as SceneAsset;
104104
var scenePath = AssetDatabase.GetAssetPath(sceneAsset);
105105
var sceneGuid = AssetDatabase.AssetPathToGUID(scenePath);
106+
var sceneIndex = -1;
106107
for (var i = 0; i < EditorBuildSettings.scenes.Length; i++)
107108
{
108109
var sceneSettings = EditorBuildSettings.scenes[i];
110+
var isEnabled = sceneSettings.enabled;
111+
if (isEnabled)
112+
{
113+
sceneIndex++;
114+
}
115+
109116
var guid = sceneSettings.guid;
110117
if (guid.Equals(new GUID(sceneGuid)))
111118
{
112-
sceneData.index = i;
113-
sceneData.enabled = sceneSettings.enabled;
119+
sceneData.index = isEnabled ? sceneIndex : -1;
120+
sceneData.enabled = isEnabled;
114121
sceneData.guid = guid;
115122
sceneData.inBuild = true;
123+
break;
116124
}
117125
}
118126

Assets/Editor Toolbox/Runtime/Serialization/SceneSerializationUtility.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
#if UNITY_EDITOR
33
using UnityEditor;
44
#endif
5-
using UnityEngine;
65

76
namespace Toolbox.Serialization
87
{
98
internal static class SceneSerializationUtility
109
{
1110
#if UNITY_EDITOR
12-
private readonly static Dictionary<SceneAsset, SceneData> cachedScenes = new Dictionary<SceneAsset, SceneData>();
11+
private static readonly Dictionary<SceneAsset, SceneData> cachedScenes = new Dictionary<SceneAsset, SceneData>();
1312
private static bool isInitialized;
1413

1514

@@ -21,18 +20,25 @@ private static void Initialize()
2120
return;
2221
}
2322

24-
UnityEngine.Debug.Log("INIT");
25-
UpdateAllIndexes();
26-
27-
EditorBuildSettings.sceneListChanged -= UpdateAllIndexes;
28-
EditorBuildSettings.sceneListChanged += UpdateAllIndexes;
23+
ConfirmCache();
24+
EditorBuildSettings.sceneListChanged -= RefreshCache;
25+
EditorBuildSettings.sceneListChanged += RefreshCache;
2926
isInitialized = true;
3027
}
3128

32-
private static void UpdateAllIndexes()
29+
private static void ConfirmCache()
30+
{
31+
//NOTE: refresh data only if the cache is empty,
32+
//it probably means that it's our first time when we are updating it
33+
if (cachedScenes.Count == 0)
34+
{
35+
RefreshCache();
36+
}
37+
}
38+
39+
private static void RefreshCache()
3340
{
3441
cachedScenes.Clear();
35-
UnityEngine.Debug.Log("UPDATE INDEXES");
3642
var buildIndex = -1;
3743
foreach (var scene in EditorBuildSettings.scenes)
3844
{
@@ -42,7 +48,7 @@ private static void UpdateAllIndexes()
4248
}
4349

4450
buildIndex++;
45-
var sceneAsset = AssetDatabase.LoadAssetAtPath<SceneAsset>(scene.path);
51+
var sceneAsset = EditorGUIUtility.Load(scene.path) as SceneAsset;
4652
if (sceneAsset != null)
4753
{
4854
cachedScenes.Add(sceneAsset, new SceneData()
@@ -58,6 +64,7 @@ private static void UpdateAllIndexes()
5864

5965
public static bool TryGetSceneData(SceneAsset sceneAsset, out SceneData data)
6066
{
67+
ConfirmCache();
6168
if (!sceneAsset || !cachedScenes.TryGetValue(sceneAsset, out data))
6269
{
6370
data = null;

Assets/Editor Toolbox/Runtime/Serialization/SerializedScene.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
23
using Toolbox.Serialization;
4+
35
#if UNITY_EDITOR
46
using UnityEditor;
57
#endif
@@ -26,30 +28,24 @@ public class SerializedScene : ISerializationCallbackReceiver
2628

2729
void ISerializationCallbackReceiver.OnBeforeSerialize()
2830
{
29-
UnityEngine.Debug.Log("BEFORE");
3031
UpdateProperties();
3132
}
3233

3334
void ISerializationCallbackReceiver.OnAfterDeserialize()
34-
{
35-
UnityEngine.Debug.Log("AFTER");
36-
UpdateProperties();
37-
}
35+
{ }
3836

3937

4038
private void UpdateProperties()
4139
{
42-
#if UNITY_EDITOR
40+
#if UNITY_EDITOR
4341
if (SceneSerializationUtility.TryGetSceneData(sceneReference, out var sceneData))
4442
{
45-
UnityEngine.Debug.Log("UPDATE");
4643
SceneName = sceneData.SceneName;
4744
ScenePath = sceneData.ScenePath;
4845
BuildIndex = sceneData.BuildIndex;
4946
}
5047
else
5148
{
52-
UnityEngine.Debug.Log("RESET");
5349
SceneName = string.Empty;
5450
ScenePath = string.Empty;
5551
BuildIndex = -1;

0 commit comments

Comments
 (0)