Ejemplo n.º 1
0
    void RichTextButtons(SerializedProperty _text, int _index)
    {
        EditorGUILayout.BeginHorizontal();

        lastTextSelected = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);

        // Adds <b> and </b> with the selected text between
        if (GUILayout.Button("Bold"))
        {
            if (!string.IsNullOrEmpty(lastTextSelected.text) && lastTextSelected.hasSelection)
            {
                lastTextSelected.ReplaceSelection($"<b>{lastTextSelected.SelectedText}</b>");
                _text.GetArrayElementAtIndex(_index).stringValue = lastTextSelected.text;
            }
        }

        // Adds <u> and </u> with the selected text between
        if (GUILayout.Button("Underline"))
        {
            if (!string.IsNullOrEmpty(lastTextSelected.text) && lastTextSelected.hasSelection)
            {
                lastTextSelected.ReplaceSelection($"<u>{lastTextSelected.SelectedText}</u>");
                _text.GetArrayElementAtIndex(_index).stringValue = lastTextSelected.text;
            }
        }

        // Adds <i> and </i> with the selected text between
        if (GUILayout.Button("Italic"))
        {
            if (!string.IsNullOrEmpty(lastTextSelected.text) && lastTextSelected.hasSelection)
            {
                lastTextSelected.ReplaceSelection($"<i>{lastTextSelected.SelectedText}</i>");
                _text.GetArrayElementAtIndex(_index).stringValue = lastTextSelected.text;
            }
        }

        if (GUILayout.Button("Color"))
        {
            ColorPopup.Init(this, _text, _index);
        }

        if (GUILayout.Button("Size"))
        {
            SizePopup.Init(this, _text, _index);
        }

        EditorGUILayout.EndHorizontal();
    }