Example #1
0
        /// <summary>
        /// 定数を管理するクラスを生成します
        /// </summary>
        public static void Create(TMPRuleSettings settings)
        {
            var editorSettings = UniTMPRuleConstCreatorSettings.GetInstance();
            var template       = editorSettings.CodeTemplate;

            var values = settings.List
                         .Select(x => new ConstStringCodeGeneratorOptions.Element {
                Name = x.Name, Value = x.Name, Comment = x.Comment
            })
                         .ToArray()
            ;

            var options = new ConstStringCodeGeneratorOptions
            {
                Template = template,
                Elements = values,
            };

            var path = editorSettings.OutputAssetPath;
            var code = ConstStringCodeGenerator.Generate(options);

            code = code
                   .Replace("\t", "    ")
                   .Replace("\r\n", "#NEW_LINE#")
                   .Replace("\r", "#NEW_LINE#")
                   .Replace("\n", "#NEW_LINE#")
                   .Replace("#NEW_LINE#", "\r\n")
            ;

            ConstStringCodeGenerator.Write(path, code);
            AssetDatabase.Refresh();
        }
Example #2
0
 /// <summary>
 /// UniSymbolSettings の Inspector のヘッダの GUI を描画する時に呼び出されます
 /// </summary>
 private static void OnHeaderGUI(TMPRuleSettings settings)
 {
     if (GUILayout.Button("定数を管理するスクリプトを生成"))
     {
         Create(settings);
     }
 }
Example #3
0
        /// <summary>
        /// 指定された TMPRule を持つオブジェクトに設定を反映します
        /// </summary>
        public static void Apply(TMPRuleSettings settings, TMPRule tmpRule)
        {
            var ruleName = tmpRule.RuleName;

            if (ruleName == TMPRule.INVALID_RULE_NAME)
            {
                return;
            }

            var setting = Array.Find(settings.List, c => c.Name == ruleName);

            if (setting == null)
            {
                return;
            }

            var tmpText    = tmpRule.GetComponent <TMP_Text>();
            var canApplyTo = setting.CanApplyTo(tmpText);

            if (!canApplyTo)
            {
                return;
            }

            Undo.RecordObject(tmpText, "Inspector");
            setting.ApplyTo(tmpText);
            EditorUtility.SetDirty(tmpText);
        }
Example #4
0
        //==============================================================================
        // 関数
        //==============================================================================
        /// <summary>
        /// GUI を表示する時に呼び出されます
        /// </summary>
        public override void OnInspectorGUI()
        {
            if (m_settings == null)
            {
                m_settings = TMPRuleEditorUtils.GetSettings();

                if (m_settings == null)
                {
                    return;
                }
            }

            var tmpRuleSelf = ( TMPRule )target;
            var list        = m_settings.List;
            var index       = Array.FindIndex(list, x => x.Name == tmpRuleSelf.RuleName) + 1;

            // プルダウンメニューの先頭に「無効」を追加
            var invalidOption = new[] { TMPRule.INVALID_RULE_NAME };
            var options       = invalidOption.Concat(list.Select(x => x.Comment)).ToArray();

            EditorGUI.BeginChangeCheck();

            index = EditorGUILayout.Popup("ルール名", index, options);

            if (GUILayout.Button("設定ファイル"))
            {
                EditorGUIUtility.PingObject(m_settings);
            }

            if (!EditorGUI.EndChangeCheck())
            {
                return;
            }

            var ruleName = index == 0
                                        ? TMPRule.INVALID_RULE_NAME
                                        : list[index - 1].Name
            ;

            // 複数選択されている場合に、選択されている
            // すべてのオブジェクトのパラメータを更新するために targets を参照
            foreach (var tmpRule in targets.OfType <TMPRule>())
            {
                var serializedObject   = new SerializedObject(tmpRule);
                var serializedProperty = serializedObject.FindProperty("m_ruleName");

                serializedProperty.stringValue = ruleName;
                serializedObject.ApplyModifiedProperties();

                TMPRuleEditorUtils.Apply(m_settings, tmpRule);
            }
        }
Example #5
0
        /// <summary>
        /// 指定された TMPRule の設定を反映します
        /// </summary>
        private static void Apply(TMPRule tmpRule)
        {
            if (m_settings == null)
            {
                m_settings = TMPRuleEditorUtils.GetSettings();

                if (m_settings == null)
                {
                    return;
                }
            }

            TMPRuleEditorUtils.Apply(m_settings, tmpRule);
        }