public static void DrawWindow(UdonGraph graph, UdonGraphGUI graphGUI)
        {
            if (_instance == null)
            {
                _instance = CreateInstance <UdonNodeSearchMenu>();
            }

            Rect rect      = GUILayoutUtility.GetLastRect();
            bool goodState = graphGUI.selection.Count == 0;

            if (goodState)
            {
                goodState = GUI.GetNameOfFocusedControl() != "NodeField";
            }

            if (goodState && KeyUpEvent(KeyCode.Space) && !Event.current.shift)
            {
                GUI.UnfocusWindow();
            }

            if (!GUILayout.Button("Add Node", EditorStyles.toolbarButton, GUILayout.Width(120)) && !(KeyUpEvent(KeyCode.Space) && goodState))
            {
                return;
            }

            rect = RemapRectForPopup(rect);
            _instance.InitWindow(graph, graphGUI, rect);
            _instance.Repaint();
        }
Beispiel #2
0
        private void OnEnable()
        {
            titleContent = new GUIContent("Udon Graph");

            graph          = CreateInstance <UdonGraph>();
            graphGUI       = CreateInstance <UdonGraphGUI>();
            graphGUI.graph = graph;

            Texture2D logoTexture = Resources.Load <Texture2D>(EditorGUIUtility.isProSkin ? "UdonLogoAlphaWhite" : "UdonLogoAlpha");

            _udonLogo = new GUIStyle
            {
                normal =
                {
                    background = logoTexture,
                    textColor  = Color.white
                },
                fixedHeight = (int)(logoTexture.height * CONTENT_LOGO_SCALE),
                fixedWidth  = (int)(logoTexture.width * CONTENT_LOGO_SCALE)
            };

            // ReSharper disable once DelegateSubtraction
            Undo.undoRedoPerformed -= OnUndoRedo; //Remove old handler if present to prevent duplicates, doesn't cause errors if not present
            Undo.undoRedoPerformed += OnUndoRedo;
        }
        private void InitWindow(UdonGraph graph, UdonGraphGUI graphGUI, Rect rect)
        {
            _dropDownRect  = rect;
            _graph         = graph;
            _graphGUI      = graphGUI;
            _styles        = new Styles();
            wantsMouseMove = true;

            if (NodeMenu.MenuName == null)
            {
                new Thread(() =>
                {
                    Thread.CurrentThread.IsBackground = true;
                    NodeMenu.PopulateNodeMenu();
                }).Start();
            }

            _dropDownWidth = rect.width;
            ShowAsDropDown(rect, new Vector2(rect.width, DROPDOWN_HEIGHT));
            Focus();
        }
Beispiel #4
0
        private void OnGUILogic()
        {
            _drawGraph = true;

            if (Selection.gameObjects.Count(g => g.GetComponent <UdonBehaviour>()) > 1)
            {
                _displayText = "Multi-object editing not supported";
                _drawGraph   = false;
            }
            else if (Selection.objects.Count(o => o != null && o is IUdonGraphDataProvider) > 1) // == typeof(UdonGraphProgramAsset)
            {
                _displayText = "Multi-object editing not supported";
                _drawGraph   = false;
            }

            IUdonGraphDataProvider udonGraphProgramAsset = (IUdonGraphDataProvider)Selection.objects.FirstOrDefault(g => g != null && g is IUdonGraphDataProvider);

            if (udonGraphProgramAsset == null)
            {
                GameObject behaviourObject = Selection.gameObjects.FirstOrDefault(g => g.GetComponent <UdonBehaviour>());
                if (behaviourObject != null)
                {
                    UdonBehaviour udonBehaviour;
                    var           udonBehaviours = behaviourObject.GetComponents <UdonBehaviour>();
                    if (udonBehaviours.Length == 1 || lastClickedProgramSource == null)
                    {
                        udonBehaviour = udonBehaviours[0];
                    }
                    else
                    {
                        udonBehaviour = udonBehaviours.FirstOrDefault(u => u.programSource == lastClickedProgramSource);
                        if (udonBehaviour == null)
                        {
                            // the last clicked graph is not available on this object, reset it
                            lastClickedProgramSource = null;
                            udonBehaviour            = udonBehaviours[0];
                        }
                    }
                    AbstractUdonProgramSource programSource = udonBehaviour.programSource;
                    if (programSource is IUdonGraphDataProvider asUdonGraphProgramAsset)
                    {
                        udonGraphProgramAsset = asUdonGraphProgramAsset;
                    }
                }
            }

            if (graph == null)
            {
                graph = CreateInstance <UdonGraph>();
            }

            if (udonGraphProgramAsset != null)
            {
                if (graphGUI == null)
                {
                    graphGUI       = CreateInstance <UdonGraphGUI>();
                    graphGUI.graph = graph;
                }
                if (graph == null)
                {
                    graph          = CreateInstance <UdonGraph>();
                    graphGUI.graph = graph;
                }

                if (graph.graphProgramAsset == udonGraphProgramAsset)
                {
                    if (graph.data != null)
                    {
                        return;
                    }
                }

                titleContent = new GUIContent($"Udon - {udonGraphProgramAsset}");

                graph.data = new UdonGraphData(udonGraphProgramAsset.GetGraphData());
                graph.graphProgramAsset = udonGraphProgramAsset;
                graph.Reload();
                graphGUI.CenterGraph();
            }
            else
            {
                if (graph.graphProgramAsset != null)
                {
                    return;
                }

                _displayText = "Create an Udon Graph Asset to begin.";
                _drawGraph   = false;
            }
        }