protected void ShowContextMenu() { if (Event.current.type != EventType.MouseDown || Event.current.button != 1 || Event.current.clickCount != 1) { return; } Event.current.Use(); Vector2 mousePosition = Event.current.mousePosition; Rect position = new Rect(mousePosition.x, mousePosition.y, 0f, 0f); List <GUIContent> list = new List <GUIContent>(); if (this.selection.Count != 0) { list.Add(new GUIContent("Cut")); list.Add(new GUIContent("Copy")); list.Add(new GUIContent("Duplicate")); list.Add(new GUIContent(string.Empty)); list.Add(new GUIContent("Delete")); } else { list.Add((this.edgeGUI.edgeSelection.Count != 0) ? new GUIContent("Delete") : new GUIContent("Paste")); } GUIContent[] options = list.ToArray(); GraphGUI.ContextMenuData userData = new GraphGUI.ContextMenuData { items = list.ToArray(), mousePosition = mousePosition }; this.m_contextMenuMouseDownPosition = null; EditorUtility.DisplayCustomMenu(position, options, -1, new EditorUtility.SelectMenuItemFunction(this.ContextMenuClick), userData); }
private void ContextMenuClick(object userData, string[] options, int selected) { if (selected < 0) { return; } GraphGUI.ContextMenuData contextMenuData = (GraphGUI.ContextMenuData)userData; string text = contextMenuData.items[selected].text; string text2 = text; if (text2 != null) { if (GraphGUI.< > f__switch$map3 == null) { GraphGUI.< > f__switch$map3 = new Dictionary <string, int>(5) { { "Cut", 0 }, { "Copy", 0 }, { "Duplicate", 0 }, { "Delete", 0 }, { "Paste", 1 } }; } int num; if (GraphGUI.< > f__switch$map3.TryGetValue(text2, out num)) { if (num != 0) { if (num == 1) { this.m_contextMenuMouseDownPosition = new Vector2?(contextMenuData.mousePosition); this.m_Host.SendEvent(EditorGUIUtility.CommandEvent(text)); } } else { this.m_Host.SendEvent(EditorGUIUtility.CommandEvent(text)); } } } }