void OnEnable() { minSize = new Vector2(560.0f, 200.0f); #if UNITY_2019_1_OR_NEWER var root = rootVisualElement; root.styleSheets.Add(Resources.Load <StyleSheet>(s_StylesFolder + "recorder")); root.styleSheets.Add(Resources.Load <StyleSheet>(s_StylesFolder + (EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin"))); #else var root = this.GetRootVisualContainer(); root.AddStyleSheetPath(s_StylesFolder + "recorder"); root.AddStyleSheetPath(s_StylesFolder + (EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin")); #endif root.style.flexDirection = FlexDirection.Column; UIElementHelper.SetFocusable(root); var mainControls = new VisualElement { style = { flexDirection = FlexDirection.Row, minHeight = 110.0f } }; root.Add(mainControls); var controlLeftPane = new VisualElement { style = { #if UNITY_2018_1 minWidth = 350.0f, #else minWidth = 180.0f, #endif maxWidth = 450.0f, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(controlLeftPane, 0.5f); var controlRightPane = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(controlRightPane, 0.5f); mainControls.Add(controlLeftPane); mainControls.Add(controlRightPane); controlLeftPane.AddToClassList("StandardPanel"); controlRightPane.AddToClassList("StandardPanel"); m_RecordButtonIcon = new Button(OnRecordButtonClick) { name = "recorderIcon", style = { backgroundImage = Resources.Load <Texture2D>("recorder_icon"), } }; controlLeftPane.Add(m_RecordButtonIcon); var leftButtonsStack = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(leftButtonsStack, 1.0f); m_RecordButton = new Button(OnRecordButtonClick) { name = "recordButton" }; UpdateRecordButtonText(); leftButtonsStack.Add(m_RecordButton); m_RecordOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordOptionsPanel.layout.width); Options.exitPlayMode = EditorGUILayout.Toggle(Styles.ExitPlayModeLabel, Options.exitPlayMode); }) { name = "recordOptions" }; UIElementHelper.SetFlex(m_RecordOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordOptionsPanel); m_RecordModeOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordModeOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.RecordModeGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_RecordModeOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordModeOptionsPanel); controlLeftPane.Add(leftButtonsStack); m_FrameRateOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_FrameRateOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.FrameRateGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_FrameRateOptionsPanel, 1.0f); controlRightPane.Add(m_FrameRateOptionsPanel); m_SettingsPanel = new ScrollView(); UIElementHelper.SetFlex(m_SettingsPanel, 1.0f); UIElementHelper.ResetStylePosition(m_SettingsPanel.contentContainer.style); var recordersAndParameters = new VisualElement { style = { alignSelf = Align.Stretch, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(recordersAndParameters, 1.0f); m_RecordersPanel = new VisualElement { name = "recordersPanel", style = { width = 200.0f, minWidth = 150.0f, maxWidth = 500.0f } }; m_RecordersPanel.AddToClassList("StandardPanel"); m_PanelSplitter = new PanelSplitter(m_RecordersPanel); recordersAndParameters.Add(m_RecordersPanel); recordersAndParameters.Add(m_PanelSplitter); recordersAndParameters.Add(m_SettingsPanel); m_SettingsPanel.AddToClassList("StandardPanel"); root.Add(recordersAndParameters); var addRecordButton = new Label("+ Add New Recorders"); UIElementHelper.SetFlex(addRecordButton, 1.0f); var recorderListPresetButton = new VisualElement { name = "recorderListPreset" }; recorderListPresetButton.RegisterCallback <MouseUpEvent>(evt => ShowRecorderListMenu()); recorderListPresetButton.Add(new Image { image = (Texture2D)EditorGUIUtility.Load("Builtin Skins/" + (EditorGUIUtility.isProSkin ? "DarkSkin" : "LightSkin") + "/Images/pane options.png"), style = { width = 16.0f, height = 11.0f } }); addRecordButton.AddToClassList("RecorderListHeader"); recorderListPresetButton.AddToClassList("RecorderListHeader"); addRecordButton.RegisterCallback <MouseUpEvent>(evt => ShowNewRecorderMenu()); m_AddNewRecordPanel = new VisualElement { name = "addRecordersButton", style = { flexDirection = FlexDirection.Row } }; m_AddNewRecordPanel.Add(addRecordButton); m_AddNewRecordPanel.Add(recorderListPresetButton); m_RecordingListItem = new RecorderItemList { name = "recorderList" }; UIElementHelper.SetFlex(m_RecordingListItem, 1.0f); UIElementHelper.SetFocusable(m_RecordingListItem); m_RecordingListItem.OnItemContextMenu += OnRecordContextMenu; m_RecordingListItem.OnSelectionChanged += OnRecordSelectionChanged; m_RecordingListItem.OnItemRename += item => item.StartRenaming(); m_RecordingListItem.OnContextMenu += ShowNewRecorderMenu; m_RecordersPanel.Add(m_AddNewRecordPanel); m_RecordersPanel.Add(m_RecordingListItem); m_ParametersControl = new VisualElement { style = { minWidth = 300.0f, } }; UIElementHelper.SetFlex(m_ParametersControl, 1.0f); m_ParametersControl.Add(new Button(OnRecorderSettingPresetClicked) { name = "presetButton", style = { alignSelf = Align.FlexEnd, backgroundImage = PresetHelper.presetIcon, paddingTop = 0.0f, paddingLeft = 0.0f, paddingBottom = 0.0f, paddingRight = 0.0f, #if UNITY_2019_1_OR_NEWER unityBackgroundScaleMode = ScaleMode.ScaleToFit, #elif UNITY_2018_3_OR_NEWER backgroundScaleMode = ScaleMode.ScaleToFit, #else backgroundSize = ScaleMode.ScaleToFit, #endif #if UNITY_2019_1_OR_NEWER unitySliceTop = 0, unitySliceBottom = 0, unitySliceLeft = 0, unitySliceRight = 0, #else sliceTop = 0, sliceBottom = 0, sliceLeft = 0, sliceRight = 0, #endif } }); m_RecorderSettingPanel = new IMGUIContainer(OnRecorderSettingsGUI) { name = "recorderSettings" }; UIElementHelper.SetFlex(m_RecorderSettingPanel, 1.0f); var statusBar = new VisualElement { name = "statusBar" }; statusBar.Add(new IMGUIContainer(UpdateRecordingProgressGUI)); root.Add(statusBar); m_ParametersControl.Add(m_RecorderSettingPanel); m_SettingsPanel.Add(m_ParametersControl); m_ControllerSettings = RecorderControllerSettings.LoadOrCreate(Application.dataPath + s_PrefsFileName); m_RecorderController = new RecorderController(m_ControllerSettings); m_RecorderSettingsPrefsEditor = (RecorderSettingsPrefsEditor)Editor.CreateEditor(m_ControllerSettings); #if UNITY_2018_2_OR_NEWER m_RecordingListItem.RegisterCallback <ValidateCommandEvent>(OnRecorderListValidateCommand); m_RecordingListItem.RegisterCallback <ExecuteCommandEvent>(OnRecorderListExecuteCommand); #else m_RecordingListItem.RegisterCallback <IMGUIEvent>(OnRecorderListIMGUI); #endif m_RecordingListItem.RegisterCallback <KeyUpEvent>(OnRecorderListKeyUp); ReloadRecordings(); Undo.undoRedoPerformed += SaveAndRepaint; EditorApplication.playModeStateChanged += OnPlayModeStateChanged; }
void OnEnable() { minSize = new Vector2(560.0f, 200.0f); if (!s_PackageVersionInitialized) { s_Request = Client.List(); // List packages installed for the Project EditorApplication.update += Progress; } #if UNITY_2019_1_OR_NEWER var root = rootVisualElement; root.styleSheets.Add(Resources.Load <StyleSheet>(s_StylesFolder + "recorder")); root.styleSheets.Add(Resources.Load <StyleSheet>(s_StylesFolder + (EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin"))); #else var root = this.GetRootVisualContainer(); root.AddStyleSheetPath(s_StylesFolder + "recorder"); root.AddStyleSheetPath(s_StylesFolder + (EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin")); #endif root.style.flexDirection = FlexDirection.Column; UIElementHelper.SetFocusable(root); var mainControls = new VisualElement { style = { flexDirection = FlexDirection.Row, minHeight = 110.0f } }; root.Add(mainControls); var controlLeftPane = new VisualElement { style = { #if UNITY_2018_1 minWidth = 350.0f, #else minWidth = 180.0f, #endif maxWidth = 450.0f, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(controlLeftPane, 0.5f); var controlRightPane = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(controlRightPane, 0.5f); mainControls.Add(controlLeftPane); mainControls.Add(controlRightPane); controlLeftPane.AddToClassList("StandardPanel"); controlRightPane.AddToClassList("StandardPanel"); m_RecordButtonIcon = new Button(OnRecordButtonClick) { name = "recorderIcon", style = { backgroundImage = Resources.Load <Texture2D>("recorder_icon"), }, tooltip = "Start the recording for all active recorders of the list\n\n This automatically activates the Play mode first (if not activated yet)." }; controlLeftPane.Add(m_RecordButtonIcon); var leftButtonsStack = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(leftButtonsStack, 1.0f); m_RecordButton = new Button(OnRecordButtonClick) { name = "recordButton", tooltip = "Start/Stop the recording for all active recorders of the list\n\nStarting the recording automatically activates the Play mode first (if not activated yet)." }; UpdateRecordButtonText(); leftButtonsStack.Add(m_RecordButton); m_RecordOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordOptionsPanel.layout.width); RecorderOptions.exitPlayMode = EditorGUILayout.Toggle(Styles.ExitPlayModeLabel, RecorderOptions.exitPlayMode); }) { name = "recordOptions" }; UIElementHelper.SetFlex(m_RecordOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordOptionsPanel); m_RecordModeOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordModeOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.RecordModeGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_RecordModeOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordModeOptionsPanel); controlLeftPane.Add(leftButtonsStack); m_FrameRateOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_FrameRateOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.FrameRateGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_FrameRateOptionsPanel, 1.0f); controlRightPane.Add(m_FrameRateOptionsPanel); m_SettingsPanel = new ScrollView(); m_SettingsPanel.name = "SettingPanelScrollView"; UIElementHelper.SetFlex(m_SettingsPanel, 1.0f); UIElementHelper.ResetStylePosition(m_SettingsPanel.contentContainer.style); var recordersAndParameters = new VisualElement { style = { alignSelf = Align.Stretch, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(recordersAndParameters, 1.0f); m_RecordersPanel = new VisualElement { name = "recordersPanel", style = { width = 200.0f, minWidth = 150.0f, maxWidth = 500.0f } }; m_RecordersPanel.AddToClassList("StandardPanel"); m_PanelSplitter = new PanelSplitter(m_RecordersPanel); recordersAndParameters.Add(m_RecordersPanel); recordersAndParameters.Add(m_PanelSplitter); recordersAndParameters.Add(m_SettingsPanel); m_SettingsPanel.AddToClassList("StandardPanel"); root.Add(recordersAndParameters); var addRecordButton = new Label("+ Add Recorder"); UIElementHelper.SetFlex(addRecordButton, 1.0f); var recorderListPresetButton = new VisualElement { name = "recorderListPreset", tooltip = "Manage the recorder list" }; recorderListPresetButton.RegisterCallback <MouseUpEvent>(evt => ShowRecorderListMenu()); recorderListPresetButton.Add(new Image { image = (Texture2D)EditorGUIUtility.Load("Builtin Skins/" + (EditorGUIUtility.isProSkin ? "DarkSkin" : "LightSkin") + "/Images/pane options.png"), style = { width = 16.0f, height = 16.0f } }); addRecordButton.AddToClassList("RecorderListHeader"); recorderListPresetButton.AddToClassList("RecorderListHeader"); addRecordButton.RegisterCallback <MouseUpEvent>(evt => ShowNewRecorderMenu()); m_AddNewRecordPanel = new VisualElement { name = "addRecordersButton", style = { flexDirection = FlexDirection.Row }, tooltip = "Add a new recorder item to the list" }; m_AddNewRecordPanel.Add(addRecordButton); m_AddNewRecordPanel.Add(recorderListPresetButton); m_RecordingListItem = new RecorderItemList { name = "recorderList" }; UIElementHelper.SetFlex(m_RecordingListItem, 1.0f); UIElementHelper.SetFocusable(m_RecordingListItem); m_RecordingListItem.OnItemContextMenu += OnRecordContextMenu; m_RecordingListItem.OnSelectionChanged += OnRecordSelectionChanged; m_RecordingListItem.OnItemRename += item => item.StartRenaming(); m_RecordingListItem.OnContextMenu += ShowNewRecorderMenu; m_RecordersPanel.Add(m_AddNewRecordPanel); m_RecordersPanel.Add(m_RecordingListItem); m_ParametersControl = new VisualElement { style = { minWidth = 300.0f, } }; UIElementHelper.SetFlex(m_ParametersControl, 1.0f); m_RecorderSettingPanel = new IMGUIContainer(OnRecorderSettingsGUI) { name = "recorderSettings" }; UIElementHelper.SetFlex(m_RecorderSettingPanel, 1.0f); var statusBar = new VisualElement { name = "statusBar" }; statusBar.Add(new IMGUIContainer(UpdateRecordingProgressGUI)); root.Add(statusBar); m_ParametersControl.Add(m_RecorderSettingPanel); m_SettingsPanel.Add(m_ParametersControl); #if UNITY_2018_2_OR_NEWER m_RecordingListItem.RegisterCallback <ValidateCommandEvent>(OnRecorderListValidateCommand); m_RecordingListItem.RegisterCallback <ExecuteCommandEvent>(OnRecorderListExecuteCommand); #else m_RecordingListItem.RegisterCallback <IMGUIEvent>(OnRecorderListIMGUI); #endif m_RecordingListItem.RegisterCallback <KeyUpEvent>(OnRecorderListKeyUp); SetRecorderControllerSettings(RecorderControllerSettings.GetGlobalSettings()); Undo.undoRedoPerformed += SaveAndRepaint; EditorApplication.playModeStateChanged += OnPlayModeStateChanged; EditorApplication.update += UpdateInternal; }
void CreateView() { minSize = new Vector2(560.0f, 200.0f); var pathPrefix1 = $"Styles/recorder.uss"; var lightOrDark = EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin"; var pathPrefix2 = $"Styles/{lightOrDark}.uss"; var root = rootVisualElement; var sheet1 = UnityHelpers.LoadLocalPackageAsset <StyleSheet>(pathPrefix1, false); var sheet2 = UnityHelpers.LoadLocalPackageAsset <StyleSheet>(pathPrefix2, false); bool sheetNotFound = sheet1 == null || sheet2 == null; if (sheetNotFound) { s_NeedToResetView = true; return; } root.styleSheets.Add(sheet1); root.styleSheets.Add(sheet2); root.style.flexDirection = FlexDirection.Column; UIElementHelper.SetFocusable(root); var mainControls = new VisualElement { style = { flexDirection = FlexDirection.Row, minHeight = 120.0f } }; root.Add(mainControls); var controlLeftPane = new VisualElement { style = { minWidth = 180.0f, maxWidth = 450.0f, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(controlLeftPane, 0.5f); var controlRightPane = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(controlRightPane, 0.5f); mainControls.Add(controlLeftPane); mainControls.Add(controlRightPane); controlLeftPane.AddToClassList("StandardPanel"); controlRightPane.AddToClassList("StandardPanel"); m_RecordButtonIcon = new Button(OnRecordButtonClick) { name = "recorderIcon", style = { backgroundImage = UnityHelpers.LoadLocalPackageAsset <Texture2D>("recorder_icon.png", true), }, tooltip = "Start the recording for all active recorders of the list\n\n This automatically activates the Play mode first (if not activated yet)." }; controlLeftPane.Add(m_RecordButtonIcon); var leftButtonsStack = new VisualElement { style = { flexDirection = FlexDirection.Column, } }; UIElementHelper.SetFlex(leftButtonsStack, 1.0f); m_RecordButton = new Button(OnRecordButtonClick) { name = "recordButton", tooltip = "Start/Stop the recording for all active recorders of the list\n\nStarting the recording automatically activates the Play mode first (if not activated yet)." }; UpdateRecordButtonText(); leftButtonsStack.Add(m_RecordButton); m_RecordOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordOptionsPanel.layout.width); RecorderOptions.exitPlayMode = EditorGUILayout.Toggle(Styles.ExitPlayModeLabel, RecorderOptions.exitPlayMode); }) { name = "recordOptions" }; UIElementHelper.SetFlex(m_RecordOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordOptionsPanel); m_RecordModeOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_RecordModeOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.RecordModeGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_RecordModeOptionsPanel, 1.0f); leftButtonsStack.Add(m_RecordModeOptionsPanel); controlLeftPane.Add(leftButtonsStack); m_FrameRateOptionsPanel = new IMGUIContainer(() => { PrepareGUIState(m_FrameRateOptionsPanel.layout.width); if (m_RecorderSettingsPrefsEditor.FrameRateGUI()) { OnGlobalSettingsChanged(); } }); UIElementHelper.SetFlex(m_FrameRateOptionsPanel, 1.0f); controlRightPane.Add(m_FrameRateOptionsPanel); m_SettingsPanel = new ScrollView(); m_SettingsPanel.name = "SettingPanelScrollView"; UIElementHelper.SetFlex(m_SettingsPanel, 1.0f); UIElementHelper.ResetStylePosition(m_SettingsPanel.contentContainer.style); var recordersAndParameters = new VisualElement { style = { alignSelf = Align.Stretch, flexDirection = FlexDirection.Row, } }; UIElementHelper.SetFlex(recordersAndParameters, 1.0f); m_RecordersPanel = new VisualElement { name = "recordersPanel", style = { width = 200.0f, minWidth = 150.0f, maxWidth = 500.0f } }; m_RecordersPanel.AddToClassList("StandardPanel"); m_PanelSplitter = new PanelSplitter(m_RecordersPanel); recordersAndParameters.Add(m_RecordersPanel); recordersAndParameters.Add(m_PanelSplitter); recordersAndParameters.Add(m_SettingsPanel); m_SettingsPanel.AddToClassList("StandardPanel"); root.Add(recordersAndParameters); var addRecordButton = new Label("+ Add Recorder"); UIElementHelper.SetFlex(addRecordButton, 1.0f); var recorderListPresetButton = new VisualElement { name = "recorderListPreset", tooltip = "Manage the recorder list" }; recorderListPresetButton.RegisterCallback <MouseUpEvent>(evt => ShowRecorderListMenu()); recorderListPresetButton.Add(new Image { image = (Texture2D)EditorGUIUtility.Load("Builtin Skins/" + (EditorGUIUtility.isProSkin ? "DarkSkin" : "LightSkin") + "/Images/pane options.png"), style = { width = 16.0f, height = 16.0f } }); addRecordButton.AddToClassList("RecorderListHeader"); recorderListPresetButton.AddToClassList("RecorderListHeader"); addRecordButton.RegisterCallback <MouseUpEvent>(evt => ShowNewRecorderMenu()); m_AddNewRecordPanel = new VisualElement { name = "addRecordersButton", style = { flexDirection = FlexDirection.Row }, tooltip = "Add a new recorder item to the list" }; m_AddNewRecordPanel.Add(addRecordButton); m_AddNewRecordPanel.Add(recorderListPresetButton); m_RecordingListItem = new RecorderItemList { name = "recorderList" }; UIElementHelper.SetFlex(m_RecordingListItem, 1.0f); UIElementHelper.SetFocusable(m_RecordingListItem); m_RecordingListItem.OnItemContextMenu += OnRecordContextMenu; m_RecordingListItem.OnSelectionChanged += OnRecordSelectionChanged; m_RecordingListItem.OnItemRename += item => item.StartRenaming(); m_RecordingListItem.OnContextMenu += ShowNewRecorderMenu; m_RecordersPanel.Add(m_AddNewRecordPanel); m_RecordersPanel.Add(m_RecordingListItem); m_ParametersControl = new VisualElement { style = { minWidth = 300.0f, } }; UIElementHelper.SetFlex(m_ParametersControl, 1.0f); m_RecorderSettingPanel = new IMGUIContainer(OnRecorderSettingsGUI) { name = "recorderSettings" }; UIElementHelper.SetFlex(m_RecorderSettingPanel, 1.0f); var statusBar = new VisualElement { name = "statusBar" }; statusBar.Add(new IMGUIContainer(UpdateRecordingProgressGUI)); root.Add(statusBar); m_ParametersControl.Add(m_RecorderSettingPanel); m_SettingsPanel.Add(m_ParametersControl); m_RecordingListItem.RegisterCallback <ValidateCommandEvent>(OnRecorderListValidateCommand); m_RecordingListItem.RegisterCallback <ExecuteCommandEvent>(OnRecorderListExecuteCommand); m_RecordingListItem.RegisterCallback <KeyUpEvent>(OnRecorderListKeyUp); SetRecorderControllerSettings(RecorderControllerSettings.GetGlobalSettings()); }