Skip to content

Commit 41bed90

Browse files
committed
Simplify BuildIndex calculation
1 parent e6901a2 commit 41bed90

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#if UNITY_EDITOR
44
using UnityEditor;
55
#endif
6+
using UnityEngine.SceneManagement;
67

78
namespace Toolbox.Serialization
89
{
@@ -40,37 +41,30 @@ internal static void ConfirmCache()
4041
internal static void RefreshCache()
4142
{
4243
cachedScenes.Clear();
43-
var buildIndex = -1;
4444
foreach (var scene in EditorBuildSettings.scenes)
4545
{
46-
if (string.IsNullOrEmpty(scene.path))
46+
var path = scene.path;
47+
if (string.IsNullOrEmpty(path))
4748
{
4849
continue;
4950
}
5051

51-
var sceneAsset = EditorGUIUtility.Load(scene.path) as SceneAsset;
52+
var sceneAsset = EditorGUIUtility.Load(path) as SceneAsset;
5253
if (sceneAsset == null)
5354
{
5455
continue;
5556
}
5657

57-
var sceneIndex = InvalidSceneIndex;
58-
if (scene.enabled)
59-
{
60-
buildIndex++;
61-
sceneIndex = buildIndex;
62-
}
63-
6458
if (cachedScenes.ContainsKey(sceneAsset))
6559
{
6660
continue;
6761
}
6862

6963
cachedScenes.Add(sceneAsset, new SceneData()
7064
{
71-
BuildIndex = sceneIndex,
65+
BuildIndex = SceneUtility.GetBuildIndexByScenePath(path),
7266
SceneName = sceneAsset.name,
73-
ScenePath = scene.path
67+
ScenePath = path
7468
});
7569
}
7670
}

0 commit comments

Comments
 (0)