public override VisualElement CreateInspectorGUI()
        {
            var root = Root = new VisualElement();

            root.AddToClassList("scene-template-asset-inspector");
            root.AddToClassList(Styles.unityThemeVariables);
            root.AddToClassList(Styles.sceneTemplateThemeVariables);
            root.AddStyleSheetPath(Styles.k_CommonStyleSheetPath);
            root.AddStyleSheetPath(Styles.variableStyleSheet);
            root.style.flexDirection = FlexDirection.Column;

            var detailElement = new VisualElement();

            // Template scene
            var templateSceneProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateScenePropertyName);
            var templatePropertyField = new PropertyField(templateSceneProperty, L10n.Tr("Template Scene"));

            templatePropertyField.tooltip = L10n.Tr("Scene to instantiate.");
            templatePropertyField.RegisterCallback <ChangeEvent <Object> >(e =>
            {
                RebuildDependencies(root);
                TriggerSceneTemplateModified();
            });
            detailElement.Add(templatePropertyField);

            // Scene title
            var templateTitleProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateTitlePropertyName);
            var titlePropertyField    = new PropertyField(templateTitleProperty, L10n.Tr("Title"));

            titlePropertyField.tooltip = L10n.Tr("Scene template display name. Shown in New Scene Dialog.");
            titlePropertyField.RegisterCallback <ChangeEvent <string> >(e => TriggerSceneTemplateModified());
            titlePropertyField.RegisterCallback <SerializedPropertyBindEvent>(e =>
            {
                EditorApplication.delayCall += () =>
                {
                    if (!titlePropertyField.Children().Any())
                    {
                        return;
                    }
                    if (titlePropertyField.Children().First() is TextField titlePropertyFieldTextField)
                    {
                        titlePropertyFieldTextField.maxLength = 1024;
                        m_TitleTextFieldReady = true;
                    }
                };
            });
            detailElement.Add(titlePropertyField);

            // Scene description
            var templateDescriptionProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateDescriptionPropertyName);
            var description = new PropertyField(templateDescriptionProperty, L10n.Tr("Description"));

            description.tooltip = L10n.Tr("Scene template description. Shown in New Scene Dialog.");
            description.RegisterCallback <ChangeEvent <string> >(e => TriggerSceneTemplateModified());
            description.RegisterCallback <SerializedPropertyBindEvent>(e =>
            {
                EditorApplication.delayCall += () =>
                {
                    if (!description.Children().Any())
                    {
                        return;
                    }
                    var descriptionTextField = description.Children().First() as TextField;
                    if (descriptionTextField != null)
                    {
                        descriptionTextField.AddToClassList(Styles.classWrappingText);
                        descriptionTextField.multiline = true;
                        descriptionTextField.maxLength = 1024;
                        m_DescriptionTextFieldReady    = true;
                    }
                };
            });
            detailElement.Add(description);

            var templateAddToDefaultsProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateAddToDefaultsPropertyName);
            var defaultTemplateField          = new VisualElement();

            defaultTemplateField.style.flexDirection = FlexDirection.Row;
            var addToDefaultsPropertyField = new PropertyField(templateAddToDefaultsProperty, " ");

            addToDefaultsPropertyField.RegisterCallback <ChangeEvent <bool> >(e => TriggerSceneTemplateModified());
            addToDefaultsPropertyField.style.flexShrink = 0;
            defaultTemplateField.Add(addToDefaultsPropertyField);
            var label = new Label(L10n.Tr("Pin in New Scene Dialog"));

            label.tooltip = L10n.Tr("Pin in New Scene Dialog. Ensuring this template is shown before unpinned template in the list.");
            label.style.unityTextAlign = TextAnchor.MiddleLeft;
            label.style.overflow       = Overflow.Hidden;
            label.style.textOverflow   = TextOverflow.Ellipsis;
            label.style.flexShrink     = 1;
            defaultTemplateField.Add(label);
            detailElement.Add(defaultTemplateField);
            root.Add(CreateFoldoutInspector(detailElement, L10n.Tr("Details"), "SceneTemplateInspectorDetailsFoldout"));

            // Template thumbnail
            var templateThumbnailProperty      = serializedObject.FindProperty(SceneTemplateUtils.TemplateThumbnailPropertyName);
            var templateThumbnailBadgeProperty = serializedObject.FindProperty(SceneTemplateUtils.TemplateThumbnailBadgePropertyName);
            var thumbnailField = MakeThumbnailField(templateThumbnailProperty, templateThumbnailBadgeProperty);

            root.Add(CreateFoldoutInspector(thumbnailField, L10n.Tr("Thumbnail"), "SceneTemplateInspectorThumbnailFoldout"));

            // SceneTemplatePipeline
            var sceneTemplatePipeline = new VisualElement();
            var pipelineProperty      = serializedObject.FindProperty(SceneTemplateUtils.TemplatePipelineName);
            var pipelineField         = new PropertyField(pipelineProperty, L10n.Tr("Scene Template Pipeline"));

            pipelineField.tooltip = k_SceneTemplateInfo;
            pipelineField.RegisterCallback <ChangeEvent <Object> >(e =>
            {
                if (e.newValue != null && !SceneTemplateAsset.IsValidPipeline(e.newValue as MonoScript))
                {
                    Debug.LogWarning(k_SceneTemplateInfo);
                    pipelineProperty.objectReferenceValue = null;
                    serializedObject.ApplyModifiedProperties();
                }
            });
            sceneTemplatePipeline.Add(pipelineField);
            var buttonRow            = CreateEmptyLabelRow(L10n.Tr("Scene Template Pipeline"), Styles.classUnityPropertyFieldLabel); // Use a hidden label instead of an empty element for proper alignment
            var createPipelineButton = new Button(OnCreateSceneTemplatePipeline)
            {
                text = k_CreatePipelineButtonLabel, tooltip = k_CreatePipelineTooltip
            };

            createPipelineButton.AddToClassList(Styles.classUnityBaseFieldInput);
            buttonRow.Add(createPipelineButton);
            sceneTemplatePipeline.Add(buttonRow);
            root.Add(CreateFoldoutInspectorWithHelp(sceneTemplatePipeline, L10n.Tr("Scene Template Pipeline"), "SceneTemplatePipelineFoldout", k_PipelineHelpUrl));

            // Dependencies
            root.Add(CreateFoldoutInspector(BuildDependencyRows(), L10n.Tr("Dependencies"), "SceneTemplateDependenciesFoldout"));
            return(root);
        }
Example #2
0
        public override VisualElement CreateInspectorGUI()
        {
            var styleSheetLoader = new StyleSheetLoader();

            styleSheetLoader.LoadStyleSheets();
            var root = Root = new VisualElement();

            root.AddToClassList("scene-template-asset-inspector");
            root.AddToClassList(StyleSheetLoader.Styles.unityThemeVariables);
            root.AddToClassList(StyleSheetLoader.Styles.sceneTemplateThemeVariables);
            root.styleSheets.Add(styleSheetLoader.CommonStyleSheet);
            root.styleSheets.Add(styleSheetLoader.VariableStyleSheet);
            root.style.flexDirection = FlexDirection.Column;

            var detailElement = new VisualElement();

            // Template scene
            var templateSceneProperty = serializedObject.FindProperty(k_TemplateScenePropertyName);
            var templatePropertyField = new PropertyField(templateSceneProperty, "Template Scene");

            templatePropertyField.RegisterCallback <ChangeEvent <Object> >(e =>
            {
                RebuildDependencies(root);
                TriggerSceneTemplateModified();
            });
            detailElement.Add(templatePropertyField);

            // Scene title
            var templateTitleProperty = serializedObject.FindProperty(k_TemplateTitlePropertyName);
            var titlePropertyField    = new PropertyField(templateTitleProperty, "Title");

            titlePropertyField.RegisterCallback <ChangeEvent <string> >(e => TriggerSceneTemplateModified());
            detailElement.Add(titlePropertyField);

            // Scene description
            var templateDescriptionProperty = serializedObject.FindProperty(k_TemplateDescriptionPropertyName);
            var descriptionTextField        = new TextField("Description", -1, true, false, '*')
            {
                name  = k_DescriptionTextFieldName,
                value = templateDescriptionProperty.stringValue
            };

            descriptionTextField.AddToClassList(StyleSheetLoader.Styles.classWrappingText);
            descriptionTextField.RegisterValueChangedCallback(e =>
            {
                serializedObject.UpdateIfRequiredOrScript();
                templateDescriptionProperty.stringValue = e.newValue;
                serializedObject.ApplyModifiedProperties();
                TriggerSceneTemplateModified();
            });
            detailElement.Add(descriptionTextField);

            var templateAddToDefaultsProperty = serializedObject.FindProperty(k_TemplateAddToDefaultsPropertyName);
            var defaultTemplateField          = new VisualElement();

            defaultTemplateField.style.flexDirection = FlexDirection.Row;
            var addToDefaultsPropertyField = new PropertyField(templateAddToDefaultsProperty, " ");

            addToDefaultsPropertyField.RegisterCallback <ChangeEvent <bool> >(e => TriggerSceneTemplateModified());
            addToDefaultsPropertyField.style.flexShrink = 0;
            defaultTemplateField.Add(addToDefaultsPropertyField);
            var label = new Label("Pin in New Scene Dialog");

            label.style.unityTextAlign = TextAnchor.MiddleLeft;
            label.style.overflow       = Overflow.Hidden;
            label.style.textOverflow   = TextOverflow.Ellipsis;
            label.style.flexShrink     = 1;
            defaultTemplateField.Add(label);
            detailElement.Add(defaultTemplateField);
            root.Add(CreateFoldoutInspector(detailElement, "Details", "SceneTemplateInspectorDetailsFoldout"));

            // Template thumbnail
            var templateThumbnailProperty = serializedObject.FindProperty(k_TemplateThumbnailPropertyName);
            var thumbnailField            = MakeThumbnailField(templateThumbnailProperty, "Texture");

            root.Add(CreateFoldoutInspector(thumbnailField, "Thumbnail", "SceneTemplateInspectorThumbnailFoldout"));

            // SceneTemplatePipeline
            var sceneTemplatePipeline = new VisualElement();

            sceneTemplatePipeline.Add(new HelpBox(k_ScenteTemplateInfo, HelpBoxMessageType.Info));

            var pipelineProperty = serializedObject.FindProperty(k_TemplatePipelineName);
            var pipelineField    = new PropertyField(pipelineProperty, "Scene Template Pipeline")
            {
                name = k_SceneTemplatePipelineName
            };

            pipelineField.RegisterCallback <ChangeEvent <Object> >(e =>
            {
                if (e.newValue != null && !SceneTemplateAsset.IsValidPipeline(e.newValue as MonoScript))
                {
                    Debug.LogWarning(k_ScenteTemplateInfo);
                    pipelineProperty.objectReferenceValue = null;
                    serializedObject.ApplyModifiedProperties();
                }
            });
            sceneTemplatePipeline.Add(pipelineField);
            root.Add(CreateFoldoutInspector(sceneTemplatePipeline, "Scene Template Pipeline", "SceneTemplatePipelineFoldout"));

            // Dependencies
            root.Add(CreateFoldoutInspector(BuildDependencyRows(), "Dependencies", "SceneTemplateDependenciesFoldout"));

            root.Bind(serializedObject);
            return(root);
        }