Button CreateButton(string name) { var button = new Button { name = name, }; button.AddToClassList(k_ButtonClass); button.RegisterCallback <DetachFromPanelEvent>(OnButtonDetachFromPanel); button.clicked += () => { value = m_Buttons.IndexOf(button); }; m_Buttons.Add(button); Add(button); RefreshButtonsStyling(); return(button); }
private void OnEnable() { ab = new ObjectField(); ab.objectType = typeof(TMP_FontAsset); bb = new ObjectField(); bb.objectType = typeof(Material); var but = new Button() { text = "Replace fonts" }; rootVisualElement.Add(ab); rootVisualElement.Add(bb); rootVisualElement.Add(but); but.RegisterCallback <MouseUpEvent>(aa); }
private void SetupPolygonChangeShapeWindowElements(VisualElement moduleView) { var sidesField = moduleView.Q <IntegerField>("labelIntegerField"); sidesField.SetValueWithoutNotify(polygonSides); sidesField.RegisterValueChangedCallback((evt) => { polygonSides = (int)evt.newValue; ShowHideWarningMessage(); }); m_ChangeButton = moduleView.Q <UIElementButton>("changeButton"); m_ChangeButton.RegisterCallback <MouseUpEvent>((e) => { if (isSidesValid) { GeneratePolygonOutline(); showChangeShapeWindow = false; } }); m_WarningMessage = moduleView.Q("warning"); ShowHideWarningMessage(); }
private VisualElement MakeItem() { var row = new VisualElement(); row.style.flexDirection = FlexDirection.Row; row.AddToClassList("perf-row"); var pinIcon = new VisualElement(); pinIcon.AddToClassList("perf-pin"); row.Add(pinIcon); var trackerName = new TextField { isReadOnly = true }; VisualElement column = trackerName; column.AddToClassList("perf-tracker-name"); row.Add(column); if (IsColumnVisible(ColumnId.SampleCount)) { column = new Button(); column.RegisterCallback <MouseUpEvent>(evt => { var tracker = GetTrackerInRowAtEvt(evt); EditorPerformanceTracker.Reset(tracker.name); RefreshTrackers(); SendAnalytics(Analytics.WindowUsageType.ResetSampleCount, tracker.name); }); column.AddToClassList("perf-sample-count"); row.Add(column); } if (IsColumnVisible(ColumnId.Age)) { column = new Label(); column.AddToClassList("perf-age"); row.Add(column); } if (IsColumnVisible(ColumnId.AvgTime)) { column = new Label(); column.AddToClassList("perf-avg-time"); row.Add(column); } if (IsColumnVisible(ColumnId.PeakTime)) { column = new Label(); column.AddToClassList("perf-peak-time"); row.Add(column); } if (IsColumnVisible(ColumnId.LastTime)) { column = new Label(); column.AddToClassList("perf-last-time"); row.Add(column); } if (IsColumnVisible(ColumnId.TotalTime)) { column = new Label(); column.AddToClassList("perf-total-time"); row.Add(column); } var actionBtn = new Button { text = "..." }; actionBtn.RegisterCallback <MouseUpEvent>(evt => { var btn = evt.target as Button; var tracker = GetTrackerInRowAtEvt(evt); if (tracker.name == m_CurrentProfileTag) { EndTrackerProfiling(evt.target as Button, tracker.name); } else { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Set as search filter"), false, () => { m_SearchField.value = tracker.name; SendAnalytics(Analytics.WindowUsageType.SetSearchFieldAction, tracker.name); }); menu.AddItem(new GUIContent("Add performance notification"), false, () => PerformanceTrackerActions.AddNewPerformanceNotification(tracker.name, (float)tracker.avgTime, Analytics.ActionSource.PerformanceTrackerWindow)); menu.AddItem(new GUIContent("LogCallstack"), false, () => PerformanceTrackerActions.LogCallstack(tracker.name, Analytics.ActionSource.PerformanceTrackerWindow)); if (String.IsNullOrEmpty(m_CurrentProfileTag)) { menu.AddSeparator(""); menu.AddItem(new GUIContent("Editmode Profile..."), false, () => StartTrackerProfiling(btn, tracker.name, false, true)); menu.AddItem(new GUIContent("Editmode Deep profile..."), false, () => StartTrackerProfiling(btn, tracker.name, true, true)); menu.AddSeparator(""); menu.AddItem(new GUIContent("Playmode Profile..."), false, () => StartTrackerProfiling(btn, tracker.name, false, false)); menu.AddItem(new GUIContent("Playmode Deep profile..."), false, () => StartTrackerProfiling(btn, tracker.name, true, false)); } menu.ShowAsContext(); } }); actionBtn.AddToClassList("perf-actions"); row.Add(actionBtn); return(row); }