Beispiel #1
0
    /// <summary>
    /// Draws info box of the provided scene
    /// </summary>
    private void DrawSceneInfoGUI(Rect position, SceneUtils.SubScene buildScene, int sceneControlID)
    {
        bool   readOnly        = SceneUtils.IsReadOnly();
        string readOnlyWarning = readOnly ? "\n\nWARNING: Build Settings is not checked out and so cannot be modified." : "";

        // Label Prefix
        GUIContent iconContent  = new GUIContent();
        GUIContent labelContent = new GUIContent();


        // If scene is enabled
        bool isLoaded = false;

        if (Application.isPlaying)
        {
            isLoaded = SceneManager.GetSceneByPath(buildScene.assetPath).isLoaded;
        }
        else
        {
            isLoaded = EditorSceneManager.GetSceneByPath(buildScene.assetPath).isLoaded;
        }
        if (isLoaded)
        {
            iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_max");
            labelContent.text    = "Enabled";
            labelContent.tooltip = "This scene is in build settings and ENABLED.\nIt will be included in builds." + readOnlyWarning;
        }
        // In build scenes and disabled
        else
        {
            iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_min");
            labelContent.text    = "Disabled";
            labelContent.tooltip = "This scene is in build settings and DISABLED.\nIt will be NOT included in builds.";
        }

        // Left status label
        using (new EditorGUI.DisabledScope(readOnly))
        {
            Rect labelRect = DrawUtils.GetLabelRect(position);
            Rect iconRect  = labelRect;
            iconRect.width   = iconContent.image.width + padSize;
            labelRect.width -= iconRect.width;
            labelRect.x     += iconRect.width;
            EditorGUI.PrefixLabel(iconRect, sceneControlID, iconContent);
            EditorGUI.PrefixLabel(labelRect, sceneControlID, labelContent);
        }

        // Right context buttons
        Rect buttonRect = DrawUtils.GetFieldRect(position);

        buttonRect.width = (buttonRect.width) / 3;

        string tooltipMsg = "";

        using (new EditorGUI.DisabledScope(readOnly))
        {
            // NOT loaded
            if (EditorSceneManager.GetSceneByPath(buildScene.assetPath).isSubScene&& !Application.isPlaying)
            {
                SceneUtils.AddScene(buildScene);
            }
            // Loaded
            else
            {
                //bool isEnabled = buildScene.scene.enabled;
                buttonRect.width *= 2;

                bool isEnabled;
                if (Application.isPlaying)
                {
                    isEnabled = SceneManager.GetSceneByPath(buildScene.assetPath).isLoaded;
                }
                else
                {
                    isEnabled = EditorSceneManager.GetSceneByPath(buildScene.assetPath).isLoaded;
                }

                string stateString = isEnabled ? "Disable" : "Enable";
                tooltipMsg = stateString + " this scene in current scene.\n" + (isEnabled ? "It will no longer be included in scene" : "It will be included in scene") + "." + readOnlyWarning;

                if (DrawUtils.ButtonHelper(buttonRect, stateString, stateString + " In Scene", EditorStyles.miniButtonLeft, tooltipMsg))
                {
                    SceneUtils.SetSceneState(buildScene, isEnabled);
                }
                buttonRect.width /= 2;
                buttonRect.x     += buttonRect.width;
            }
        }

        buttonRect.x += buttonRect.width;

        tooltipMsg = "Open the 'Build Settings' Window for managing scenes." + readOnlyWarning;
        if (DrawUtils.ButtonHelper(buttonRect, "Settings", "Build Settings", EditorStyles.miniButtonRight, tooltipMsg))
        {
            SceneUtils.OpenBuildSettings();
        }
    }