KevS
1
I’m trying to use this function : GUIStyle.DrawWithTextSelection
void OnGUI ()
{
text = new GUIContent ("I want select this part by code");
if (Event.current.type == EventType.Repaint) {
myLabelID = GUIUtility.GetControlID (text, FocusType.Keyboard, rect);
GUI.skin.GetStyle ("MyLabel").DrawWithTextSelection (rect, text, myLabelID, 5, 10);
}
}
It draw my text, but with no selection. What i missed ? 
dkozar
2
Due to internal bug, the selection is displayed only if setting GUIUtility.keyboardControl.
Try this:
using UnityEngine;
using System.Collections;
/// <summary>
/// Selection test.
/// Author: Danko Kozar
/// </summary>
public class SelectionTest : MonoBehaviour {
private GUIContent _text;
private Rect _rect = new Rect(100, 100, 200, 150);
void OnGUI ()
{
_text = new GUIContent ("I want select this part by code");
if (Event.current.type == EventType.Repaint) {
int id = GUIUtility.GetControlID (_text, FocusType.Keyboard, _rect);
GUIUtility.keyboardControl = id; // added
GUI.skin.textArea.DrawWithTextSelection(_rect, _text, id, 5, 10);
}
}
}