- Home /
The question is answered, right answer was accepted
Unity editor context scripts - on object selected draw text near it
I've created public class EditorMenuMyPrefab {
[MenuItem ("GameObject/Create Other/MyOwnPrefab")]
static void addMyPrefab(MenuCommand menuCommand) {
Object prefab = AssetDatabase.LoadAssetAtPath ("Assets/Prefabs/Path/MyOwnPrefab.prefab", typeof(GameObject));
if (prefab != null) {
GameObject newGameObject = (GameObject)PrefabUtility.InstantiatePrefab (prefab);
GameObjectUtility.SetParentAndAlign (newGameObject, menuCommand.context as GameObject);
Undo.RegisterCreatedObjectUndo (newGameObject, "Create " + newGameObject.name);
Selection.activeObject = newGameObject;
}
}
Now I wish to have a method which will draw text near this new generated object when I have it selected. That's the first question. Only in Editor context! So I do not want to put it in element script, I want it outside of game. Editor**.cs
Then I want to draw text near this. When I move object, this text would move with itself. I guess I'd have element, then I can take transform to take this position and print this text on that. But I can't print simplemessage using Handles, need example to use in method whcih is called on selecting elements. Ofc it'd have to be only attached to elements of some kind of prefabs, not all elements and filter it. It wouldn't be optimize.
Answer by Sarseth · Jan 06, 2016 at 11:07 AM
I've managed to draw text:
[CustomEditor (typeof(MyPrefab))]
public class EditorMyPrefab : Editor {
void OnSceneGUI () {
GameObject selectedObject = Selection.activeGameObject;
Handles.Label (selectedObject.transform.position, "SDADASD");
}
}
selectedObject can be null.
MyPrefab is a script attached to this prefab.
Can not answer my own question till atigin for moderation :( shame. But I could convert ^^ hacked ;d