Exemple #1
0
        public RecorderItem(RecorderControllerSettings prefs, RecorderSettings recorderSettings, string iconName)
        {
            settings = recorderSettings;

            if (settings != null)
            {
                editor = Editor.CreateEditor(settings);
            }

            UIElementHelper.SetFlex(this, 1.0f);
            style.flexDirection = FlexDirection.Row;

            m_Toggle = new Toggle(null);

            m_Toggle.OnToggle(() =>
            {
                SetItemEnabled(prefs, UIElementHelper.GetToggleValue(m_Toggle));
            });

            Add(m_Toggle);

            m_RecorderIcon = LoadIcon(iconName);

            if (m_RecorderIcon == null)
            {
                m_RecorderIcon = LoadIcon("customrecorder_16");
            }

            UpdateState(false);

            var iconContainer = new IMGUIContainer(() => // UIElement Image doesn't support tint yet. Use IMGUI instead.
            {
                var r   = EditorGUILayout.GetControlRect();
                r.width = r.height = Mathf.Max(r.width, r.height);

                var c = GUI.color;

                var newColor = Color.white;

                if (m_Disabled)
                {
                    newColor.a = 0.5f;
                }
                else
                {
                    if (!m_Selected)
                    {
                        newColor.a = 0.8f;
                    }
                }

                GUI.color = newColor;

                GUI.DrawTexture(r, m_Icon);

                GUI.color = c;
            });

            iconContainer.AddToClassList("RecorderItemIcon");

            iconContainer.SetEnabled(false);

            Add(iconContainer);

            m_EditableLabel = new EditableLabel {
                text = settings.name
            };
            m_EditableLabel.OnValueChanged(newValue =>
            {
                settings.name = newValue;
                prefs.Save();
            });
            Add(m_EditableLabel);

            var recorderEnabled = settings.enabled;

            UIElementHelper.SetToggleValue(m_Toggle, recorderEnabled);

            SetItemEnabled(prefs, recorderEnabled);
        }
Exemple #2
0
        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());
        }
 /// <summary>
 /// The constructor of the RecorderController.
 /// </summary>
 /// <param name="settings">The settings to be used by this RecorderController.</param>
 public RecorderController(RecorderControllerSettings settings)
 {
     m_Settings  = settings;
     m_SceneHook = new SceneHook(Guid.NewGuid().ToString());
 }
Exemple #4
0
        void OnEnable()
        {
            minSize = new Vector2(560.0f, 200.0f);

            var root = this.GetRootVisualContainer();

            root.style.flexDirection = FlexDirection.Column;

            root.AddStyleSheetPath(s_StylesFolder + "recorder");
            root.AddStyleSheetPath(s_StylesFolder + (EditorGUIUtility.isProSkin ? "recorder_darkSkin" : "recorder_lightSkin"));

            root.focusIndex = 0;

            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_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);

            m_SettingsPanel.contentContainer.style.positionLeft  = 0;
            m_SettingsPanel.contentContainer.style.positionRight = 0;

            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)
            {
                persistenceKey = "RecordingPanelSplitter"
            };

            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",
                persistenceKey = "RecordersList",
                focusIndex     = 0
            };

            UIElementHelper.SetFlex(m_RecordingListItem, 1.0f);

            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,
                    backgroundSize  = ScaleMode.ScaleToFit,
                    sliceTop        =                       0,
                    sliceBottom     =                       0,
                    sliceLeft       =                       0,
                    sliceRight      =                       0,
                    paddingTop      =                    0.0f,
                    paddingLeft     =                    0.0f,
                    paddingBottom   =                    0.0f,
                    paddingRight    =                    0.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_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;
        }