private void SaveData(string path)
        {
            UQueryState <GraphElement>      query = graphView.graphElements;
            Dictionary <string, ReddotData> nodes = new Dictionary <string, ReddotData>();

            query.ForEach((element) =>
            {
                if (element is ReddotNode node)
                {
                    if (nodes.ContainsKey(node.Key))
                    {
                        throw new System.Exception($"´æÔÚÖظ´µÄkey ¡¾{node.Key}¡¿");
                    }

                    nodes.Add(node.Key, new ReddotData
                    {
                        key      = node.Key,
                        children = node.RedotChildren,

                        name = node.ReddotName,

                        position = node.transform.position
                    });
                }
            });

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(nodes, Newtonsoft.Json.Formatting.Indented);

            File.WriteAllText(path, json);
        }
        private void CreateFrame()
        {
            SetLabel(Proxy.Label, Proxy.Tooltip);

            _addButton = AddHeaderButton(_addIcon.Texture, Proxy.AddTooltip, AddButtonUssClassName, AddItem);
            _addButton.SetEnabled(false);
            _removeButtons = Content.Query <IconButton>(className: RemoveButtonUssClassName).Build();

            _keyField = new TextField();
            _keyField.AddToClassList(HeaderKeyTextUssClassName);
            _keyField.RegisterValueChangedCallback(evt => AddKeyChanged(evt.newValue));
            _keyField.Q(TextField.textInputUssName).RegisterCallback <KeyDownEvent>(evt => KeyPressed(evt));

            var keyPlaceholder = new PlaceholderControl(Proxy.AddPlaceholder);

            keyPlaceholder.AddToField(_keyField);

            Header.Add(_keyField);
            _keyField.PlaceInFront(Label);

            var empty = new TextElement {
                text = Proxy.EmptyLabel, tooltip = Proxy.EmptyTooltip
            };

            empty.AddToClassList(EmptyLabelUssClassName);

            Content.Add(empty);

            _itemsContainer = new VisualElement();
            _itemsContainer.AddToClassList(ItemsUssClassName);

            Content.Add(_itemsContainer);
        }
Beispiel #3
0
        public void SetInputEnabled(bool enable)
        {
            UQueryState <Button> buttons = m_MetricEditorContainer.Query <Button>(classes: k_ArrayButtonKey).Build();

            buttons.ForEach(b => b.SetEnabled(enable));

            UQueryState <MetricField> metricFields = m_MetricEditorContainer.Query <MetricField>().Build();

            metricFields.ForEach(mf => mf.SetInputEnabled(enable));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BlackboardSection"/> class.
        /// </summary>
        /// <param name="blackboard">The blackboard.</param>
        /// <param name="name">The name of the section, displayed in the section header.</param>
        public BlackboardSection(Blackboard blackboard, string name)
        {
            m_Blackboard  = blackboard;
            m_InsertIndex = -1;

            RegisterCallback <DragUpdatedEvent>(OnDragUpdatedEvent);
            RegisterCallback <DragPerformEvent>(OnDragPerformEvent);
            RegisterCallback <DragLeaveEvent>(OnDragLeaveEvent);

            var header = new VisualElement {
                name = "section-header"
            };

            header.AddToClassList(headerUssClassName);

            var titleLabel = new Label(name)
            {
                name = "section-title-label"
            };

            titleLabel.AddToClassList(titleLabelUssClassName);
            header.Add(titleLabel);

            m_AddButton = new Button(() =>
            {
                var menu = new GenericMenu();
                ((Stencil)m_Blackboard.Model.GraphModel.Stencil)?.PopulateBlackboardCreateMenu(name, menu, m_Blackboard.CommandDispatcher);
                var menuPosition = new Vector2(m_AddButton.layout.xMin, m_AddButton.layout.yMax);
                menuPosition     = m_AddButton.parent.LocalToWorld(menuPosition);
                menu.DropDown(new Rect(menuPosition, Vector2.zero));
            })
            {
                text = "+"
            };
            m_AddButton.AddToClassList(addButtonUssClassName);
            header.Add(m_AddButton);

            hierarchy.Add(header);

            m_RowsContainer = new VisualElement {
                name = "rows-container"
            };
            m_RowsContainer.AddToClassList(rowsUssClassName);
            hierarchy.Add(m_RowsContainer);

            m_DragIndicator = new VisualElement {
                name = "drag-indicator"
            };
            m_DragIndicator.AddToClassList(dragIndicatorUssClassName);
            hierarchy.Add(m_DragIndicator);

            m_Fields = m_RowsContainer.Query <BlackboardField>().Build();

            AddToClassList(ussClassName);
        }
        public EnumButtonsControl(Enum value, bool?useFlags = null)
        {
            Value    = value;
            Type     = value.GetType();
            UseFlags = useFlags ?? Type.HasAttribute <FlagsAttribute>();

            _names   = Enum.GetNames(Type);
            _values  = Enum.GetValues(Type);
            _buttons = this.Query <Button>().Build();

            Rebuild();

            AddToClassList(UssClassName);
            this.AddStyleSheet(Configuration.ElementsPath, Stylesheet);
        }
Beispiel #6
0
        public Tabs()
        {
            Header = new VisualElement();
            Header.AddToClassList(HeaderUssClassName);

            Content = new VisualElement();
            Content.AddToClassList(ContentUssClassName);

            Pages = Content.Query <TabPage>().Build();

            hierarchy.Add(Header);
            hierarchy.Add(Content);

            AddToClassList(UssClassName);
            this.AddStyleSheet(Stylesheet);
        }
Beispiel #7
0
        private void CreateFrame()
        {
            SetLabel(Proxy.Label, Proxy.Tooltip);

            _addButton     = AddHeaderButton(_addIcon.Texture, Proxy.AddTooltip, AddButtonUssClassName, AddItem);
            _removeButtons = Content.Query <IconButton>(className: RemoveButtonUssClassName).Build();

            var empty = new TextElement {
                text = Proxy.EmptyLabel, tooltip = Proxy.EmptyTooltip
            };

            empty.AddToClassList(EmptyLabelUssClassName);

            _itemsContainer = new VisualElement();
            _itemsContainer.AddToClassList(ItemsUssClassName);

            Content.Add(empty);
            Content.Add(_itemsContainer);
        }
Beispiel #8
0
        public GraphView(GraphViewWindow window, Graph graph)
        {
            Graph = graph;

            _window        = window;
            _nodeProvider  = ScriptableObject.CreateInstance <GraphViewNodeProvider>();
            _nodeConnector = new GraphViewConnector(_nodeProvider);

            _inputs  = this.Query <GraphViewInputPort>().Build();
            _outputs = this.Query <GraphViewOutputPort>().Build();

            AddToClassList(UssClassName);
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);
            SetupNodeProvider();
            SetupNodes();
            SetupConnections();
            RegisterCallback <KeyDownEvent>(OnKeyDown);
            RegisterCallback <GeometryChangedEvent>(evt => ShowAll());            // Use this event because the layout isn't build right away so ShowAll won't work immediately

            nodeCreationRequest    = OnShowCreateNode;
            graphViewChanged       = OnGraphChanged;
            canPasteSerializedData = data => canPaste;
            serializeGraphElements = OnCopy;
            unserializeAndPaste    = OnPaste;

            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());
            this.AddManipulator(new ClickSelector());

            Undo.undoRedoPerformed += Rebuild;
            EditorApplication.playModeStateChanged += PlayStateChanged;

            if (Application.isPlaying)             // Make sure the callback still gets set if the window was opened during play mode
            {
                PlayStateChanged(PlayModeStateChange.EnteredPlayMode);
                FrameChanged(null);
            }
        }
        public RadioButtonGroup()
        {
            RegisterCallback <ChangeEvent <bool> >(OnToggleChanged);

            m_ToggleQuery = this.Query <Toggle>().Build();
        }