Exemple #1
0
        public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName)
        {
            m_Graph = graph;
            AddStyleSheetPath("Styles/MaterialGraph");
            m_EditorWindow = editorWindow;
            previewManager = new PreviewManager(graph);

            var toolbar = new IMGUIContainer(() =>
            {
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (GUILayout.Button("Save Asset", EditorStyles.toolbarButton))
                {
                    if (saveRequested != null)
                    {
                        saveRequested();
                    }
                }
                GUILayout.Space(6);
                if (GUILayout.Button("Show In Project", EditorStyles.toolbarButton))
                {
                    if (showInProjectRequested != null)
                    {
                        showInProjectRequested();
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            });

            Add(toolbar);

            var content = new VisualElement {
                name = "content"
            };

            {
                m_GraphView = new MaterialGraphView(graph)
                {
                    name = "GraphView", persistenceKey = "MaterialGraphView"
                };
                m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale);
                m_GraphView.AddManipulator(new ContentDragger());
                m_GraphView.AddManipulator(new SelectionDragger());
                m_GraphView.AddManipulator(new RectangleSelector());
                m_GraphView.AddManipulator(new ClickSelector());
                m_GraphView.AddManipulator(new GraphDropTarget(graph));
                m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown);
                content.Add(m_GraphView);

                m_BlackboardProvider = new BlackboardProvider(assetName, graph);
                m_GraphView.Add(m_BlackboardProvider.blackboard);
                m_BlackboardProvider.blackboard.layout = new Rect(new Vector2(10f, 10f), m_BlackboardProvider.blackboard.layout.size);

                m_MasterPreviewView = new MasterPreviewView(assetName, previewManager, graph)
                {
                    name = "masterPreview"
                };

                WindowDraggable masterPreviewViewDraggable = new WindowDraggable();
                m_MasterPreviewView.AddManipulator(masterPreviewViewDraggable);
                m_GraphView.Add(m_MasterPreviewView);

                ResizeBorderFrame masterPreviewResizeBorderFrame = new ResizeBorderFrame(m_MasterPreviewView)
                {
                    name = "resizeBorderFrame"
                };
                masterPreviewResizeBorderFrame.stayWithinParentBounds = true;
                masterPreviewResizeBorderFrame.maintainAspectRatio    = true;
                masterPreviewResizeBorderFrame.OnResizeFinished      += UpdateSerializedWindowLayout;
                m_MasterPreviewView.Add(masterPreviewResizeBorderFrame);

                m_BlackboardProvider.onDragFinished             += UpdateSerializedWindowLayout;
                m_BlackboardProvider.onResizeFinished           += UpdateSerializedWindowLayout;
                masterPreviewViewDraggable.OnDragFinished       += UpdateSerializedWindowLayout;
                masterPreviewResizeBorderFrame.OnResizeFinished += UpdateSerializedWindowLayout;

                m_GraphView.graphViewChanged = GraphViewChanged;

                RegisterCallback <PostLayoutEvent>(ApplySerializewindowLayouts);
            }

            m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>();
            m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView);
            m_GraphView.nodeCreationRequest = (c) =>
            {
                m_SearchWindowProvider.connectedPort = null;
                SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider);
            };

            m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider);

            foreach (var node in graph.GetNodes <INode>())
            {
                AddNode(node);
            }

            foreach (var edge in graph.edges)
            {
                AddEdge(edge);
            }

            Add(content);
        }
        public GraphEditorView(EditorWindow editorWindow, GraphData graph, MessageManager messageManager)
        {
            m_Graph          = graph;
            m_MessageManager = messageManager;
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/GraphEditorView"));
            previewManager = new PreviewManager(graph, messageManager);
            previewManager.onPrimaryMasterChanged = OnPrimaryMasterChanged;

            string serializedToggle = EditorUserSettings.GetConfigValue(k_ToggleSettings);

            if (!string.IsNullOrEmpty(serializedToggle))
            {
                m_ToggleSettings = JsonUtility.FromJson <ToggleSettings>(serializedToggle);
            }

            string serializedWindowLayout = EditorUserSettings.GetConfigValue(k_FloatingWindowsLayoutKey);

            if (!string.IsNullOrEmpty(serializedWindowLayout))
            {
                m_FloatingWindowsLayout = JsonUtility.FromJson <FloatingWindowsLayout>(serializedWindowLayout);
            }
            else
            {
                m_FloatingWindowsLayout = new FloatingWindowsLayout
                {
                    blackboardLayout =
                    {
                        dockingTop       = true,
                        dockingLeft      = true,
                        verticalOffset   =              16,
                        horizontalOffset =              16,
                        size             = new Vector2(200, 400)
                    }
                };
            }

            if (m_FloatingWindowsLayout.masterPreviewSize.x > 0f && m_FloatingWindowsLayout.masterPreviewSize.y > 0f)
            {
                previewManager.ResizeMasterPreview(m_FloatingWindowsLayout.masterPreviewSize);
            }

            previewManager.RenderPreviews();
            var toolbar = new IMGUIContainer(() =>
            {
                GUILayout.BeginHorizontal(EditorStyles.toolbar);
                if (GUILayout.Button("Save Asset", EditorStyles.toolbarButton))
                {
                    if (saveRequested != null)
                    {
                        saveRequested();
                    }
                }
                GUILayout.Space(6);
                if (GUILayout.Button("Show In Project", EditorStyles.toolbarButton))
                {
                    if (showInProjectRequested != null)
                    {
                        showInProjectRequested();
                    }
                }

                GUILayout.FlexibleSpace();

                EditorGUI.BeginChangeCheck();
                m_ToggleSettings.isBlackboardVisible = GUILayout.Toggle(m_ToggleSettings.isBlackboardVisible, "Blackboard", EditorStyles.toolbarButton);

                GUILayout.Space(6);

                m_ToggleSettings.isPreviewVisible = GUILayout.Toggle(m_ToggleSettings.isPreviewVisible, "Main Preview", EditorStyles.toolbarButton);
                if (EditorGUI.EndChangeCheck())
                {
                    m_MasterPreviewView.visible             = m_ToggleSettings.isPreviewVisible;
                    m_BlackboardProvider.blackboard.visible = m_ToggleSettings.isBlackboardVisible;
                    string serializedToggleables            = JsonUtility.ToJson(m_ToggleSettings);
                    EditorUserSettings.SetConfigValue(k_ToggleSettings, serializedToggleables);
                }
                GUILayout.EndHorizontal();
            });

            Add(toolbar);

            var content = new VisualElement {
                name = "content"
            };

            {
                m_GraphView = new MaterialGraphView(graph)
                {
                    name = "GraphView", viewDataKey = "MaterialGraphView"
                };
                m_GraphView.SetupZoom(0.05f, ContentZoomer.DefaultMaxScale);
                m_GraphView.AddManipulator(new ContentDragger());
                m_GraphView.AddManipulator(new SelectionDragger());
                m_GraphView.AddManipulator(new RectangleSelector());
                m_GraphView.AddManipulator(new ClickSelector());
                m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown);
                m_GraphView.groupTitleChanged        = OnGroupTitleChanged;
                m_GraphView.elementsAddedToGroup     = OnElementsAddedToGroup;
                m_GraphView.elementsRemovedFromGroup = OnElementsRemovedFromGroup;
                content.Add(m_GraphView);

                m_BlackboardProvider = new BlackboardProvider(graph);
                m_GraphView.Add(m_BlackboardProvider.blackboard);

                // Initialize toggle settings if it doesnt exist.
                if (m_ToggleSettings == null)
                {
                    m_ToggleSettings = new ToggleSettings();
                }
                m_BlackboardProvider.blackboard.visible = m_ToggleSettings.isBlackboardVisible;

                CreateMasterPreview();

                m_GraphView.graphViewChanged = GraphViewChanged;

                RegisterCallback <GeometryChangedEvent>(ApplySerializewindowLayouts);
            }

            m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>();
            m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView);
            m_GraphView.nodeCreationRequest = (c) =>
            {
                m_SearchWindowProvider.connectedPort = null;
                SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider);
            };

            m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider);

            foreach (var graphGroup in graph.groups)
            {
                AddGroup(graphGroup);
            }

            foreach (var node in graph.GetNodes <AbstractMaterialNode>())
            {
                AddNode(node);
            }

            foreach (var edge in graph.edges)
            {
                AddEdge(edge);
            }

            Add(content);
        }
Exemple #3
0
        public GraphEditorView(EditorWindow editorWindow, AbstractMaterialGraph graph, string assetName)
        {
            m_Graph = graph;
            AddStyleSheetPath("Styles/MaterialGraph");
            m_EditorWindow = editorWindow;
            previewManager = new PreviewManager(graph);

            var content = new VisualElement {
                name = "content"
            };

            {
                m_GraphView = new MaterialGraphView(graph)
                {
                    name = "GraphView", persistenceKey = "MaterialGraphView"
                };
                m_GraphView.SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
                m_GraphView.AddManipulator(new ContentDragger());
                m_GraphView.AddManipulator(new SelectionDragger());
                m_GraphView.AddManipulator(new RectangleSelector());
                m_GraphView.AddManipulator(new ClickSelector());
                m_GraphView.AddManipulator(new GraphDropTarget(graph));
                content.Add(m_GraphView);

                m_GraphInspectorView = new GraphInspectorView(assetName, previewManager, graph)
                {
                    name = "inspector"
                };
                m_GraphInspectorView.AddManipulator(new Draggable(OnMouseDrag, true));
                m_GraphView.RegisterCallback <PostLayoutEvent>(OnPostLayout);
                m_GraphInspectorView.RegisterCallback <PostLayoutEvent>(OnPostLayout);

                m_GraphView.RegisterCallback <KeyDownEvent>(OnSpaceDown);

                m_GraphView.Add(m_GraphInspectorView);

                m_GraphView.graphViewChanged = GraphViewChanged;
            }

            m_SearchWindowProvider = ScriptableObject.CreateInstance <SearchWindowProvider>();
            m_SearchWindowProvider.Initialize(editorWindow, m_Graph, m_GraphView);
            m_GraphView.nodeCreationRequest = (c) =>
            {
                m_SearchWindowProvider.connectedPort = null;
                SearchWindow.Open(new SearchWindowContext(c.screenMousePosition), m_SearchWindowProvider);
            };

            m_EdgeConnectorListener = new EdgeConnectorListener(m_Graph, m_SearchWindowProvider);

            foreach (var node in graph.GetNodes <INode>())
            {
                AddNode(node);
            }

            foreach (var edge in graph.edges)
            {
                AddEdge(edge);
            }

            Add(content);
        }