I tried to use this function but i wan’t work.
Is it wrong to use this?
I searched this but i can’t found any clue.
Please, Help me
Hi !
Same question, almost one year later xD
Here is my code :
GUI.skin = skin;
GUIContent text = new GUIContent (myText);
cursorIndex = GUI.skin.GetStyle ("MyLabel").GetCursorStringIndex (rect, text, Event.current.mousePosition);
if (Event.current.type == EventType.Repaint) {
int controlId = GUIUtility.GetControlID (text, FocusType.Passive);
GUI.skin.GetStyle ("MyLabel").DrawWithTextSelection (rect, text, controlId, 5, 20);
}
And no selection …
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 = new GUIContent ("I want select this part by code");
private Rect _rect = new Rect(100, 100, 200, 150);
void OnGUI ()
{
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);
}
}
}