public static CreateNodeMenu ( Vector2, position, GenericMenu, MenuCallback ) : void | ||
position | Vector2, | |
MenuCallback | GenericMenu, | |
Результат | void |
public static void CreateNodeMenu(Vector2 position, GenericMenu.MenuFunction2 MenuCallback)
{
GenericMenu menu = new GenericMenu();
var assembly = Assembly.Load(new AssemblyName("Assembly-CSharp"));
var paramTypes = (from t in assembly.GetTypes() where t.IsSubclassOfRawGeneric(typeof(AParameterNode<>)) && !t.IsAbstract select t).ToArray();
var flowTypes = (from t in assembly.GetTypes() where t.IsSubclassOfRawGeneric(typeof(AFlowNode)) && !t.IsAbstract select t).ToArray();
foreach(System.Type t in paramTypes) {
menu.AddItem(new GUIContent(string.Format("Parameter Nodes/{0}", t.Name)), false, MenuCallback, new NodeCallbackData(position, t));
}
foreach(System.Type t in flowTypes) {
menu.AddItem(new GUIContent(string.Format("Flow Nodes/{0}", t.Name)), false, MenuCallback, new NodeCallbackData(position, t));
}
menu.AddItem(new GUIContent("TaskNode"), false, MenuCallback, new NodeCallbackData(position, typeof(TaskNode)));
menu.AddItem(new GUIContent("TreeNode"), false, MenuCallback, new NodeCallbackData(position, typeof(TreeNode)));
menu.ShowAsContext();
}
private void InputHandler() { if (_target == null) { return; } int controlID = GUIUtility.GetControlID(new GUIContent("grid view"), FocusType.Passive); Event current = Event.current; Rect r = new Rect(0f, 0f, _currentViewWidth + 1f, position.height); if ((current.type == EventType.MouseDown || current.type == EventType.MouseUp)) { Selection.activeObject = _target; if (r.Contains(current.mousePosition)) { return; } } if (current.button == 1 && current.type == EventType.MouseDown && _target != null) { NodeFactory.CreateNodeMenu(current.mousePosition, MenuCallback); current.Use(); return; } if (current.button != 2) { return; } switch (current.GetTypeForControl(controlID)) { case EventType.MouseDown: GUIUtility.hotControl = controlID; current.Use(); EditorGUIUtility.SetWantsMouseJumping(1); break; case EventType.MouseUp: if (GUIUtility.hotControl == controlID) { GUIUtility.hotControl = 0; current.Use(); EditorGUIUtility.SetWantsMouseJumping(0); } break; case EventType.MouseMove: case EventType.MouseDrag: if (GUIUtility.hotControl == controlID) { if (_treeDrawer != null) { _treeDrawer.OffsetNodes(current.delta); } current.Use(); } break; } }