예제 #1
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();
        }
예제 #2
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();
        }
예제 #3
0
        /// <summary> Drawing the 'SceneReference' property </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            using (PropertyScope(position, label, property, out label)) {
                var lineRect = position;
                lineRect.height = lineHeight;

                // Draw the main Object field
                var sceneAssetProperty = GetSceneAssetProperty(property);
                EditorGUI.BeginChangeCheck();
                sceneAssetProperty.objectReferenceValue = EditorGUI.ObjectField(lineRect, label, sceneAssetProperty.objectReferenceValue, typeof(SceneAsset), false);

                var buildScene = BuildUtils.GetBuildScene(sceneAssetProperty.objectReferenceValue);
                if (EditorGUI.EndChangeCheck())
                {
                    if (buildScene.scene == null)
                    {
                        GetScenePathProperty(property).stringValue = string.Empty;
                    }
                }

                if (property.isExpanded = EditorGUI.Foldout(lineRect, property.isExpanded, GUIContent.none, true))
                {
                    // Draw the Box Background
                    var footerRect = position;
                    footerRect.yMin  += lineHeight + spacing;
                    footerRect.height = FOOTER_HEIGHT;
                    GUI.Box(EditorGUI.IndentedRect(footerRect), GUIContent.none, EditorStyles.helpBox);
                    var itemsRect = EditorStyles.helpBox.padding.Remove(footerRect);

                    var sceneControlID = GUIUtility.GetControlID(FocusType.Passive);
                    if (!buildScene.assetGUID.Empty())
                    {
                        // Draw the Build Settings Info of the selected Scene
                        DrawSceneInfoGUI(itemsRect, buildScene, sceneControlID + 1);
                    }
                }
                else
                {
                    GetBuildGuiContent(buildScene, out var icon, out var buildLabel);
                    var iconRect = lineRect;
                    iconRect.xMax = lineRect.xMin + labelWidth;
                    iconRect.xMin = iconRect.xMax - icon.image.width - spacing;
                    icon.tooltip  = $"{buildLabel.text}\n{buildLabel.tooltip}";
                    EditorGUI.LabelField(iconRect, icon);
                }
            }
        }
        /// <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>
        /// Drawing the 'SceneReference' property
        /// </summary>
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.serializedObject.isEditingMultipleObjects)
            {
                GUI.Label(position, "Scene multiediting not supported");
                return;
            }
            var sceneAssetProperty = GetSceneAssetProperty(property);
            // label.tooltip = "The actual Scene Asset reference.\nOn serialize this is also stored as the asset's path.";
            var sceneControlID = GUIUtility.GetControlID(FocusType.Passive);

            EditorGUI.BeginChangeCheck();
            {
                sceneAssetProperty.objectReferenceValue = EditorGUI.ObjectField(position, label, sceneAssetProperty.objectReferenceValue, typeof(SceneAsset), false);
            }
            if (EditorGUI.EndChangeCheck())
            {
                var buildScene = BuildUtils.GetBuildScene(sceneAssetProperty.objectReferenceValue);
                if (buildScene.scene == null)
                {
                    GetScenePathProperty(property).stringValue = string.Empty;
                }
            }
        }