Beispiel #1
0
    public void ShowNodeCreationMenu()
    {
        if (NodifyEditorUtilities.currentSelectedGroup == null)
        {
            return;
        }

        GenericMenu menu = new GenericMenu();

        InitializeCreateNodeMenu();
        foreach (CreateMenu menuItem in createNodeMenuItems)
        {
            object[] argArray = new object[] { menuItem.type, menuItem.name, Event.current.mousePosition - NodifyEditorUtilities.currentSelectedGroup.editorWindowOffset, menuItem.iconResourcePath };

            menu.AddItem(new GUIContent(menuItem.path), false, delegate(object args)
            {
                object[] argToArray = (object[])args;

                System.Type type   = (System.Type)argToArray[0];
                GameObject nodeObj = new GameObject((string)argToArray[1]);

                                #if UNITY_5
                Node nodeClass = (Node)nodeObj.AddComponent(type);
                                #else
                Node nodeClass = (Node)UnityEngineInternal.APIUpdaterRuntimeServices.AddComponent(nodeObj, "Assets/Nodify/Editor/NodifyEditorWindow.cs (800,29)", type.Name);
                                #endif
                nodeClass.editorPosition     = (Vector2)argToArray[2];
                nodeClass.editorResourceIcon = (string)argToArray[3];
                nodeClass.OnEditorNodeCreated();
                nodeObj.transform.SetParent(NodifyEditorUtilities.currentSelectedGroup.transform);

                Undo.RegisterCreatedObjectUndo(nodeObj, "Create " + type.Name);
            }, argArray);
        }

        menu.AddSeparator("");

        menu.AddItem(new GUIContent("New Group"), false, delegate(object args)
        {
            GameObject nGroup            = new GameObject("NewGroup");
            NodeGroup nGroupClass        = nGroup.AddComponent <NodeGroup>();
            nGroupClass.transform.parent = NodifyEditorUtilities.currentSelectedGroup.transform;
            nGroupClass.editorPosition   = (Vector2)args;
            nGroupClass.OnEditorNodeCreated();
        }, Event.current.mousePosition - NodifyEditorUtilities.currentSelectedGroup.editorWindowOffset);

        if (Selection.objects.Length > 0)
        {
            if (Selection.objects.Length > 1 || (Selection.objects.Length == 1 && !Selection.Contains(NodifyEditorUtilities.currentSelectedGroup.gameObject)))
            {
                menu.AddItem(new GUIContent("New Group [with selected]"), false, delegate(object args)
                {
                    GameObject nGroup            = new GameObject("NewGroup");
                    NodeGroup nGroupClass        = nGroup.AddComponent <NodeGroup>();
                    nGroupClass.transform.parent = NodifyEditorUtilities.currentSelectedGroup.transform;
                    nGroupClass.editorPosition   = (Vector2)args;
                    nGroupClass.OnEditorNodeCreated();

                    foreach (GameObject obj in Selection.gameObjects)
                    {
                        if (obj != NodifyEditorUtilities.currentSelectedGroup.gameObject && obj.GetComponent <Node>())
                        {
                            obj.transform.parent = nGroupClass.transform;
                        }
                    }
                }, Event.current.mousePosition - NodifyEditorUtilities.currentSelectedGroup.editorWindowOffset);
            }
        }

        menu.ShowAsContext();
    }