Пример #1
0
        private static void GetBuildGuiContent(BuildUtils.BuildScene buildScene, out GUIContent icon, out GUIContent label)
        {
            icon  = new GUIContent();
            label = new GUIContent();

            // Missing from build scenes
            if (buildScene.buildIndex == -1)
            {
                icon          = EditorGUIUtility.IconContent("d_winbtn_mac_close");
                label.text    = "Not in build";
                label.tooltip = "This scene is not in the build.";
            }
            // In build scenes and enabled
            else if (buildScene.scene.enabled)
            {
                icon          = EditorGUIUtility.IconContent("d_winbtn_mac_max");
                label.text    = "Build index: " + buildScene.buildIndex;
                label.tooltip = "This scene is in the build.";
            }
            // In build scenes but disabled
            else
            {
                icon          = EditorGUIUtility.IconContent("d_winbtn_mac_min");
                label.text    = "Build index: " + buildScene.buildIndex;
                label.tooltip = "This scene is in the build but is DISABLED!";
            }
            return;
        }
Пример #2
0
        /// <summary>
        /// Drawing the 'SceneReference' property
        /// </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Draw the Box Background
            position.height -= footerHeight;
            GUI.Box(EditorGUI.IndentedRect(position), GUIContent.none, EditorStyles.helpBox);
            position        = boxPadding.Remove(position);
            position.height = lineHeight;

            label.tooltip = "";

            EditorGUI.BeginProperty(position, GUIContent.none, property);

            var sceneAsset = property.FindPropertyRelative(sceneAssetPropertyString);
            var sceneName  = property.FindPropertyRelative(sceneNamePropertyString);

            sceneAsset.objectReferenceValue = EditorGUI.ObjectField(position, label, sceneAsset.objectReferenceValue, typeof(SceneAsset), false);
            if (sceneAsset.objectReferenceValue != null)
            {
                sceneName.stringValue = (sceneAsset.objectReferenceValue as SceneAsset).name;
            }

            int sceneControlID = GUIUtility.GetControlID(FocusType.Passive);

            BuildUtils.BuildScene buildScene = BuildUtils.GetBuildScene(sceneAsset.objectReferenceValue);

            position.y += paddedLine;

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

            EditorGUI.EndProperty();
        }
Пример #3
0
        /// <summary>
        /// Drawing the 'SceneReference' property
        /// </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Move this up
            EditorGUI.BeginProperty(position, GUIContent.none, property);
            {
                // Here we add the foldout using a single line height, the label and change
                // the value of property.isExpanded
                property.isExpanded = EditorGUI.Foldout(new Rect(position.x, position.y, position.width, lineHeight), property.isExpanded, label);

                // Now you want to draw the content only if you unfold this property
                if (property.isExpanded)
                {
                    // Optional: Indent the content
                    //EditorGUI.indentLevel++;
                    //{

                    // reduce the height by one line and move the content one line below
                    position.height -= lineHeight;
                    position.y      += lineHeight;

                    //SerializedProperty sceneAssetProperty = GetSceneAssetProperty(property);
                    SceneAsset sceneAsset = GetSceneAssetProperty(property);

                    // Draw the Box Background
                    position.height -= FOOTER_HEIGHT;
                    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.";


                    int sceneControlID = GUIUtility.GetControlID(FocusType.Passive);
                    EditorGUI.BeginChangeCheck();

                    // removed the label here since we already have it in the foldout before
                    sceneAsset = EditorGUI.ObjectField(position, sceneAsset, typeof(SceneAsset), false) as SceneAsset;
                    if (EditorGUI.EndChangeCheck())
                    {
                        SetSceneAssetProperty(property, sceneAsset);
                    }

                    position.y += paddedLine;

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

                    // Optional: If enabled before reset the indentlevel
                    //}
                    //EditorGUI.indentLevel--;
                }
            }
            EditorGUI.EndProperty();
        }
        /// <inheritdoc />
        /// <summary> Drawing the 'SceneReference' property </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty sceneAssetProperty = GetSceneAssetProperty(property);

            // Draw the Box Background
            position.height -= FOOTER_HEIGHT;
            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);

            Object selectedObject = EditorGUI.ObjectField(position, label, sceneAssetProperty.objectReferenceValue, typeof(SceneAsset), false);

            BuildUtils.BuildScene buildScene = BuildUtils.GetBuildScene(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();
        }
Пример #5
0
        /// <summary>
        /// Draws info box of the provided scene
        /// </summary>
        private void DrawSceneInfoGUI(Rect position, BuildUtils.BuildScene buildScene, int sceneControlID)
        {
            bool   readOnly        = BuildUtils.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();

            // Missing from build scenes
            if (buildScene.buildIndex == -1)
            {
                iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_close");
                labelContent.text    = "NOT In Build";
                labelContent.tooltip = "This scene is NOT in build settings.\nIt will be NOT included in builds.";
            }
            // In build scenes and enabled
            else if (buildScene.scene.enabled)
            {
                iconContent          = EditorGUIUtility.IconContent("d_winbtn_mac_max");
                labelContent.text    = "BuildIndex: " + buildScene.buildIndex;
                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    = "BuildIndex: " + buildScene.buildIndex;
                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 in build settings
                if (buildScene.buildIndex == -1)
                {
                    buttonRect.width *= 2;
                    int addIndex = EditorBuildSettings.scenes.Length;
                    tooltipMsg = "Add this scene to build settings. It will be appended to the end of the build scenes as buildIndex: " + addIndex + "." + readOnlyWarning;
                    if (DrawUtils.ButtonHelper(buttonRect, "Add...", "Add (buildIndex " + addIndex + ")", EditorStyles.miniButtonLeft, tooltipMsg))
                    {
                        BuildUtils.AddBuildScene(buildScene);
                    }
                    buttonRect.width /= 2;
                    buttonRect.x     += buttonRect.width;
                }
                // In build settings
                else
                {
                    bool   isEnabled   = buildScene.scene.enabled;
                    string stateString = isEnabled ? "Disable" : "Enable";
                    tooltipMsg = stateString + " this scene in build settings.\n" + (isEnabled ? "It will no longer be included in builds" : "It will be included in builds") + "." + readOnlyWarning;

                    if (DrawUtils.ButtonHelper(buttonRect, stateString, stateString + " In Build", EditorStyles.miniButtonLeft, tooltipMsg))
                    {
                        BuildUtils.SetBuildSceneState(buildScene, !isEnabled);
                    }
                    buttonRect.x += buttonRect.width;

                    tooltipMsg = "Completely remove this scene from build settings.\nYou will need to add it again for it to be included in builds!" + readOnlyWarning;
                    if (DrawUtils.ButtonHelper(buttonRect, "Remove...", "Remove from Build", EditorStyles.miniButtonMid, tooltipMsg))
                    {
                        BuildUtils.RemoveBuildScene(buildScene);
                    }
                }
            }

            buttonRect.x += buttonRect.width;

            tooltipMsg = "Open the 'Build Settings' Window for managing scenes." + readOnlyWarning;
            if (DrawUtils.ButtonHelper(buttonRect, "Settings", "Build Settings", EditorStyles.miniButtonRight, tooltipMsg))
            {
                BuildUtils.OpenBuildSettings();
            }
        }
Пример #6
0
        /// <summary> Draws info box of the provided scene </summary>
        private void DrawSceneInfoGUI(Rect position, BuildUtils.BuildScene buildScene, int sceneControlID)
        {
            var disabled        = BuildUtils.IsDisabled();
            var disabledWarning = disabled ? "\n\nWARNING: Build Settings is not checked out and so cannot be modified." : "";

            GetBuildGuiContent(buildScene, out var icon, out var label);

            // Left status label
            using (DisabledScope(disabled)) {
                var labelRect = DrawUtils.GetLabelRect(position);
                var iconRect  = labelRect;
                iconRect.width   = icon.image.width + spacing;
                labelRect.width -= iconRect.width;
                labelRect.x     += iconRect.width;
                EditorGUI.PrefixLabel(iconRect, sceneControlID, icon);
                EditorGUI.PrefixLabel(labelRect, sceneControlID, label);
            }

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

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

            var tooltipMsg = "";

            using (DisabledScope(disabled)) {
                // NOT in build settings
                if (buildScene.buildIndex == -1)
                {
                    buttonRect.width *= 2;
                    var addIndex = EditorBuildSettings.scenes.Length;
                    tooltipMsg = "Add this scene to build settings. It will be appended to the end of the build scenes as buildIndex: " + addIndex + "." + disabledWarning;
                    if (DrawUtils.ButtonHelper(buttonRect, "Add...", "Add (buildIndex " + addIndex + ")", EditorStyles.miniButtonLeft, tooltipMsg))
                    {
                        BuildUtils.AddBuildScene(buildScene);
                    }
                    buttonRect.width /= 2;
                    buttonRect.x     += buttonRect.width;
                }
                // In build settings
                else
                {
                    var isEnabled   = buildScene.scene.enabled;
                    var stateString = isEnabled ? "Disable" : "Enable";
                    tooltipMsg = stateString + " this scene in build settings.\n" + (isEnabled ? "It will no longer be included in builds" : "It will be included in builds") + "." + disabledWarning;

                    if (DrawUtils.ButtonHelper(buttonRect, stateString, stateString + " In Build", EditorStyles.miniButtonLeft, tooltipMsg))
                    {
                        BuildUtils.SetBuildSceneState(buildScene, !isEnabled);
                    }
                    buttonRect.x += buttonRect.width;

                    tooltipMsg = "Completely remove this scene from build settings.\nYou will need to add it again for it to be included in builds!" + disabledWarning;
                    if (DrawUtils.ButtonHelper(buttonRect, "Remove...", "Remove from Build", EditorStyles.miniButtonMid, tooltipMsg))
                    {
                        BuildUtils.RemoveBuildScene(buildScene);
                    }
                }
            }

            buttonRect.x += buttonRect.width;

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