Exemple #1
0
 private static void HelpBox(string message, string link, Action linkClicked)
 {
     GUILayout.BeginHorizontal(EditorStyles.helpBox);
     GUILayout.Label(EditorGUIUtility.GetHelpIcon(MessageType.Info), GUILayout.ExpandWidth(false));
     GUILayout.BeginVertical();
     GUILayout.Label(message, Styles.textLabel);
     if (GUILayout.Button(link, Styles.linkLabel))
     {
         linkClicked?.Invoke();
     }
     EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link);
     GUILayout.EndVertical();
     GUILayout.EndHorizontal();
 }
 void ShowUpgradeTreePrototypeScaleUI(Terrain terrain)
 {
     if (terrain.terrainData != null && terrain.terrainData.NeedUpgradeScaledTreePrototypes())
     {
         var msgContent = EditorGUIUtility.TempContent(
             "Some of your prototypes have scaling values on the prefab. Since Unity 5.2 these scalings will be applied to terrain tree instances. Do you want to upgrade to this behaviour?",
             EditorGUIUtility.GetHelpIcon(MessageType.Warning));
         GUILayout.BeginVertical(EditorStyles.helpBox);
         GUILayout.Label(msgContent, EditorStyles.wordWrappedLabel);
         GUILayout.Space(3);
         if (GUILayout.Button("Upgrade", GUILayout.ExpandWidth(false)))
         {
             terrain.terrainData.UpgradeScaledTreePrototype();
             TerrainMenus.RefreshPrototypes();
         }
         GUILayout.Space(3);
         GUILayout.EndVertical();
     }
 }
        static GUIContent GetTextContent(int width, BreadCrumbTitle text, GUIStyle style)
        {
            s_TextContent.tooltip = string.Empty;
            s_TextContent.image   = null;
            if (text.mode == TitleMode.DisabledComponent)
            {
                s_TextContent.tooltip = k_DisabledComponentText;
                s_TextContent.image   = EditorGUIUtility.GetHelpIcon(MessageType.Warning);
            }
            else if (text.mode == TitleMode.Prefab)
            {
                s_TextContent.image = PrefabUtility.GameObjectStyles.prefabIcon;
            }
            else if (text.mode == TitleMode.GameObject)
            {
                s_TextContent.image = PrefabUtility.GameObjectStyles.gameObjectIcon;
            }
            else if (text.mode == TitleMode.Asset)
            {
                s_TextContent.image = k_TimelineIcon;
            }
            else if (text.mode == TitleMode.PrefabOutOfContext)
            {
                s_TextContent.image = PrefabUtility.GameObjectStyles.prefabIcon;
                if (!TimelineWindow.instance.locked)
                {
                    s_TextContent.tooltip = k_PrefabOutOfContext;
                }
            }

            if (s_TextContent.image != null)
            {
                width = Math.Max(0, width - s_TextContent.image.width);
            }
            s_TextContent.text = FitTextInArea(width, text.name, style);

            return(s_TextContent);
        }
Exemple #4
0
        void SetupLayout()
        {
            m_Root = rootVisualElement;
            m_Root.AddStyleSheetPath(k_UIElementsEditorWindowCreatorStyleSheetPath);

            var           visualTree = EditorGUIUtility.Load(k_UIElementsEditorWindowCreatorUxmlPath) as VisualTreeAsset;
            VisualElement uxmlLayout = visualTree.Instantiate();

            m_Root.Add(uxmlLayout);

            m_ErrorMessageBox = m_Root.Q("errorMessageBox");

            var cSharpTextField = m_Root.Q <TextField>("cSharpTextField");

            cSharpTextField.RegisterCallback <ChangeEvent <string> >(OnCSharpValueChanged);

            var cSharpTextInput = cSharpTextField.Q(TextField.textInputUssName);

            cSharpTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey);
            cSharpTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage());

            m_Root.Q <Toggle>("cSharpToggle").RegisterValueChangedCallback((evt) =>
            {
                m_IsCSharpEnable = evt.newValue;
                if (!m_IsCSharpEnable)
                {
                    cSharpTextField.value = "";
                    m_CSharpName          = "";
                }

                cSharpTextInput.SetEnabled(m_IsCSharpEnable);
            });

            m_Root.schedule.Execute(() => cSharpTextField.Focus());

            var uxmlTextField = m_Root.Q <TextField>("uxmlTextField");

            uxmlTextField.RegisterCallback <ChangeEvent <string> >(e =>
            {
                m_ErrorMessageBox.style.visibility = Visibility.Hidden;
                m_UxmlName = e.newValue;
            });

            var uxmlTextInput = uxmlTextField.Q(TextField.textInputUssName);

            uxmlTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey);
            uxmlTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage());

            m_Root.Q <Toggle>("uxmlToggle").RegisterValueChangedCallback((evt) =>
            {
                m_IsUxmlEnable = evt.newValue;
                if (!m_IsUxmlEnable)
                {
                    uxmlTextField.value = "";
                    m_UxmlName          = "";
                }

                uxmlTextInput.SetEnabled(m_IsUxmlEnable);
            });

            var ussTextField = m_Root.Q <TextField>("ussTextField");

            ussTextField.RegisterCallback <ChangeEvent <string> >(e =>
            {
                m_ErrorMessageBox.style.visibility = Visibility.Hidden;
                m_UssName = e.newValue;
            });

            var ussTextInput = ussTextField.Q(TextField.textInputUssName);

            ussTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey);
            ussTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage());

            m_Root.Q <Toggle>("ussToggle").RegisterValueChangedCallback((evt) =>
            {
                m_IsUssEnable = evt.newValue;
                if (!m_IsUssEnable)
                {
                    ussTextField.value = "";
                    m_UssName          = "";
                }

                ussTextInput.SetEnabled(m_IsUssEnable);
            });

            m_Root.Q <Button>("confirmButton").clickable.clicked += CreateNewTemplatesFiles;
            m_ErrorMessageBox.Q <Image>("warningIcon").image      = EditorGUIUtility.GetHelpIcon(MessageType.Warning);
            HideErrorMessage();
        }
        void SetupLayout()
        {
            m_Root = rootVisualElement;
            m_Root.AddStyleSheetPath(k_UIElementsEditorWindowCreatorStyleSheetPath);

            var           visualTree = EditorGUIUtility.Load(k_UIElementsEditorWindowCreatorUxmlPath) as VisualTreeAsset;
            VisualElement uxmlLayout = visualTree.Instantiate();

            m_Root.Add(uxmlLayout);

            m_ErrorMessageBox = m_Root.Q("errorMessageBox");

            var cSharpTextField = m_Root.Q <TextField>(k_CSharpTextFieldName);

            cSharpTextField.RegisterCallback <ChangeEvent <string> >(OnCSharpValueChanged);

            var cSharpTextInput = cSharpTextField.Q(TextField.textInputUssName);

            cSharpTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey, TrickleDown.TrickleDown);
            cSharpTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage(), TrickleDown.TrickleDown);

            m_Root.schedule.Execute(() => cSharpTextField.Focus());

            var uxmlTextField = m_Root.Q <TextField>(k_UXMLTextFieldName);

            uxmlTextField.RegisterCallback <ChangeEvent <string> >(e =>
            {
                m_ErrorMessageBox.style.visibility = Visibility.Hidden;
                m_UxmlName = e.newValue;
            });

            var uxmlTextInput = uxmlTextField.Q(TextField.textInputUssName);

            uxmlTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey, TrickleDown.TrickleDown);
            uxmlTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage(), TrickleDown.TrickleDown);

            m_Root.Q <Toggle>(k_UXMLToggleName).RegisterValueChangedCallback((evt) =>
            {
                m_IsUxmlEnable = evt.newValue;
                if (!m_IsUxmlEnable)
                {
                    uxmlTextField.value = "";
                    m_UxmlName          = "";
                }

                uxmlTextInput.SetEnabled(m_IsUxmlEnable);

                UpdateActionChoices();
            });

            var ussTextField = m_Root.Q <TextField>(k_USSTextFieldName);

            ussTextField.RegisterCallback <ChangeEvent <string> >(e =>
            {
                m_ErrorMessageBox.style.visibility = Visibility.Hidden;
                m_UssName = e.newValue;
            });

            var ussTextInput = ussTextField.Q(TextField.textInputUssName);

            ussTextInput.RegisterCallback <KeyDownEvent>(OnReturnKey, TrickleDown.TrickleDown);
            ussTextInput.RegisterCallback <FocusEvent>(e => HideErrorMessage(), TrickleDown.TrickleDown);

            m_Root.Q <Toggle>(k_USSToggleName).RegisterValueChangedCallback((evt) =>
            {
                m_IsUssEnable = evt.newValue;
                if (!m_IsUssEnable)
                {
                    ussTextField.value = "";
                    m_UssName          = "";
                }

                ussTextInput.SetEnabled(m_IsUssEnable);
            });

            var actionsDropdown = m_Root.Q <DropdownField>(k_ActionsDropdownName);

            actionsDropdown.RegisterValueChangedCallback((evt) =>
            {
                m_ActionSelected = evt.newValue;
            });
            actionsDropdown.value = string.IsNullOrEmpty(m_ActionSelected) ? k_JustCreateFilesOption : m_ActionSelected;

            UpdateActionChoices();

            var pathIcon = m_Root.Q <VisualElement>(k_PathIconName);

            pathIcon.style.backgroundImage = EditorGUIUtility.LoadIcon("FolderOpened Icon");

            var chooseFolderButton = m_Root.Q <Button>(k_ChooseFolderButtonName);

            chooseFolderButton.clicked += OnChooseFolderClicked;

            m_Root.Q <Button>("confirmButton").clickable.clicked += CreateNewTemplatesFiles;
            m_ErrorMessageBox.Q <Image>("warningIcon").image      = EditorGUIUtility.GetHelpIcon(MessageType.Warning);
            HideErrorMessage();
        }
        public override void OnInspectorGUI(Terrain terrain, IOnInspectorGUI editContext)
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            DetailPrototype[] prototypes = terrain.terrainData.detailPrototypes;
            var detailIcons = LoadDetailIcons(prototypes);

            // Detail picker
            GUILayout.Label(s_Styles.details, EditorStyles.boldLabel);

            selectedDetail = TerrainInspector.AspectSelectionGridImageAndText(selectedDetail, prototypes.Length, (i, rect, style, controlID) =>
            {
                bool renderModeSupported = DetailPrototype.IsModeSupportedByRenderPipeline(prototypes[i].renderMode, prototypes[i].useInstancing, out var errorMessage);
                bool mouseHover          = rect.Contains(Event.current.mousePosition);

                if (Event.current.type == EventType.Repaint)
                {
                    bool wasEnabled = GUI.enabled;
                    GUI.enabled    &= renderModeSupported;
                    style.Draw(rect, detailIcons[i], GUI.enabled && mouseHover && (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID), GUI.enabled && GUIUtility.hotControl == controlID, i == selectedDetail, false);
                    GUI.enabled = wasEnabled;
                }

                if (!renderModeSupported)
                {
                    var tmpContent     = EditorGUIUtility.TempContent(EditorGUIUtility.GetHelpIcon(MessageType.Error));
                    tmpContent.tooltip = errorMessage;
                    GUI.Label(new Rect(rect.xMax - 16, rect.yMin + 1, 19, 19), tmpContent);
                }

                if (mouseHover)
                {
                    GUIUtility.mouseUsed = true;
                    GUIStyle.SetMouseTooltip(detailIcons[i].tooltip, rect);
                }
            }, 64, s_Styles.noDetailObjectDefined, out var doubleClick);

            if (doubleClick)
            {
                TerrainDetailContextMenus.EditDetail(new MenuCommand(terrain, selectedDetail));
                GUIUtility.ExitGUI();
            }

            if (selectedDetail >= 0 && selectedDetail < prototypes.Length)
            {
                ShowDetailPrototypeMessages(prototypes[selectedDetail], terrain);
            }

            var terrainInspector = TerrainInspector.s_activeTerrainInspectorInstance;

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            TerrainInspector.MenuButton(s_Styles.editDetails, "CONTEXT/TerrainEngineDetails", terrain, selectedDetail);
            terrainInspector.ShowRefreshPrototypes();
            GUILayout.EndHorizontal();

            terrainInspector.ShowDetailStats();
            EditorGUILayout.Space();

            // Brush selector
            editContext.ShowBrushesGUI(0, BrushGUIEditFlags.Select, 0);

            // Brush size
            terrainInspector.brushSize = EditorGUILayout.PowerSlider(s_Styles.brushSize, Mathf.Clamp(terrainInspector.brushSize, 1, 100), 1, 100, 4);
            detailOpacity = EditorGUILayout.Slider(s_Styles.opacity, detailOpacity, 0, 1);

            // Strength
            detailStrength = EditorGUILayout.Slider(s_Styles.detailTargetStrength, detailStrength, 0, 1);

            // Brush editor
            editContext.ShowBrushesGUI((int)EditorGUIUtility.singleLineHeight, BrushGUIEditFlags.Inspect);
        }
        private void ShowTextureFallbackWarning(ref Terrain terrain)
        {
            if (!UnityEngine.Experimental.Rendering.GraphicsFormatUtility.IsCompressedFormat(terrain.terrainData.atlasFormat))
            {
                using (new EditorGUILayout.VerticalScope())
                {
                    GUILayout.Space(3);
                    using (new EditorGUILayout.HorizontalScope(EditorStyles.helpBox))
                    {
                        // Copied from LabelField called by HelpBox - using so that label and button link are in the same helpbox
                        var  infoLabel = EditorGUIUtility.TempContent("Atlas uncompressed. This can be caused by mismatched texture formats.", EditorGUIUtility.GetHelpIcon(MessageType.Warning));
                        Rect r         = GUILayoutUtility.GetRect(infoLabel, EditorStyles.wordWrappedLabel);
                        int  oldIndent = EditorGUI.indentLevel;
                        EditorGUI.indentLevel = 0;
                        EditorGUI.LabelField(r, infoLabel, EditorStyles.wordWrappedLabel);
                        EditorGUI.indentLevel = oldIndent;

                        using (new EditorGUILayout.VerticalScope())
                        {
                            GUILayout.FlexibleSpace();
                            if (EditorGUILayout.LinkButton("Read More"))
                            {
                                Help.BrowseURL($"https://docs.unity3d.com//{Application.unityVersionVer}.{Application.unityVersionMaj}/Documentation/ScriptReference/Texture2D.PackTextures.html");
                            }
                            GUILayout.FlexibleSpace();
                        }
                    }
                }
            }
        }