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)))
            {
                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();
        }
Exemple #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();
        }
Exemple #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 = behaviourObject.GetComponent <UdonBehaviour>();
                    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;
                    }
                }

                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;
            }
        }