private void PopulateFileMenuDropdown(ToolbarMenu dropdown) { if (AssetDatabase.IsValidFolder(pathToResources + conversationFolder)) { DirectoryInfo directory = new DirectoryInfo(pathToResources + conversationFolder); FileInfo[] fileInfo = directory.GetFiles("*.*", SearchOption.AllDirectories); bool filesFound = false; foreach (FileInfo file in fileInfo) { if (file.Extension == ".asset") { string directoryFileName = file.Name.Remove(file.Name.Length - 6); filesFound = true; dropdown.menu.AppendAction(directoryFileName, evt => LoadFile(directoryFileName)); } } if (filesFound) { dropdown.SetEnabled(true); } else { Debug.Log("No files found at " + pathToResources + conversationFolder); dropdown.SetEnabled(false); } } else { Debug.Log("Unable to find the CONVERSATION folder at " + pathToResources + conversationFolder); dropdown.SetEnabled(false); } }
public void SetData(ref ProfilerTrace trace) { m_Trace = trace; m_ThreadSelection.menu.MenuItems().Clear(); m_ThreadSelection.SetEnabled(true); m_CurrentThread = -1; for (int i = 0; i < m_Trace.Threads.Length; i++) { var thread = m_Trace.Threads[i]; string threadName; if (thread.ThreadName.UTF8LengthInBytes == 0) { threadName = "Thread " + i + " (unnamed)"; } else { threadName = thread.ThreadName.ToString(); } int index = i; m_ThreadSelection.menu.AppendAction(threadName, action => { m_ThreadSelection.text = action.name; m_CurrentThread = index; RefreshHeatMap(); }); } m_ThreadSelection.text = "Select thread"; }
protected void OnTextFieldValueChange(ChangeEvent <string> evt) { if (!string.IsNullOrEmpty(evt.newValue) && evt.newValue != BuilderConstants.UssSelectorClassNameSymbol) { m_OptionsPopup.SetEnabled(true); } else { m_OptionsPopup.SetEnabled(false); } }
private void RefreshToolbar() { var isEnabled = Application.isPlaying && CurrentGraph != null && CurrentGraph.IsRunning; var isPlaying = isEnabled && CurrentGraph.DebugState == Graph.PlaybackState.Running; var isPaused = isEnabled && CurrentGraph.DebugState == Graph.PlaybackState.Paused; var isStepping = isEnabled && CurrentGraph.DebugState == Graph.PlaybackState.Step; var isStopping = isEnabled && CurrentGraph.DebugState == Graph.PlaybackState.Stopped; _graphButton.text = CurrentGraph == null ? "No Graph Selected" : CurrentGraph.name; _lockButton.image = IsLocked ? Icon.Locked.Texture : Icon.Unlocked.Texture; _editButton.SetEnabled(CurrentGraph != null); _viewButton.SetEnabled(CurrentGraph != null); _playButton.SetEnabled(isEnabled); _pauseButton.SetEnabled(isEnabled); _stepButton.SetEnabled(isEnabled); _stopButton.SetEnabled(isEnabled); _playButton.EnableInClassList(ToolbarButtonActiveUssClassName, isEnabled && isPlaying); _pauseButton.EnableInClassList(ToolbarButtonActiveUssClassName, isEnabled && isPaused); _stepButton.EnableInClassList(ToolbarButtonActiveUssClassName, isEnabled && isStepping); _stopButton.EnableInClassList(ToolbarButtonActiveUssClassName, isEnabled && isStopping); _breakButton.EnableInClassList(ToolbarButtonActiveUssClassName, Graph.IsDebugBreakEnabled); _loggingButton.EnableInClassList(ToolbarButtonActiveUssClassName, Graph.IsDebugLoggingEnabled); _lockButton.EnableInClassList(ToolbarButtonActiveUssClassName, IsLocked); EnableInClassList(BreakpointsDisabledUssClassName, !Graph.IsDebugBreakEnabled); }
public BuilderNewSelectorField() { AddToClassList(s_UssClassName); styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPath)); #if UNITY_2019_2 styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPath2019_2)); if (EditorGUIUtility.isProSkin) { styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPathDark2019_2)); } else { styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(s_UssPathLight2019_2)); } #endif var template = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath); template.CloneTree(this); m_TextField = this.Q <TextField>(s_TextFieldName); var popupContainer = this.Q(s_OptionsPopupContainerName); m_OptionsPopup = new ToolbarMenu(); m_OptionsPopup.AddToClassList(s_OptionsPopupUssClassName); popupContainer.Add(m_OptionsPopup); SetUpPseudoStatesMenu(); m_OptionsPopup.text = ":"; m_OptionsPopup.SetEnabled(false); m_TextField.RegisterValueChangedCallback <string>(OnTextFieldValueChange); }
public BuilderNewSelectorField() { AddToClassList(s_UssClassName); styleSheets.Add(BuilderPackageUtilities.LoadAssetAtPath <StyleSheet>(s_UssPath)); var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath); template.CloneTree(this); m_TextField = this.Q <TextField>(s_TextFieldName); var popupContainer = this.Q(s_OptionsPopupContainerName); m_OptionsPopup = new ToolbarMenu(); m_OptionsPopup.AddToClassList(s_OptionsPopupUssClassName); popupContainer.Add(m_OptionsPopup); SetUpPseudoStatesMenu(); m_OptionsPopup.text = ":"; m_OptionsPopup.SetEnabled(false); m_TextField.RegisterValueChangedCallback <string>(OnTextFieldValueChange); }
public BuilderStyleSheets( BuilderPaneWindow paneWindow, BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderStyleSheetsDragger styleSheetsDragger, HighlightOverlayPainter highlightOverlayPainter, BuilderTooltipPreview tooltipPreview) : base( paneWindow, viewport, selection, classDragger, styleSheetsDragger, new BuilderStyleSheetsContextMenu(paneWindow, selection), viewport.styleSelectorElementContainer, false, highlightOverlayPainter, kToolbarPath) { m_TooltipPreview = tooltipPreview; if (m_TooltipPreview != null) { var helpTooltipTemplate = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath); var helpTooltipContainer = helpTooltipTemplate.CloneTree(); m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done. } viewDataKey = "builder-style-sheets"; AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName); var parent = this.Q("new-selector-item"); // Init text field. m_NewSelectorField = parent.Q <BuilderNewSelectorField>("new-selector-field"); m_NewSelectorTextField = m_NewSelectorField.textField; m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input"); m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown); UpdateNewSelectorFieldEnabledStateFromDocument(); m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) => { var input = evt.target as VisualElement; var field = GetTextFieldParent(input); m_FieldFocusStep = FieldFocusStep.FocusedFromStandby; if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_ShouldRefocusSelectorFieldOnBlur) { m_ShouldRefocusSelectorFieldOnBlur = false; field.value = BuilderConstants.UssSelectorClassNameSymbol; } ShowTooltip(); }, TrickleDown.TrickleDown); m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) => { if (m_FieldFocusStep != FieldFocusStep.FocusedFromStandby) { return; } m_FieldFocusStep = m_NewSelectorTextField.value == BuilderConstants.UssSelectorClassNameSymbol ? FieldFocusStep.NeedsSelectionOverride : FieldFocusStep.Idle; // We don't want the '.' we just inserted in the FocusEvent to be highlighted, // which is the default behavior. Same goes for when we add pseudo states with options menu. m_NewSelectorTextField.SelectRange(m_NewSelectorTextField.value.Length, m_NewSelectorTextField.value.Length); }); // Since MouseDown captures the mouse, we need to RegisterCallback directly on the target in order to intercept the event. // This could be replaced by setting selectAllOnMouseUp to false. m_NewSelectorTextInputField.Q <TextElement>().RegisterCallback <MouseUpEvent>((evt) => { // We want to prevent the default action on mouse up in KeyboardTextEditor, but only when // the field selection behaviour was changed by us. if (m_FieldFocusStep != FieldFocusStep.NeedsSelectionOverride) { return; } m_FieldFocusStep = FieldFocusStep.Idle; // Reselect on the next execution, after the KeyboardTextEditor selects all. m_NewSelectorTextInputField.schedule.Execute(() => { m_NewSelectorTextField.SelectRange(m_NewSelectorTextField.value.Length, m_NewSelectorTextField.value.Length); }); }, TrickleDown.TrickleDown); m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) => { var input = evt.target as VisualElement; var field = GetTextFieldParent(input); if (m_ShouldRefocusSelectorFieldOnBlur) { field.schedule.Execute(PostEnterRefocus); evt.PreventDefault(); evt.StopImmediatePropagation(); return; } if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol) { field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_PseudoStatesMenu.SetEnabled(false); } HideTooltip(); }, TrickleDown.TrickleDown); // Setup New USS Menu. m_AddUSSMenu = parent.Q <ToolbarMenu>("add-uss-menu"); SetUpAddUSSMenu(); // Setup pseudo states menu. m_PseudoStatesMenu = m_NewSelectorField.pseudoStatesMenu; // Update sub title. UpdateSubtitleFromActiveUSS(); // Init drag stylesheet root classDragger.builderStylesheetRoot = container; styleSheetsDragger.builderStylesheetRoot = container; RegisterCallback <GeometryChangedEvent>(e => AdjustPosition()); }
public BuilderStyleSheets( BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderHierarchyDragger hierarchyDragger, BuilderExplorerContextMenu contextMenuManipulator, HighlightOverlayPainter highlightOverlayPainter, BuilderTooltipPreview tooltipPreview) : base( viewport, selection, classDragger, hierarchyDragger, contextMenuManipulator, viewport.styleSelectorElementContainer, highlightOverlayPainter, kToolbarPath) { m_TooltipPreview = tooltipPreview; if (m_TooltipPreview != null) { var helpTooltipTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath); var helpTooltipContainer = helpTooltipTemplate.CloneTree(); m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done. } viewDataKey = "builder-style-sheets"; AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName); var parent = this.Q("new-selector-item"); // Init text field. m_NewSelectorTextField = parent.Q <TextField>("new-selector-field"); m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input"); m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown); m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; m_FieldFocusedFromStandby = true; if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_NewSelectorJustCreated) { m_NewSelectorJustCreated = false; field.value = BuilderConstants.UssSelectorClassNameSymbol; } ShowTooltip(); }); m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) => { var field = evt.target as TextField; if (!string.IsNullOrEmpty(evt.newValue) && evt.newValue != BuilderConstants.UssSelectorClassNameSymbol) { m_NewSelectorAddButton.SetEnabled(true); m_PseudoStatesMenu.SetEnabled(true); } else { m_NewSelectorAddButton.SetEnabled(false); m_PseudoStatesMenu.SetEnabled(false); } if (!m_FieldFocusedFromStandby) { return; } m_FieldFocusedFromStandby = false; // We don't want the '.' we just inserted in the FocusEvent to be highlighted, // which is the default behavior. field.SelectRange(1, 1); }); m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; if (m_NewSelectorJustCreated) { field.schedule.Execute(PostEnterRefocus); evt.PreventDefault(); evt.StopImmediatePropagation(); return; } if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol) { field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorAddButton.SetEnabled(false); m_PseudoStatesMenu.SetEnabled(false); } HideTooltip(); }); // Setup new selector button. m_NewSelectorAddButton = parent.Q <ToolbarButton>("add-new-selector-button"); m_NewSelectorAddButton.clickable.clicked += OnAddPress; m_NewSelectorAddButton.SetEnabled(false); // Setup pseudo states menu. m_PseudoStatesMenu = parent.Q <ToolbarMenu>("add-pseudo-state-menu"); m_PseudoStatesMenu.SetEnabled(false); SetUpPseudoStatesMenu(); }
public BuilderStyleSheets( BuilderPaneWindow paneWindow, BuilderViewport viewport, BuilderSelection selection, BuilderClassDragger classDragger, BuilderStyleSheetsDragger styleSheetsDragger, HighlightOverlayPainter highlightOverlayPainter, BuilderTooltipPreview tooltipPreview) : base( paneWindow, viewport, selection, classDragger, styleSheetsDragger, new BuilderStyleSheetsContextMenu(paneWindow, selection), viewport.styleSelectorElementContainer, false, highlightOverlayPainter, kToolbarPath) { m_TooltipPreview = tooltipPreview; if (m_TooltipPreview != null) { var helpTooltipTemplate = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(kHelpTooltipPath); var helpTooltipContainer = helpTooltipTemplate.CloneTree(); m_TooltipPreview.Add(helpTooltipContainer); // We are the only ones using it so just add the contents and be done. } viewDataKey = "builder-style-sheets"; AddToClassList(BuilderConstants.ExplorerStyleSheetsPaneClassName); var parent = this.Q("new-selector-item"); // Init text field. m_NewSelectorField = parent.Q <BuilderNewSelectorField>("new-selector-field"); m_NewSelectorTextField = m_NewSelectorField.textField; m_NewSelectorTextField.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_NewSelectorTextInputField = m_NewSelectorTextField.Q("unity-text-input"); m_NewSelectorTextInputField.RegisterCallback <KeyDownEvent>(OnEnter, TrickleDown.TrickleDown); UpdateNewSelectorFieldEnabledStateFromDocument(); m_NewSelectorTextInputField.RegisterCallback <FocusEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; m_FieldFocusedFromStandby = true; if (field.text == BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage || m_ShouldRefocusSelectorFieldOnBlur) { m_ShouldRefocusSelectorFieldOnBlur = false; field.value = BuilderConstants.UssSelectorClassNameSymbol; } ShowTooltip(); }); m_NewSelectorTextField.RegisterCallback <ChangeEvent <string> >((evt) => { var field = evt.target as TextField; if (!m_FieldFocusedFromStandby) { return; } m_FieldFocusedFromStandby = false; // We don't want the '.' we just inserted in the FocusEvent to be highlighted, // which is the default behavior. field.SelectRange(1, 1); }); m_NewSelectorTextInputField.RegisterCallback <BlurEvent>((evt) => { var input = evt.target as VisualElement; var field = input.parent as TextField; if (m_ShouldRefocusSelectorFieldOnBlur) { field.schedule.Execute(PostEnterRefocus); evt.PreventDefault(); evt.StopImmediatePropagation(); return; } if (string.IsNullOrEmpty(field.text) || field.text == BuilderConstants.UssSelectorClassNameSymbol) { field.SetValueWithoutNotify(BuilderConstants.ExplorerInExplorerNewClassSelectorInfoMessage); m_PseudoStatesMenu.SetEnabled(false); } HideTooltip(); }); // Setup New USS Menu. m_AddUSSMenu = parent.Q <ToolbarMenu>("add-uss-menu"); SetUpAddUSSMenu(); // Setup pseudo states menu. m_PseudoStatesMenu = m_NewSelectorField.pseudoStatesMenu; // Update sub title. UpdateSubtitleFromActiveUSS(); }
void OnEnable() { titleContent = new GUIContent("Screw It! Profiler"); m_HeatMapView = new ScrewItHeatMapView(); m_Overview = new ScrewItOverview(); m_TopDownView = new ScrewItTopDownView(); m_HotSubtreeView = new ScrewItHotSubtreeView(); rootVisualElement.style.flexDirection = FlexDirection.Column; m_Views = new List <IScrewItView> { m_Overview, m_HeatMapView, m_TopDownView, m_HotSubtreeView }; { m_Toolbar = new Toolbar { style = { height = EditorGUIUtility.singleLineHeight } }; m_RecordingToggle = new ToolbarToggle { text = "Start Recording" }; m_RecordingToggle.RegisterValueChangedCallback(OnRecordingToggled); m_Toolbar.Add(m_RecordingToggle); var loadButton = new ToolbarButton { style = { unityTextAlign = TextAnchor.MiddleLeft } }; loadButton.clicked += ShowLoadTraceFileDialog; loadButton.text = "Load Trace"; m_Toolbar.Add(loadButton); m_Toolbar.Add(new ToolbarSpacer { style = { flexGrow = 1 } }); m_ViewSelection = new ToolbarMenu { variant = ToolbarMenu.Variant.Popup, text = "Select view" }; foreach (var view in m_Views) { var thisView = view; m_ViewSelection.menu.AppendAction(view.Name, action => { SetActiveView(thisView); }); } m_ViewSelection.SetEnabled(false); m_Toolbar.Add(m_ViewSelection); rootVisualElement.Add(m_Toolbar); } { // setup center m_CenterElement = new VisualElement { style = { flexGrow = 1 } };; rootVisualElement.Add(m_CenterElement); } { // setup footer var footer = new VisualElement { style = { height = 20, flexDirection = FlexDirection.Row, flexGrow = 0 } }; rootVisualElement.Add(footer); } }
private void GenerateToolbar() { // //This handles the initalization of the toolbar // toolbar = new Toolbar(); //Conversation File Name text field /* * TextField conversationNameTextField = new TextField("Conversation Name:"); * conversationNameTextField.SetValueWithoutNotify(fileName); * conversationNameTextField.MarkDirtyRepaint(); * conversationNameTextField.RegisterValueChangedCallback(evt => fileName = evt.newValue); * toolbar.Add(conversationNameTextField); * * //Save and Open Buttons * * * //Add Node Button * toolbar.Add(new Button(() => AddNewNode()) { text = "Add New Node" }); */ //What tools do we need fileNameLabel = new TextField("Conversation File:"); fileNameLabel.SetValueWithoutNotify(""); fileNameLabel.SetEnabled(false); toolbar.Add(fileNameLabel); fileNameLabel.SetValueWithoutNotify("No file loaded"); ToolbarMenu fileListMenu = new ToolbarMenu(); fileListMenu.SetEnabled(false); //Disable it until we are positive we have files PopulateFileMenuDropdown(fileListMenu); toolbar.Add(fileListMenu); saveButton = new Button(() => SaveConversation()) { text = "SAVE" }; loadButton = new Button(() => LoadConversation()) { text = "LOAD" }; addSpeechButton = new Button(() => AddNewNode(NodeType.speech)) { text = "ADD SPEECH" }; addResponseButton = new Button(() => AddNewNode(NodeType.response)) { text = "ADD RESPONSE" }; displayLocalizationList = new Button(() => DisplayLocalizationList()) { text = "DISPLAY LOCALIZATION LIST" }; //Button checkLocationButton = new Button(() => CheckLocation()) { text = "CHECK LOCATION "}; //Button checkIfDirty = new Button(() => RunDirtTest()) {text = "CHECK IF FILE IS DIRTY"}; saveButton.SetEnabled(false); loadButton.SetEnabled(false); addSpeechButton.SetEnabled(false); addResponseButton.SetEnabled(false); toolbar.Add(saveButton); toolbar.Add(loadButton); toolbar.Add(addSpeechButton); toolbar.Add(addResponseButton); toolbar.Add(displayLocalizationList); //toolbar.Add(checkLocationButton); //toolbar.Add(checkIfDirty); toolbar.style.backgroundColor = new Color(0.25f, 0.25f, 0.25f, 1); //until we make a styleSheet rootVisualElement.Add(toolbar); // Adds the actual toolbar to the Editor Window }