Exemplo n.º 1
0
        public void OnEnable()
        {
            InitElements();

            var root = rootVisualElement;

            root.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/Editor/breadcrumbs-demo.uss"));

            var toolbar = new Toolbar();

            root.Add(toolbar);

            var btn1 = new ToolbarButton(LoadRandomContent)
            {
                text = "Random"
            };

            toolbar.Add(btn1);

            toolbar.Add(new ToolbarSpacer());

            m_Breadcrumbs = new ToolbarBreadcrumbs();
            toolbar.Add(m_Breadcrumbs);

            var box = new Box();

            m_ListContainer = new ScrollView();
            m_ListContainer.showHorizontal = false;
            box.Add(m_ListContainer);

            root.Add(box);

            LoadContentByName(RootName);
        }
Exemplo n.º 2
0
        private void OnEnable()
        {
            m_Window = this;

            rootVisualElement.AddStyleSheetPath(ussPath);
            if (EditorGUIUtility.isProSkin)
            {
                rootVisualElement.AddStyleSheetPath(ussPathDark);
            }
            else
            {
                rootVisualElement.AddStyleSheetPath(ussPathLight);
            }

            var toolbar = new UIElements.Toolbar();

            m_DismissAllBtn = new UIElements.ToolbarButton(ClearAll)
            {
                name = "DismissAllBtn",
                text = "Clear inactive",
            };
            toolbar.Add(m_DismissAllBtn);
            // This is our friend the spacer
            toolbar.Add(new VisualElement()
            {
                style =
                {
                    flexGrow = 1
                }
            });

            m_FilterSuccess   = CreateStatusFiler(toolbar, "Success", kSuccessIcon);
            m_FilterCancelled = CreateStatusFiler(toolbar, "Canceled", kCanceledIcon);
            m_FilterFailed    = CreateStatusFiler(toolbar, "Failed", kFailedIcon);

            rootVisualElement.Add(toolbar);

            m_ScrollView = new ScrollView()
            {
                style =
                {
                    flexGrow = 1
                }
            };
            rootVisualElement.Add(m_ScrollView);

            UpdateModel();
            UpdateStatusHeaders();
            UpdateStatusFilter();

            Progress.added   += OperationWasAdded;
            Progress.removed += OperationWasRemoved;
            Progress.updated += OperationWasUpdated;

            CheckUnresponsive();
        }
        private void OnEnable()
        {
            m_Window = this;

            rootVisualElement.AddStyleSheetPath(ussPath);

            var toolbar = new UIElements.Toolbar();

            m_DismissAllBtn = new UIElements.ToolbarButton(ClearAll)
            {
                name = "DismissAllBtn",
                text = "Dismiss All",
            };
            toolbar.Add(m_DismissAllBtn);
            // This is our friend the spacer
            toolbar.Add(new VisualElement()
            {
                style =
                {
                    flexGrow = 1
                }
            });

            m_FilterActive  = CreateStatusFiler(toolbar, "Active", kRunningIcon);
            m_FilterSuccess = CreateStatusFiler(toolbar, "Success", kSuccessIcon);
            m_FilterSuccess.Q <VisualElement>("unity-checkmark").style.unityBackgroundImageTintColor = new StyleColor(Color.green);
            m_FilterCancelled = CreateStatusFiler(toolbar, "Canceled", kCanceledIcon);
            m_FilterFailed    = CreateStatusFiler(toolbar, "Failed", kFailedIcon);

            rootVisualElement.Add(toolbar);

            m_ScrollView = new ScrollView()
            {
                style =
                {
                    flexGrow = 1
                }
            };
            rootVisualElement.Add(m_ScrollView);

            UpdateModel();
            UpdateStatusHeaders();
            UpdateStatusFilter();

            Progress.OnAdded   += OperationWasAdded;
            Progress.OnRemoved += OperationWasRemoved;
            Progress.OnUpdated += OperationWasUpdated;

            CheckUnresponsive();
        }
        protected void OnEnable()
        {
            var root = rootVisualElement;

            this.SetAntiAliasing(4);

            m_Toolbar = new UnityEditor.UIElements.Toolbar();

            // Register panel choice refresh on the toolbar so the event
            // is received before the ToolbarPopup clickable handle it.
            m_Toolbar.RegisterCallback <MouseDownEvent>(e =>
            {
                if (e.target == m_SelectorMenu)
                {
                    RefreshPanelChoices();
                }
            }, TrickleDown.TrickleDown);
            m_GraphViewChoices = new List <GraphViewChoice>();
            m_SelectorMenu     = new ToolbarMenu {
                name = "panelSelectPopup", text = "Select a panel"
            };

            var menu = m_SelectorMenu.menu;

            menu.AppendAction("None", OnSelectGraphView,
                              a => m_SelectedGraphView == null ?
                              DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);

            m_Toolbar.Add(m_SelectorMenu);

            root.Add(m_Toolbar);

            m_FirstUpdate = true;
        }
        public StylePropertyDebugger(VisualElement debuggerSelection)
        {
            m_SelectedElement = debuggerSelection;

            m_Toolbar = new Toolbar();
            Add(m_Toolbar);

            var searchField = new ToolbarSearchField();

            searchField.AddToClassList("unity-style-debugger-search");
            searchField.RegisterValueChangedCallback(e =>
            {
                m_SearchFilter = e.newValue;
                BuildFields();
            });
            m_Toolbar.Add(searchField);

            var showAllToggle = new ToolbarToggle();

            showAllToggle.AddToClassList("unity-style-debugger-toggle");
            showAllToggle.text = "Show all";
            showAllToggle.RegisterValueChangedCallback(e =>
            {
                m_ShowAll = e.newValue;
                BuildFields();
            });
            m_Toolbar.Add(showAllToggle);

            m_CustomPropertyFieldsContainer = new VisualElement();
            Add(m_CustomPropertyFieldsContainer);

            m_FieldsContainer = new VisualElement();
            Add(m_FieldsContainer);

            if (m_SelectedElement != null)
            {
                BuildFields();
            }

            AddToClassList("unity-style-debugger");
        }
Exemplo n.º 6
0
        public void OnEnable()
        {
            var root = this.rootVisualElement;

            root.styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/Examples/Editor/todolist.uss"));

            var toolbar = new Toolbar();

            root.Add(toolbar);

            var btn1 = new ToolbarButton {
                text = "Button"
            };

            toolbar.Add(btn1);

            var spc = new ToolbarSpacer();

            toolbar.Add(spc);

            var tgl = new ToolbarToggle {
                text = "Toggle"
            };

            toolbar.Add(tgl);

            var spc2 = new ToolbarSpacer()
            {
                name = "flexSpacer1", flex = true
            };

            toolbar.Add(spc2);

            var menu = new ToolbarMenu {
                text = "Menu"
            };

            menu.menu.AppendAction("Default is never shown", a => {}, a => DropdownMenuAction.Status.None);
            menu.menu.AppendAction("Normal menu", a => {}, a => DropdownMenuAction.Status.Normal);
            menu.menu.AppendAction("Hidden is never shown", a => {}, a => DropdownMenuAction.Status.Hidden);
            menu.menu.AppendAction("Checked menu", a => {}, a => DropdownMenuAction.Status.Checked);
            menu.menu.AppendAction("Disabled menu", a => {}, a => DropdownMenuAction.Status.Disabled);
            menu.menu.AppendAction("Disabled and checked menu", a => {}, a => DropdownMenuAction.Status.Disabled | DropdownMenuAction.Status.Checked);
            toolbar.Add(menu);

            var spc3 = new ToolbarSpacer()
            {
                name = "flexSpacer2", flex = true
            };

            toolbar.Add(spc3);

            var popup = new ToolbarMenu {
                text = "Popup", variant = ToolbarMenu.Variant.Popup
            };

            popup.menu.AppendAction("Popup", a => {}, a => DropdownMenuAction.Status.Normal);
            toolbar.Add(popup);

            var popupSearchField = new ToolbarPopupSearchField();

            popupSearchField.RegisterValueChangedCallback(OnSearchTextChanged);
            popupSearchField.menu.AppendAction(
                "Popup Search Field",
                a => m_popupSearchFieldOn = !m_popupSearchFieldOn,
                a => m_popupSearchFieldOn ?
                DropdownMenuAction.Status.Checked :
                DropdownMenuAction.Status.Normal);
            toolbar.Add(popupSearchField);
            var searchField = new ToolbarSearchField();

            searchField.RegisterValueChangedCallback(OnSearchTextChanged);
            toolbar.Add(searchField);

            var popupWindow = new PopupWindow();

            popupWindow.text = "New Task";
            root.Add(popupWindow);

            m_TextInput = new TextField()
            {
                name = "input", viewDataKey = "input", isDelayed = true
            };
            popupWindow.Add(m_TextInput);
            m_TextInput.RegisterCallback <ChangeEvent <string> >(AddTask);

            var button = new Button(AddTask)
            {
                text = "Save task"
            };

            popupWindow.Add(button);

            var box = new Box();

            m_TasksContainer = new ScrollView();
            m_TasksContainer.showHorizontal = false;
            box.Add(m_TasksContainer);

            root.Add(box);

            if (m_Tasks != null)
            {
                foreach (string task in m_Tasks)
                {
                    m_TasksContainer.Add(CreateTask(task));
                }
            }
        }
Exemplo n.º 7
0
        private void SetupUI()
        {
            var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>($"{Utils.packageFolderName}/Editor/StyleSheets/PerformanceTrackerWindow.uss");

            rootVisualElement.styleSheets.Add(styleSheet);

            m_RefreshFromSearch = Delayer.Throttle(RefreshFromSearch);

            var toolbar = new UIElements.Toolbar();

            toolbar.AddToClassList("perf-toolbar");
            toolbar.style.height = PtStyles.itemHeight;

            var searchBox = new VisualElement();

            searchBox.AddToClassList("perf-search-box");
            AddSelectorLabel(toolbar, "Tracker");
            m_SearchField = new UIElements.ToolbarSearchField();
            m_SearchField.AddToClassList("perf-search-tracker");
            m_SearchField.value = m_FilterText;
            m_SearchField.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                m_RefreshFromSearch.Execute(evt.newValue);
            });
            searchBox.Add(m_SearchField);
            toolbar.Add(searchBox);

            var resetAllCountersButton = new Button(ResetAllCounters);

            resetAllCountersButton.text = "Reset all counters";
            resetAllCountersButton.AddToClassList("perf-tracker-toolbar-button");
            toolbar.Add(resetAllCountersButton);

            AddSelectorLabel(toolbar, "Update Speed");
            var choices             = PtModel.RefreshRates.Select(r => r.label).ToList();
            var updateSpeedSelector = new UIElements.PopupField <string>(choices, 0);

            updateSpeedSelector.value = PtModel.RefreshRates[m_UpdateSpeedIndex].label;
            updateSpeedSelector.AddToClassList("perf-update-speed-selector");
            updateSpeedSelector.RegisterCallback <ChangeEvent <string> >((evt) =>
            {
                m_UpdateSpeedIndex = Array.FindIndex(PtModel.RefreshRates, (r) => r.label == evt.newValue);
                ScheduleNextRefresh();
                SendAnalytics(Analytics.WindowUsageType.ChangeMonitoringSpeed);
            });
            toolbar.Add(updateSpeedSelector);

            AddSelectorLabel(toolbar, "Columns");
            var columnsChoice   = PtModel.ColumnDescriptors.Where(desc => desc.columnsSelectorMaskId > 0).Select(desc => desc.label).ToList();
            var columnsSelector = new UIElements.MaskField(columnsChoice, m_ShownColumn);

            columnsSelector.RegisterCallback <ChangeEvent <int> >((evt) =>
            {
                m_ShownColumn = evt.newValue;
                CreateHeaders();
                RefreshTrackers();
                SendAnalytics(Analytics.WindowUsageType.ChangeColumnLayout);
            });
            columnsSelector.AddToClassList("perf-columns-selector");
            toolbar.Add(columnsSelector);

            AddSelectorLabel(toolbar, "Sort By");
            m_SortBySelector       = new UIElements.EnumField(ColumnId.Name);
            m_SortBySelector.value = m_SortBy;
            m_SortBySelector.AddToClassList("perf-sort-by-selector");
            m_SortBySelector.RegisterCallback <ChangeEvent <Enum> >((evt) =>
            {
                ChangeSortOrder((ColumnId)evt.newValue);
                SendAnalytics(Analytics.WindowUsageType.ChangeSortBy);
            });
            toolbar.Add(m_SortBySelector);

            var settingsBtn = new Button(() =>
            {
                SettingsService.OpenUserPreferences(PerformanceTrackerSettings.settingsKey);
                SendAnalytics(Analytics.WindowUsageType.OpenPreferences);
            });

            settingsBtn.style.backgroundImage = Icons.settings;
            settingsBtn.style.width           = PtStyles.itemHeight - 3;
            settingsBtn.style.height          = PtStyles.itemHeight - 3;

            toolbar.Add(settingsBtn);

            rootVisualElement.Add(toolbar);

            // Set List View Header:
            m_HeaderRow = new VisualElement();
            m_HeaderRow.AddToClassList("perf-header-row-container");
            m_HeaderRow.style.flexDirection = FlexDirection.Row;
            rootVisualElement.Add(m_HeaderRow);
            CreateHeaders();

            m_PinnedTrackersView      = new ListView(m_PinnedTrackers, PtStyles.itemHeight, MakeItem, BindPinnedItem);
            m_PinnedTrackersView.name = k_PinnedTrackerList;
            m_PinnedTrackersView.AddToClassList("perf-tracker-list");
            m_PinnedTrackersView.selectionType  = SelectionType.Multiple;
            m_PinnedTrackersView.style.flexGrow = 0;
            m_PinnedTrackersView.Q <VisualElement>(null, "unity-scroll-view__content-viewport").RegisterCallback <GeometryChangedEvent>(SyncHeaderAndListsGeometry);
            rootVisualElement.Add(m_PinnedTrackersView);

            m_TrackersView      = new ListView(m_FilteredTrackers, PtStyles.itemHeight, MakeItem, BindUnpinnedItem);
            m_TrackersView.name = k_TrackerList;
            m_TrackersView.AddToClassList("perf-tracker-list");
            m_TrackersView.selectionType  = SelectionType.Multiple;
            m_TrackersView.style.flexGrow = 1.0f;

            m_TrackersView.Q <VisualElement>(null, "unity-scroll-view__content-viewport").RegisterCallback <GeometryChangedEvent>(SyncHeaderAndListsGeometry);

            rootVisualElement.Add(m_TrackersView);

            m_NeedsUpdate = true;
            ScheduleNextRefresh();
            UpdateTrackers();
        }
Exemplo n.º 8
0
        void OnEnable()
        {
            s_Window     = this;
            titleContent = EditorGUIUtility.TrTextContent("Background Tasks");

            rootVisualElement.AddStyleSheetPath(ussPath);
            if (EditorGUIUtility.isProSkin)
            {
                rootVisualElement.AddStyleSheetPath(ussPathDark);
            }
            else
            {
                rootVisualElement.AddStyleSheetPath(ussPathLight);
            }

            var toolbar = new UIElements.Toolbar();

            m_DismissAllBtn = new ToolbarButton(ClearInactive)
            {
                name = "DismissAllBtn",
                text = L10n.Tr("Clear inactive"),
            };
            toolbar.Add(m_DismissAllBtn);

            // This is our friend the spacer
            toolbar.Add(new VisualElement()
            {
                style =
                {
                    flexGrow = 1
                }
            });

            rootVisualElement.Add(toolbar);
            s_VisualProgressItemTask = EditorGUIUtility.Load(k_UxmlProgressItemPath) as VisualTreeAsset;

            m_TreeView                 = new TreeView();
            m_TreeView.makeItem        = MakeTreeViewItem;
            m_TreeView.bindItem        = BindTreeViewItem;
            m_TreeView.unbindItem      = UnbindTreeViewItem;
            m_TreeView.destroyItem     = DestroyTreeViewItem;
            m_TreeView.fixedItemHeight = 50;
            m_TreeView.SetRootItems(new TreeViewItemData <Progress.Item>[] {});

            var scrollView = m_TreeView.Q <ScrollView>();

            if (scrollView != null)
            {
                scrollView.horizontalScrollerVisibility = ScrollerVisibility.Hidden;
            }

            rootVisualElement.Add(m_TreeView);
            m_TreeView.Rebuild();

            // Update the treeview with the existing items
            m_MissingParents        = new Dictionary <int, List <int> >();
            m_ContainedItems        = new HashSet <int>();
            m_ItemsNeedingExpansion = new HashSet <int>();
            OperationsAdded(Progress.EnumerateItems().ToArray());

            Progress.added   += OperationsAdded;
            Progress.removed += OperationsRemoved;
            Progress.updated += OperationsUpdated;
            UpdateDismissAllButton();
        }