예제 #1
0
    /// <summary>
    /// Drawing the 'SceneReference' property
    /// </summary>

    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var sceneAssetProperty = GetSceneAssetProperty(property);

        // Draw the Box Background
        position.height -= footerHeight;
        GUI.Box(EditorGUI.IndentedRect(position), GUIContent.none, EditorStyles.helpBox);
        position        = boxPadding.Remove(position);
        position.height = lineHeight;

        // Draw the main Object field
        label.tooltip = "The actual Scene Asset reference.\nOn serialize this is also stored as the asset's path.";

        EditorGUI.BeginProperty(position, GUIContent.none, property);
        EditorGUI.BeginChangeCheck();
        int sceneControlID = GUIUtility.GetControlID(FocusType.Passive);
        var selectedObject = EditorGUI.ObjectField(position, label, sceneAssetProperty.objectReferenceValue, typeof(SceneAsset), false);

        SceneUtils.SubScene buildScene = SceneUtils.GetScene(selectedObject);

        if (EditorGUI.EndChangeCheck())
        {
            sceneAssetProperty.objectReferenceValue = selectedObject;

            //If no valid scene asset was selected, reset the stored path accordingly
            //if (buildScene.scene == null)
            //    GetScenePathProperty(property).stringValue = string.Empty;
        }
        position.y += paddedLine;

        if (buildScene.assetGUID.Empty() == false)
        {
            // Draw the Build Settings Info of the selected Scene
            DrawSceneInfoGUI(position, buildScene, sceneControlID + 1);
        }

        EditorGUI.EndProperty();
    }
예제 #2
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();
        }
    }