示例#1
0
        void AddItemRequested(SGBlackboard blackboard)
        {
            var gm = new GenericMenu();

            AddPropertyItems(gm);
            AddKeywordItems(gm);
            gm.ShowAsContext();
        }
示例#2
0
        public BlackboardProvider(GraphData graph, GraphView associatedGraphView)
        {
            m_Graph     = graph;
            m_InputRows = new Dictionary <ShaderInput, BlackboardRow>();

            blackboard = new SGBlackboard(associatedGraphView)
            {
                subTitle          = FormatPath(graph.path),
                editTextRequested = EditTextRequested,
                addItemRequested  = AddItemRequested,
                moveItemRequested = MoveItemRequested
            };

            // These make sure that the drag indicators are disabled whenever a drag action is cancelled without completing a drop
            blackboard.RegisterCallback <MouseUpEvent>(evt =>
            {
                m_PropertySection.OnDragActionCanceled();
                m_KeywordSection.OnDragActionCanceled();
            });

            blackboard.RegisterCallback <DragExitedEvent>(evt =>
            {
                m_PropertySection.OnDragActionCanceled();
                m_KeywordSection.OnDragActionCanceled();
            });


            m_PathLabel = blackboard.hierarchy.ElementAt(0).Q <Label>("subTitleLabel");
            m_PathLabel.RegisterCallback <MouseDownEvent>(OnMouseDownEvent);

            m_PathLabelTextField = new TextField {
                visible = false
            };
            m_PathLabelTextField.Q("unity-text-input").RegisterCallback <FocusOutEvent>(e => { OnEditPathTextFinished(); });
            m_PathLabelTextField.Q("unity-text-input").RegisterCallback <KeyDownEvent>(OnPathTextFieldKeyPressed);
            blackboard.hierarchy.Add(m_PathLabelTextField);

            m_PropertySection = new SGBlackboardSection {
                title = "Properties"
            };
            foreach (var property in graph.properties)
            {
                AddInputRow(property);
            }
            blackboard.Add(m_PropertySection);

            m_KeywordSection = new SGBlackboardSection {
                title = "Keywords"
            };
            foreach (var keyword in graph.keywords)
            {
                AddInputRow(keyword);
            }
            blackboard.Add(m_KeywordSection);
        }
示例#3
0
        void EditTextRequested(SGBlackboard blackboard, VisualElement visualElement, string newText)
        {
            var field = (BlackboardFieldView)visualElement;
            var input = (ShaderInput)field.userData;

            if (!string.IsNullOrEmpty(newText) && newText != input.displayName)
            {
                m_Graph.owner.RegisterCompleteObjectUndo("Edit Graph Input Name");
                input.SetDisplayNameAndSanitizeForGraph(m_Graph, newText);
                field.text = input.displayName;
                // need to trigger the inspector update to match
                field.InspectorUpdateTrigger();
                DirtyNodes();
            }
        }
示例#4
0
        void MoveItemRequested(SGBlackboard blackboard, int newIndex, VisualElement visualElement)
        {
            var input = visualElement.userData as ShaderInput;

            if (input == null)
            {
                return;
            }

            m_Graph.owner.RegisterCompleteObjectUndo("Move Graph Input");
            switch (input)
            {
            case AbstractShaderProperty property:
                m_Graph.MoveProperty(property, newIndex);
                break;

            case ShaderKeyword keyword:
                m_Graph.MoveKeyword(keyword, newIndex);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }