/// <summary>
    /// Syncronizes the build settings so that they resemble the list of scenes which are in the currently
    /// active scene configuration.
    /// </summary>
    public static void SyncWithBuildSettings(SMSceneConfigurationBase configuration, Dictionary <string, string> lookup)
    {
        List <EditorBuildSettingsScene> newScenes = new List <EditorBuildSettingsScene>();

        if (!String.IsNullOrEmpty(configuration.firstScreen))
        {
            if (lookup.ContainsKey(configuration.firstScreen))
            {
                newScenes.Add(new EditorBuildSettingsScene(lookup[configuration.firstScreen], true));
            }
        }

        foreach (string screen in configuration.screens)
        {
            if (screen != configuration.firstScreen && lookup.ContainsKey(screen))
            {
                newScenes.Add(new EditorBuildSettingsScene(lookup[screen], true));
            }
        }

        foreach (string level in configuration.levels)
        {
            if (level != configuration.firstScreen && lookup.ContainsKey(level))
            {
                newScenes.Add(new EditorBuildSettingsScene(lookup[level], true));
            }
        }

        EditorBuildSettings.scenes = newScenes.ToArray();
    }
Esempio n. 2
0
    public static void VerifyConfigurations()                    // 修改配置文件
    {
        bool successful = true;
        List <SMSceneConfigurationBase> configurations = SMSceneConfigurationUtil.FindConfigurations();
        Dictionary <string, string>     lookup         = SMSceneConfigurationUtil.FindAllUnityScene();

        HashSet <string> validScenes = new HashSet <string>();

        foreach (string scene in lookup.Keys)
        {
            validScenes.Add(scene);
        }

        SMSceneConfigurationBase activeConfiguration = null;
        int activeConfigurations = 0;

        foreach (SMSceneConfigurationBase configuration in configurations)
        {
            successful &= configuration.IsValid(validScenes);

            if (configuration.activeConfiguration)
            {
                activeConfigurations++;
                activeConfiguration = configuration;
            }
        }

        if (activeConfigurations == 0)
        {
            Debug.LogWarning("Currently no scene configuration is active. This will lead to issues when your game is " +
                             "started as Scene Manager doesn't know which scene configuration it should load. Please activate one " +
                             "of your scene configurations. To activate a scene configuration, select it in the project view " +
                             "and then click on the 'Activate' button in the inspector.");
            successful = false;
        }
        else if (activeConfigurations > 1)
        {
            Debug.LogWarning(
                "Currently more than one scene configuration is active. This will lead to issues when your game is " +
                "started as Scene Manager doesn't know which scene configuration it should load. Please select the configuration you " +
                "want to keep active in the project view and then press the 'Fix Configuration' button in the inspector. This will deactivate all other " +
                "scene configurations. To activate another scene configuration, select it in the project view " +
                "and then click on the 'Activate' button in the inspector.");
            successful = false;
        }
        else
        {
            SMSceneConfigurationUtil.SyncWithBuildSettings(activeConfiguration, lookup);
        }

        if (successful)
        {
            Debug.Log("All your scene configurations are valid.");
        }
    }
    /// <summary>
    /// Ensures that the given configuration is activated. If it is already the active configuration this method
    /// will do nothing. Otherwise it will activate the given configuration and deactivate any other active
    /// configuration.
    /// </summary>
    /// <param name="configurationToBeActivated">
    /// A <see cref="SMSceneConfigurationBase"/> that is to be activated.
    /// </param>
    public static void EnsureActiveConfiguration(SMSceneConfigurationBase configurationToBeActivated, bool registerUndo)
    {
        List <SMSceneConfigurationBase> allConfigurations = FindConfigurations();

        if (registerUndo)
        {
            CUUndoUtility.RegisterUndo(allConfigurations.ToArray(), "Activate scene configuration");
        }

        foreach (SMSceneConfigurationBase configuration in allConfigurations)
        {
            configuration.activeConfiguration = configuration == configurationToBeActivated;
            EditorUtility.SetDirty(configuration);
        }
    }
Esempio n. 4
0
    /// <summary>
    /// 返回当前项目中的所有场景配置
    /// </summary>
    public static List <SMSceneConfigurationBase> FindConfigurations()
    {
        List <SMSceneConfigurationBase> allConfigurations = new List <SMSceneConfigurationBase>();

        string[] assetFullPaths = Directory.GetFiles(Application.dataPath, "*.asset", SearchOption.AllDirectories);

        foreach (string fullPath in assetFullPaths)
        {
            string assetPath = MyAssetUtil.GetAssetsBackPath(fullPath);
            SMSceneConfigurationBase configuration = AssetDatabase.LoadAssetAtPath(assetPath, typeof(SMSceneConfigurationBase)) as SMSceneConfigurationBase;
            if (configuration != null)
            {
                allConfigurations.Add(configuration);
            }
        }
        return(allConfigurations);
    }
    /// <summary>
    /// Returns all scene configuration in the current project
    /// </summary>
    public static List <SMSceneConfigurationBase> FindConfigurations()
    {
        DirectoryInfo directory     = new DirectoryInfo(Application.dataPath);
        string        directoryPath = directory.Parent.FullName;

        FileInfo[] files = directory.GetFiles("*.asset", SearchOption.AllDirectories);
        List <SMSceneConfigurationBase> allConfigurations = new List <SMSceneConfigurationBase>();

        foreach (FileInfo file in files)
        {
            string filePath = file.FullName.Substring(directoryPath.Length + 1);
            SMSceneConfigurationBase configuration = AssetDatabase.LoadAssetAtPath(filePath, typeof(SMSceneConfigurationBase)) as SMSceneConfigurationBase;
            if (configuration != null)
            {
                allConfigurations.Add(configuration);
            }
        }
        return(allConfigurations);
    }
Esempio n. 6
0
 public SMSceneRenderer(SMSceneConfigurationBase configuration)
 {
     this.configuration = configuration;
 }