Example #1
0
        public void LoadGraph()
        {
            List <PropertyCollector.TextureInfo> lti;
            var assetCollection = new AssetCollection();

            ShaderGraphImporter.GetShaderText(kGraphName, out lti, assetCollection, out m_Graph);
            Assert.NotNull(m_Graph, $"Invalid graph data found for {kGraphName}");

            m_Graph.ValidateGraph();

            m_Collector = new PropertyCollector();
            m_Graph.CollectShaderProperties(m_Collector, GenerationMode.ForReals);

            // Open up the window
            if (!ShaderGraphImporterEditor.ShowGraphEditWindow(kGraphName))
            {
                Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + kGraphName);
            }

            m_Window = EditorWindow.GetWindow <MaterialGraphEditWindow>();
            if (m_Window == null)
            {
                Assert.Fail("Could not open window");
            }

            // EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null.
            if (m_Window.graphObject == null)
            {
                Assert.Fail("Existing Shader Graph window of " + kGraphName + " not found.");
            }

            m_GraphEditorView = m_Window.graphEditorView;

            // Create the blackboard test controller
            var blackboardViewModel = new BlackboardViewModel()
            {
                parentView = m_Window.graphEditorView.graphView, model = m_Window.graphObject.graph, title = m_Window.assetName
            };

            m_BlackboardTestController = new BlackboardTestController(m_Window, m_Graph, blackboardViewModel, m_Window.graphObject.graphDataStore);

            // Remove the normal blackboard
            m_GraphEditorView.blackboardController.blackboard.RemoveFromHierarchy();

            // And override reference to the blackboard controller to point at the test controller
            m_GraphEditorView.blackboardController = m_BlackboardTestController;
        }
Example #2
0
        static void CreateBlackboardCategory(BlackboardTestController blackboardTestController)
        {
            var menuItems = blackboardTestController.addBlackboardItemsMenu.GetPrivateProperty <IList>("menuItems");

            Assert.IsNotNull(menuItems, "Could not retrieve reference to the menu items of the Blackboard Add Items menu");

            // Create category
            // We know that category is at the top of the menu items, so we can invoke it that way,
            // though ideally we would not be reliant on the in-menu order in such an explicit way as that can easily break or change
            var categoryMenuObject = menuItems[0];

            if (categoryMenuObject != null)
            {
                var menuFunction = categoryMenuObject.GetNonPrivateField <GenericMenu.MenuFunction>("func");
                menuFunction?.Invoke();
            }
        }