Red de conocimiento informático - Material del sitio web - Cómo dibujar un menú personalizado en el editor de Unity

Cómo dibujar un menú personalizado en el editor de Unity

usando UnityEngine;

usando UnityEditor;

usando System.

// Haga clic contextual en el área verde para mostrar el menú

público clase GenericMenuExample: EditorWindow

{

[MenuItem("Ejemplo/Abrir ventana")]

static void Init()

{

var window = GetWindow();

window.position = new Rect(50, 50, 250, 60);

window.Show () ;

}

void Callback(object obj)

{

Debug.Log(" Seleccionado: " + obj) ;

}

void OnGUI()

{

Evento currentEvent = Event.current;

Rect contextRect = new Rect(10, 10, 100, 100);

EditorGUI.DrawRect(contextRect, Color.green);

if (currentEvent.type == EventType.ContextClick)

p>

{

Vector2 mousePos = currentEvent.mousePosition;

if (contextRect.DrawRect(contextRect, Color.green));

if ( currentEvent.type == EventType.ContextClick)

{

Vector2 mousePos = currentEvent.mousePosition;

if (contextRect.DrawRect(contextRect) )p>

Menú GenericMenu = new GenericMenu();

menu.AddItem(new GUIContent("MenuItem1"), false, Callback, "item 1");

menu.AddItem(new GUIContent("SubMenu/ MenuItem3"), false, Callback, "item 3");

menu.ShowAsContext();

Evento actual . Uso();

}

}

}

}

}

Utilice UnityEngine;

Utilice UnityEditor;

Utilice System.Custom EditorWindow.

//Haga clic contextualmente en el área verde para mostrar el menú

clase pública GenericMenuExample: EditorWindow

{

[MenuItem(" Ejemplo/Abrir ventana")]

static void Init()

{

var window = GetWindow();

ventana .posición = new Rect(50, 50, 250, 60);

Ventana. Show();

}

void Callback(object obj)

{

Debug.Log(" Seleccionado: " + obj );

}

void OnGUI()

{

Evento currentEvent = Event.current;

RectcontextRect = new Rect(10, 10, 100, 100);

EditorGUI.DrawRect(contextRect, Color.green);

If (currentEvent.type == EventType.ContextClick)

{

Vector2mousePos = currentEvent.mousePosition;

if (contextRect.if(contextRect.Contains(mousePos)))

{

// Ahora crea el menú, agrega elementos y muéstralo

GenericMenumenu = new GenericMenu();

menu.AddItem(new GUIContent("MenuItem1" ), false, devolución de llamada, "elemento 1");

menu.AddItem(new GUIContent("MenuItem1"), false, devolución de llamada, "elemento 1");