【问题标题】:How to remove deleted scenes from build settings如何从构建设置中删除已删除的场景
【发布时间】:2020-09-30 19:02:39
【问题描述】:

添加场景构建设置然后删除它们后,删除的场景仍然显示。问题是它影响场景数。即使它说已删除,它们都显示为有效场景。将它们全部突出显示并选择删除选择没有任何作用。

EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
Debug.Log(scenes.Length);

此日志语句返回所有场景,包括已删除的场景。

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    你可以过滤掉所有EditorBuildSettingsSceneFile.Exists(scenePath) = false 喜欢

    using System.IO;
    using System.Linq;
    using UnityEditor;
    
    public static class EditorBuildSettingsTools
    {
        [MenuItem("CustomBuildTools/RemoveDeletedScenes")]
        public static void CleanUpDeletedScenes()
        {
            var currentScenes = EditorBuildSettings.scenes;
            var filteredScenes = currentScenes.Where(ebss => File.Exists(ebss.path)).ToArray();
            EditorBuildSettings.scenes = filteredScenes;
        }
    }
    

    将其放入名为 Editor 的文件夹中,以便将其从构建中排除,例如喜欢

    Assets/Editor/EditorBuildSettingsTools.cs
    

    【讨论】:

      【解决方案2】:

      derhug 的解决方案似乎不起作用。例如,当您通过包含场景的脚本删除文件夹并调用方法CleanUpDeletedScenes 时,文件场景存在于同一帧中,因为它在缓存中。我建议使用AssetDatabase.LoadAssetAtPath的方法来检查是否存在场景文件:

      public static void CleanUpDeletedScenes() {
         currentScenes = EditorBuildSettings.scenes;
         var filteredScenes = currentScenes.Where(ebss => AssetDatabase.LoadAssetAtPath(ebss.path, typeof(SceneAsset)) != null).ToArray();
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-02-02
        • 1970-01-01
        • 2015-04-28
        • 2023-03-12
        • 2015-01-08
        • 1970-01-01
        • 1970-01-01
        • 2013-08-23
        相关资源
        最近更新 更多