//----- property -----

        //----- method -----

        public static void Open()
        {
            if (instance == null)
            {
                instance = DisplayWizard <GameTextSelector>("GameTextSelector");
                instance.Initialize();
            }
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            instance = target as GameTextSetter;

            EditorGUILayout.Separator();

            var categories = Enum.GetValues(typeof(GameTextCategory)).Cast <GameTextCategory>().OrderBy(x => (int)x).ToList();

            var categoryIndex = categories.FindIndex(x => x == instance.Category);

            var categoryLabels       = categories.Select(x => x.ToLabelName());
            var currentCategoryIndex = EditorGUILayout.Popup("Category", categoryIndex, categoryLabels.ToArray());

            if (categoryIndex != currentCategoryIndex)
            {
                UnityEditorUtility.RegisterUndo("GameTextSetterInspector-Undo", instance);
                categoryIndex = currentCategoryIndex;

                instance.SetCategory(categories[categoryIndex]);
            }

            if (categoryIndex != 0)
            {
                EditorGUILayout.Separator();

                if (EditorLayoutTools.DrawPrefixButton("Selection GameText", GUILayout.Width(180f)))
                {
                    GameTextSelector.Open();
                }

                GUILayout.Space(5f);

                if (EditorLayoutTools.DrawHeader("SourceText", "GameTextSetterInspector-SourceText"))
                {
                    EditorGUILayout.TextArea(instance.Content, GUILayout.Height(48f));
                }
            }

            EditorGUILayout.Separator();
        }
        public override void OnInspectorGUI()
        {
            instance = target as GameTextSetter;

            Current = this;

            EditorGUILayout.Separator();

            using (new EditorGUILayout.HorizontalScope())
            {
                var categories = Enum.GetValues(typeof(GameTextCategory)).Cast <GameTextCategory>().OrderBy(x => (int)x).ToList();

                var categoryIndex = categories.FindIndex(x => x == instance.Category);

                var categoryLabels = categories.Select(x => x.ToLabelName());
                var labels         = categoryLabels.ToArray();

                var currentCategoryIndex = EditorGUILayout.Popup("GameText", categoryIndex, labels);

                if (categoryIndex != currentCategoryIndex)
                {
                    UnityEditorUtility.RegisterUndo("GameTextSetterInspector-Undo", instance);
                    categoryIndex = currentCategoryIndex;

                    instance.SetCategory(categories[categoryIndex]);
                }

                using (new DisableScope(categoryIndex == 0 || GameText.Instance.Cache == null))
                {
                    GUILayout.Space(2f);

                    if (GUILayout.Button("select", EditorStyles.miniButton, GUILayout.Width(75f)))
                    {
                        GameTextSelector.Open();
                    }
                }
            }

            GUILayout.Space(2f);

            if (gameTextCategory.HasValue)
            {
                if (gameTextCategory.Value != instance.Category)
                {
                    OnGameTextSetterCategoryChanged(instance.Category);
                }
            }
            else
            {
                OnGameTextSetterCategoryChanged(instance.Category);
            }

            gameTextCategory = instance.Category;

            if (instance.Category == GameTextCategory.None)
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    var labelWidth = EditorGUIUtility.labelWidth - 10f;

                    EditorGUILayout.LabelField("Development Text", GUILayout.Width(labelWidth));

                    var developmentText = instance.GetDevelopmentText();

                    var editText = developmentText.TrimStart(GameTextSetter.DevelopmentMark);

                    var prevText = editText;

                    EditorGUI.BeginChangeCheck();

                    var lineCount = editText.Count(x => x == '\n') + 1;

                    lineCount = Mathf.Clamp(lineCount, 1, 5);

                    var textAreaHeight = lineCount * 18f;

                    editText = EditorGUILayout.TextArea(editText, GUILayout.ExpandWidth(true), GUILayout.Height(textAreaHeight));

                    if (EditorGUI.EndChangeCheck())
                    {
                        UnityEditorUtility.RegisterUndo("UITextInspector-Undo", instance);

                        if (!string.IsNullOrEmpty(prevText))
                        {
                            Reflection.InvokePrivateMethod(instance, "ApplyText", new object[] { null });
                        }

                        if (!string.IsNullOrEmpty(editText))
                        {
                            editText = editText.FixLineEnd();
                        }

                        Reflection.InvokePrivateMethod(instance, "SetDevelopmentText", new object[] { editText });
                        instance.ImportText();
                    }
                }
            }
        }