コード例 #1
0
ファイル: Blackboard.cs プロジェクト: whuop/NodeGraph
        public Blackboard(VisualElement visualParent, GraphView graph)
        {
            m_visualParent = visualParent;
            UnityEditor.Experimental.GraphView.Blackboard bb = new UnityEditor.Experimental.GraphView.Blackboard(graph);
            //bb.subTitle = string.Empty;
            //m_visualParent.Add(bb);
            graph.Add(bb);

            bb.title = "Test Blackboard";

            BlackboardSection bbSection = new BlackboardSection();

            bbSection.title         = "Section Test Name";
            bbSection.headerVisible = true;
            bb.Add(bbSection);

            BlackboardField bbField = new BlackboardField();

            bbField.title = "TestVariable";
            bbField.text  = "TestText";
            //bbSection.Add(bbField);

            BlackboardRow bbRow = new BlackboardRow(bbField, new VisualElement());

            bbSection.Add(bbRow);
            bbSection.Add(bbRow);

            Debug.Log($"Is Field Droppable {bbField.IsDroppable()}");
        }
コード例 #2
0
ファイル: ComponentEditor.cs プロジェクト: substence/UnityVS3
        void OnEnable()
        {
            rootVisualElement.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(UICreationHelper.TemplatePath + "ComponentEditor.uss"));

            rootVisualElement.AddToClassList("root");
            var root = rootVisualElement;

            m_GhostGraphView = new GhostGraphView(this);

            m_Blackboard = new Blackboard(m_GhostGraphView)
            {
                windowed = true
            };
            m_BlackboardContentContainer = m_Blackboard.Q("unity-content-container");

            // need wait for layout to avoid default 200px width value
            root.RegisterCallback <GeometryChangedEvent>(e =>
            {
                if (!m_Blackboard.scrollable)
                {
                    m_Blackboard.scrollable = true;
                    var sv = m_Blackboard.Q <ScrollView>();
                    sv.RemoveFromClassList(ScrollView.horizontalVariantUssClassName);
                    sv.RemoveFromClassList(ScrollView.scrollVariantUssClassName);
                }

                if (m_BlackboardContentContainer != null)
                {
                    m_BlackboardContentContainer.style.width = e.newRect.width;
                }
            });

            m_Blackboard.editTextRequested = EditTextRequested;
            m_Blackboard.addItemRequested  = AddItemRequested;
            root.Add(m_Blackboard);

            m_Blackboard.Add(m_InfoSection = new BlackboardSection()
            {
                name = "infoSection", title = "No component selected"
            });
            m_InfoSection.Add(new Label("Open an existing component or create a new one.")
            {
                name = "noSelectionLabel"
            });
            m_Blackboard.Add(m_StructSection = new BlackboardSection()
            {
                name = "structSection", title = "Struct"
            });
            m_Blackboard.Add(m_FieldsSection = new BlackboardSection()
            {
                name = "fieldsSection", title = "Fields"
            });

            m_StructNameField = new TextField("Name");
            m_StructNameField.RegisterValueChangedCallback(e =>
            {
                if (CurrentStruct.Name != e.newValue)
                {
                    CurrentStruct.Name = e.newValue;
                    SetModelDirty();
                }
            });

            m_StructSection.Add(m_StructNameField);

            m_PickStructTypeButton = new Button(() => PickStructType(CurrentStruct, SetStructType));
            var structTypeRow = new VisualElement {
                name = "structTypeRow"
            };

            structTypeRow.Add(new Label("Type"));
            structTypeRow.Add(m_PickStructTypeButton);
            m_StructSection.Add(structTypeRow);
            m_StructSection.Add(m_StructTypeLabel = new Label {
                name = "structTypeLabel"
            });

            m_FieldsSection.Q("sectionHeader").Add(new Button(() =>
            {
                FieldModel newField = CurrentStruct.Add(typeof(int), MakeUniqueFieldName("newField"));
                m_FieldsSection.Add(MakeFieldRow(newField));
                SetModelDirty();
            })
            {
                text = "+"
            });

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

            bottomToolbar.Add(m_SaveButton = new Button(Save)
            {
                text = "Save"
            });
            root.Add(bottomToolbar);

            // resume after domain reload
            if (!string.IsNullOrEmpty(m_CurrentPath) && File.Exists(m_CurrentPath))
            {
                LoadFromPath(m_CurrentPath);
            }
            else
            {
                Unload();
            }
        }