示例#1
0
        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
        void OnAddClicked(Blackboard t)
        {
            GenericMenu menu = new GenericMenu();

            foreach (var dataType in CZTypeFactory.TypeCreator.Keys)
            {
                Type valueType = Utility_Reflection.GetFieldInfo(dataType, "value").FieldType;
                if (!typeof(UnityEngine.Object).IsAssignableFrom(valueType) && !UIElementsFactory.FieldDrawerCreatorMap.ContainsKey(valueType))
                {
                    continue;
                }
                menu.AddItem(new GUIContent(dataType.Name), false, () =>
                {
                    string name = dataType.Name;

                    int i = 0;
                    while (GraphView.Model.ContainsName_BB(name))
                    {
                        name = dataType.Name + " " + i++;
                    }
                    GraphView.Model.AddData_BB(name, CZTypeFactory.TypeCreator[dataType]());
                });
            }

            menu.ShowAsContext();
        }
示例#3
0
 static void AddItemRequested(Blackboard obj)
 {
     EditorUtility.DisplayCustomMenu(new Rect(Event.current.mousePosition, Vector2.one),
                                     s_StructTypeOptions,
                                     -1,
                                     (data, options, selected) => CreateNewStruct((StructType)selected),
                                     null);
 }
示例#4
0
        void EditTextRequested(Blackboard arg1, VisualElement arg2, string newName)
        {
            var blackboardField = (BlackboardField)arg2;
            var field           = (FieldModel)blackboardField.userData;

            blackboardField.text = newName;
            field.Name           = newName;
            SetModelDirty();
        }
示例#5
0
        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();
            }
        }
示例#6
0
        void Rename(Blackboard _blackboard, VisualElement _field, string _newName)
        {
            BlackboardField blackboardField = _field as BlackboardField;

            GraphView.Model.RenameData_BB(blackboardField.text, _newName);
        }