Ejemplo n.º 1
0
        public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorListener)
            : base(null, ShaderPort.Create(node.GetOutputSlots <MaterialSlot>().First(), edgeConnectorListener))
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNodeView"));
            this.node   = node;
            viewDataKey = node.objectId.ToString();
            userData    = node;

            // Getting the generatePropertyBlock property to see if it is exposed or not
            var graph    = node.owner as GraphData;
            var property = node.property;
            var icon     = (graph.isSubGraph || (property.isExposable && property.generatePropertyBlock)) ? exposedIcon : null;

            this.icon = icon;

            // Setting the position of the node, otherwise it ends up in the center of the canvas
            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

            // Removing the title label since it is not used and taking up space
            this.Q("title-label").RemoveFromHierarchy();

            // Add disabled overlay
            Add(new VisualElement()
            {
                name = "disabledOverlay", pickingMode = PickingMode.Ignore
            });

            // Update active state
            SetActive(node.isActive);

            // Registering the hovering callbacks for highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);
        }
Ejemplo n.º 2
0
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);

            m_CurrentValue = new Label();

            extensionContainer.Add(m_CurrentValue);
            RefreshExpandedState();
        }
Ejemplo n.º 3
0
        public static new ReddotPort Create <TEdge>(Orientation orientation, Direction direction, Capacity capacity, Type type) where TEdge : Edge, new()
        {
            EdgeConnectorListener listener = new EdgeConnectorListener();
            ReddotPort            port     = new ReddotPort(orientation, direction, capacity, type)
            {
                m_EdgeConnector = new EdgeConnector <TEdge>(listener)
            };

            port.AddManipulator(port.m_EdgeConnector);
            return(port);
        }
Ejemplo n.º 4
0
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);

            styleSheets.Add(Resources.Load <StyleSheet>("Styles/ExecNodeView"));
            AddToClassList("execNodeView");

            // Customize placement of the default exec IO ports
            PortView inView  = GetInputPort("_execIn");
            PortView outView = GetOutputPort("_execOut");

            inView.AddToClassList("execInPortView");
            outView.AddToClassList("execOutPortView");
        }
Ejemplo n.º 5
0
        // TODO: It makes sense just to add this behavior to the base node view
        // and let the developer define templates to use for icons.
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);

            styleSheets.Add(Resources.Load <StyleSheet>("Styles/IconNodeView"));
            AddToClassList("iconNodeView");

            VisualElement iconContainer = new VisualElement
            {
                name = "icon"
            };

            string iconName  = null;
            bool   showTitle = true;

            foreach (var attr in node.GetType().GetCustomAttributes(false))
            {
                if (attr is NodeIconAttribute iconAttr)
                {
                    iconName  = iconAttr.iconName;
                    showTitle = iconAttr.showTitle;
                    break;
                }
            }

            if (showTitle)
            {
                var titleLabel = new Label();
                titleLabel.text = title;
                titleLabel.AddToClassList("iconNodeTitle");

                iconContainer.Add(titleLabel);
            }

            if (iconName != null)
            {
                var icon = Resources.Load <Texture2D>(iconName);
                iconContainer.style.backgroundImage = icon;
            }

            inputContainer.parent.Add(iconContainer);
            iconContainer.PlaceInFront(inputContainer);
        }
Ejemplo n.º 6
0
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);
            m_target = node as MeshPreviewTestNode;

            m_PreviewUtility = new PreviewRenderUtility();

            // Add a slider to rotate the preview mesh
            var slider = new Slider(0f, 360f, SliderDirection.Horizontal);

            slider.RegisterValueChangedCallback(OnSliderChange);

            // Setup a container to render IMGUI content in
            var container = new IMGUIContainer(OnGUI);

            extensionContainer.Add(slider);
            extensionContainer.Add(container);

            // Currently needed by Unity's base Node class to properly
            // resize for extensionContent. Might be a bug.
            RefreshExpandedState();
        }
Ejemplo n.º 7
0
        public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorListener)
            : base(null, ShaderPort.Create(node.GetOutputSlots <MaterialSlot>().First(), edgeConnectorListener))
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNodeView"));
            this.node   = node;
            viewDataKey = node.objectId.ToString();
            userData    = node;

            // Getting the generatePropertyBlock property to see if it is exposed or not
            UpdateIcon();

            // Setting the position of the node, otherwise it ends up in the center of the canvas
            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

            // Removing the title label since it is not used and taking up space
            this.Q("title-label").RemoveFromHierarchy();

            // Add disabled overlay
            Add(new VisualElement()
            {
                name = "disabledOverlay", pickingMode = PickingMode.Ignore
            });

            // Update active state
            SetActive(node.isActive);

            // Registering the hovering callbacks for highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);

            // add the right click context menu
            IManipulator contextMenuManipulator = new ContextualMenuManipulator(AddContextMenuOptions);

            this.AddManipulator(contextMenuManipulator);

            // Set callback association for display name updates
            property.displayNameUpdateTrigger += node.UpdateNodeDisplayName;
        }
Ejemplo n.º 8
0
        public PropertyNodeView(PropertyNode node, EdgeConnectorListener edgeConnectorListener)
            : base(null, ShaderPort.Create(node.GetOutputSlots <MaterialSlot>().First(), edgeConnectorListener))
        {
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/PropertyNodeView"));
            this.node = node;
            userData  = node;

            // Getting the generatePropertyBlock property to see if it is exposed or not
            var graph    = node.owner as GraphData;
            var property = graph.properties.FirstOrDefault(x => x.guid == node.propertyGuid);
            var icon     = property.generatePropertyBlock ? exposedIcon : null;

            this.icon = icon;

            // Setting the position of the node, otherwise it ends up in the center of the canvas
            SetPosition(new Rect(node.drawState.position.x, node.drawState.position.y, 0, 0));

            // Removing the title label since it is not used and taking up space
            this.Q("title-label").RemoveFromHierarchy();

            // Registering the hovering callbacks for highlighting
            RegisterCallback <MouseEnterEvent>(OnMouseHover);
            RegisterCallback <MouseLeaveEvent>(OnMouseHover);
        }
Ejemplo n.º 9
0
        public GraphNode(string titleLabel, string uxmlPath, string ussPath, Type runtimeType, EdgeConnectorListener edgeConnectorListener, SerializedNode serializedNode)
        {
            styleSheets.Remove(EditorGUIUtility.Load("StyleSheets/GraphView/Node.uss") as StyleSheet);
            m_serializedNode        = serializedNode;
            m_runtimeType           = runtimeType;
            m_runtimeInstance       = Activator.CreateInstance(m_runtimeType);
            m_edgeConnectorListener = edgeConnectorListener;

            if (m_serializedNode == null)
            {
                m_serializedNode = new SerializedNode
                {
                    Guid                  = System.Guid.NewGuid().ToString(),
                    IsExpanded            = true,
                    EditorPosition        = this.GetPosition().position,
                    NodeRuntimeTypeString = m_runtimeType.AssemblyQualifiedName,
                    SerializedPorts       = new List <SerializedPort>()
                };
            }
            else
            {
                SynchronizeFromSerializedNode();
            }
            //  Clear all default visual elements from the GraphView node.
            this.Clear();
            //  Load and bind our custom visual elements.
            LoadStyleSheet(ussPath);
            LoadUXML(uxmlPath);
            BindUXML();
            //  Run default node bootstrap
            BindGUIInternal();
            //  Run custom node boostrap
            OnBindGUI();

            title = titleLabel;
        }
Ejemplo n.º 10
0
        public GraphEditorView(EditorWindow editorWindow, AbstractNodeGraph graph)
        {
            m_Graph = graph;
            styleSheets.Add(Resources.Load <StyleSheet>("Styles/GraphEditorView"));

            string serializedWindowLayout = EditorUserSettings.GetConfigValue(k_FloatingWindowsLayoutKey);

            if (!string.IsNullOrEmpty(serializedWindowLayout))
            {
                m_FloatingWindowsLayout = JsonUtility.FromJson <FloatingWindowsLayout>(serializedWindowLayout);
            }


            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 NodeGraphView(m_Graph)
                {
                    name = "GraphView", viewDataKey = "NodeGraphView"
                };
                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);
                content.Add(m_GraphView);

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

                Rect blackboardLayout = m_BlackboardProvider.blackboard.layout;
                blackboardLayout.x = 10f;
                blackboardLayout.y = 10f;
                m_BlackboardProvider.blackboard.SetPosition(blackboardLayout);

                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 node in graph.GetNodes <INode>())
            {
                AddNode(node);
            }

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

            Add(content);
        }
Ejemplo n.º 11
0
        public override void Initialize(AbstractNode node, EdgeConnectorListener connectorListener)
        {
            base.Initialize(node, connectorListener);

            // Custom initialization logic goes here.
        }