コード例 #1
0
    //////////////////////////////////////////////////////////////////////////

    public void DrawNameSection()
    {
        m_NameLabel         = serializedObject.FindProperty("m_NameLabel");
        m_Text              = serializedObject.FindProperty("m_Text");
        m_Prefix            = serializedObject.FindProperty("m_Prefix");
        m_IsLocalizationKey = serializedObject.FindProperty("m_IsLocalizationKey");

        showNaming = DrawSectionHeader("Name", showNaming);

        if (showNaming)
        {
            // Name editing doesn't work in multi-select
            if (targets.Length > 1)
            {
                EditorGUILayout.LabelField("-- Multiple Values --", myLabelStyle);
                EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
            }
            else
            {
                UAP_BaseElement baseItem = (UAP_BaseElement)targets[0];
                if (!baseItem.m_IsInitialized)
                {
                    baseItem.Initialize();
                }

                EditorGUILayout.PropertyField(m_NameLabel, new GUIContent("Name Label", "If assigned, the plugin will read out the content of the label when this UI element receives focus."));

                if (baseItem.m_NameLabel != null)
                {
                    // Read the element's name from a reference label
                    string nameText = baseItem.GetText();
                    EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
                    EditorGUI.BeginDisabledGroup(baseItem.m_NameLabel != null);
                    EditorGUILayout.TextArea(nameText, myTextAreaInputStyle);
                    EditorGUI.EndDisabledGroup();
                    baseItem.m_TryToReadLabel = true;
                }
                else
                {
                    // Manual setup of the name
                    m_Text.stringValue = EditorGUILayout.TextArea(m_Text.stringValue, myTextAreaInputStyle);
                    EditorGUILayout.PropertyField(m_IsLocalizationKey, new GUIContent("Is Localization Key", "If set to true, the plugin will treat the name as a localization key and request the localization at runtime."));
                    // Display localized text if needed
                    if (m_IsLocalizationKey.boolValue)
                    {
                        ++EditorGUI.indentLevel;
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.TextArea(baseItem.GetText(), myTextAreaInputStyle);
                        EditorGUI.EndDisabledGroup();
                        --EditorGUI.indentLevel;
                    }
                    baseItem.m_TryToReadLabel = false;
                }
            }
        }
    }
    //////////////////////////////////////////////////////////////////////////

    public void DrawNameSection(bool showNameLabel = true)
    {
        m_NameLabel            = serializedObject.FindProperty("m_NameLabel");
        m_AdditionalNameLabels = serializedObject.FindProperty("m_AdditionalNameLabels");
        m_Text                    = serializedObject.FindProperty("m_Text");
        m_Prefix                  = serializedObject.FindProperty("m_Prefix");
        m_IsLocalizationKey       = serializedObject.FindProperty("m_IsLocalizationKey");
        m_PrefixIsLocalizationKey = serializedObject.FindProperty("m_PrefixIsLocalizationKey");
        m_PrefixIsPostFix         = serializedObject.FindProperty("m_PrefixIsPostFix");

        showNaming = DrawSectionHeader("Name", showNaming);

        if (showNaming)
        {
            // Name editing doesn't work in multi-select
            if (targets.Length > 1)
            {
                EditorGUILayout.LabelField("-- Multiple Values --", myLabelStyle);
                EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Prefix", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead."));
            }
            else
            {
                UAP_BaseElement baseItem = (UAP_BaseElement)targets[0];
                if (!baseItem.m_IsInitialized)
                {
                    baseItem.Initialize();
                }

                if (showNameLabel)
                {
                    EditorGUILayout.PropertyField(m_NameLabel, new GUIContent("Name Label", "If assigned, the plugin will read out the content of the label when this UI element receives focus.\nUse {0} in the prefix to place this text."));
                    // Only if at least 1 name label is set, allow the user to set more
                    if (m_NameLabel.objectReferenceValue != null)
                    {
                        EditorGUILayout.PropertyField(m_AdditionalNameLabels, new GUIContent("Combine Labels", "Additional label out of which the resulting text can be combined via {1}, {2}, etc..."), true);
                    }
                }
                else
                {
                    baseItem.m_NameLabel = null;
                }

                if (baseItem.m_NameLabel != null)
                {
                    // Read the element's name from a reference label
                    EditorGUILayout.PropertyField(m_Prefix, new GUIContent("Combine String", "Will automatically be added in front of the name if a label is set.\nYou can use the wildcard {0} to insert the label into your text instead.\nUse {1}, {2}, ... to access additional labels."));
                    EditorGUILayout.PropertyField(m_PrefixIsLocalizationKey, new GUIContent("Is Localization Key", "If set to true, the plugin will treat the name as a localization key and request the localization at runtime."));
                    if (m_AdditionalNameLabels.arraySize == 0)
                    {
                        EditorGUILayout.PropertyField(m_PrefixIsPostFix, new GUIContent("Is Postfix", "If set to true, the combination string will be add behind the label's content, not in front of it."));
                    }
                    string nameText = baseItem.GetTextToRead();
                    EditorGUI.BeginDisabledGroup(baseItem.m_NameLabel != null);
                    EditorGUILayout.TextArea(nameText, myTextAreaInputStyle);
                    EditorGUI.EndDisabledGroup();
                    baseItem.m_TryToReadLabel = true;
                }
                else
                {
                    // Manual setup of the name
                    m_Text.stringValue = EditorGUILayout.TextArea(m_Text.stringValue, myTextAreaInputStyle);
                    EditorGUILayout.PropertyField(m_IsLocalizationKey, new GUIContent("Is Localization Key", "If set to true, the plugin will treat the name as a localization key and request the localization at runtime."));
                    // Display localized text if needed
                    if (m_IsLocalizationKey.boolValue)
                    {
                        ++EditorGUI.indentLevel;
                        EditorGUI.BeginDisabledGroup(true);
                        EditorGUILayout.TextArea(baseItem.GetTextToRead(), myTextAreaInputStyle);
                        EditorGUI.EndDisabledGroup();
                        --EditorGUI.indentLevel;
                    }
                    baseItem.m_TryToReadLabel = false;
                }
            }
        }
    }