Exemple #1
0
        public void SetItemEnabled(RecorderControllerSettings prefs, bool value)
        {
            m_Disabled       = !value;
            settings.enabled = value;
            prefs.Save();

            m_EditableLabel.SetLabelEnabled(value);

            if (m_Toggle != null)
            {
                UIElementHelper.SetToggleValue(m_Toggle, value);
            }

            if (value)
            {
                RemoveFromClassList("disabled");
            }
            else
            {
                AddToClassList("disabled");
            }

            if (OnEnableStateChanged != null)
            {
                OnEnableStateChanged.Invoke(value);
            }
        }
Exemple #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Initialize(property);

            m_ImageHeight.intValue = m_HeightSelector.Popup(label, m_ImageHeight.intValue, m_MaxSupportedHeight.intValue);
            var selected = (ImageHeight)m_ImageHeight.intValue;

            if (selected == ImageHeight.Custom)
            {
                var outputDimensions = new int[2];
                outputDimensions[0] = m_CustomWidth.intValue;
                outputDimensions[1] = m_CustomHeight.intValue;

                if (UIElementHelper.MultiIntField(GUIContent.none, Styles.CustomDimensionsLabels, outputDimensions))
                {
                    m_CustomWidth.intValue  = outputDimensions[0];
                    m_CustomHeight.intValue = outputDimensions[1];
                }
            }

            if (selected != ImageHeight.Custom && selected != ImageHeight.Window)
            {
                EditorGUILayout.PropertyField(m_AspectRatio, Styles.ImageAspectLabel);
            }
        }
        void OnAddNewRecorder(RecorderInfo info)
        {
            var recorder = RecordersInventory.CreateDefaultRecorderSettings(info.settingsType);

            AddLastAndSelect(recorder, ObjectNames.NicifyVariableName(info.displayName), true);

            UIElementHelper.SetDirty(m_RecorderSettingPanel);
        }
Exemple #4
0
        void SaveAndRepaint()
        {
            if (m_ControllerSettings != null)
            {
                m_ControllerSettings.Save();
            }

            if (m_SelectedRecorderItem != null)
            {
                UIElementHelper.SetDirty(m_RecorderSettingPanel);
            }

            Repaint();
        }
        internal EditableLabel()
        {
            m_IsEditing = false;
            m_Label     = new Label();
            m_TextField = new TextField();

            UIElementHelper.SetFlex(this, 1.0f);
            UIElementHelper.SetFlex(m_TextField, 1.0f);

            Add(m_Label);

            UIElementHelper.RegisterTrickleDownCallback <KeyUpEvent>(this, OnKeyUpCallback);

            m_TextField.RegisterCallback <FocusOutEvent>(OnTextFieldLostFocus);
        }
Exemple #6
0
        void OnRecordSelectionChanged()
        {
            m_SelectedRecorderItem = m_RecordingListItem.selection;

            foreach (var r in m_RecordingListItem.items)
            {
                r.SetItemSelected(m_SelectedRecorderItem == r);
            }

            if (m_SelectedRecorderItem != null)
            {
                UIElementHelper.SetDirty(m_RecorderSettingPanel);
            }

            Repaint();
        }
        internal void StartEditing()
        {
            if (m_IsEditing)
            {
                return;
            }

            m_IsEditing       = true;
            m_TextField.value = m_Label.text;
            Remove(m_Label);
            Add(m_TextField);
            UIElementHelper.SetFocusable(m_TextField);
            m_TextField.delegatesFocus = true;
            m_PreviouslyFocused        = focusController.focusedElement;
            m_TextField.Focus();
        }
Exemple #8
0
        public PanelSplitter(VisualElement affectedElement)
        {
            m_AffectedElement = affectedElement;

            style.width = k_SplitterWidth;
            style.minWidth = k_SplitterWidth;
            style.maxWidth = k_SplitterWidth;

            UIElementHelper.RegisterTrickleDownCallback<MouseDownEvent>(this, OnMouseDown);
            UIElementHelper.RegisterTrickleDownCallback<MouseMoveEvent>(this, OnMouseMove);
            UIElementHelper.RegisterTrickleDownCallback<MouseUpEvent>(this, OnMouseUp);

            var w = RecorderOptions.recorderPanelWith;
            if (w > 0.0f)
                SetWidth(w);
        }
        void OnRecorderSettingsGUI()
        {
            PrepareGUIState(m_RecorderSettingPanel.layout.width);

            if (m_SelectedRecorderItem != null)
            {
                if (m_SelectedRecorderItem.state == RecorderItem.State.HasErrors)
                {
                    EditorGUILayout.LabelField("Missing reference to the recorder.");
                }
                else
                {
                    var editor = m_SelectedRecorderItem.editor;

                    if (editor == null)
                    {
                        EditorGUILayout.LabelField("Error while displaying the recorder inspector");
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Recorder Type",
                                                   ObjectNames.NicifyVariableName(editor.target.GetType().Name));

                        if (!(editor is RecorderEditor))
                        {
                            EditorGUILayout.LabelField(string.Empty, GUI.skin.horizontalSlider);
                        }

                        EditorGUI.BeginChangeCheck();

                        editor.OnInspectorGUI();

                        if (EditorGUI.EndChangeCheck())
                        {
                            m_ControllerSettings.Save();
                            m_SelectedRecorderItem.UpdateState();
                            UIElementHelper.SetDirty(m_RecorderSettingPanel);
                        }
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField("No recorder selected");
            }
        }
Exemple #10
0
        protected VisualListItem()
        {
            m_ScrollView = new ScrollView
            {
                style =
                {
                    flexDirection = FlexDirection.Column
                }
            };

            UIElementHelper.SetFlex(m_ScrollView, 1.0f);
            UIElementHelper.ResetStylePosition(m_ScrollView.contentContainer.style);

            Add(m_ScrollView);
            RegisterCallback <MouseUpEvent>(OnMouseUp);
            m_SelectionIndex = Options.selectedRecorderIndex;
        }
        protected VisualListItem()
        {
            m_ScrollView = new ScrollView
            {
                style =
                {
                    flexDirection = FlexDirection.Column
                }
            };

            UIElementHelper.SetFlex(m_ScrollView, 1.0f);

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

            Add(m_ScrollView);

            RegisterCallback <MouseUpEvent>(OnMouseUp);
        }
Exemple #12
0
        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 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;
        }
        internal bool RecordModeGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_RecordModeProperty, Styles.RecordModeLabel);

            ++EditorGUI.indentLevel;

            switch ((RecordMode)m_RecordModeProperty.enumValueIndex)
            {
            case RecordMode.Manual:
            {
                // Nothing
                break;
            }

            case RecordMode.SingleFrame:
            {
                var value = EditorGUILayout.IntField(Styles.SingleFrameLabel, m_StartFrameProperty.intValue);
                m_StartFrameProperty.intValue = Mathf.Max(value, 0);

                break;
            }

            case RecordMode.FrameInterval:
            {
                var outputDimensions = new int[2];
                outputDimensions[0] = m_StartFrameProperty.intValue;
                outputDimensions[1] = m_EndFrameProperty.intValue;

                if (UIElementHelper.MultiIntField(GUIContent.none, new[] { Styles.StartLabel, Styles.EndLabel },
                                                  outputDimensions))
                {
                    m_StartFrameProperty.intValue = Mathf.Max(outputDimensions[0], 0);
                    m_EndFrameProperty.intValue   = Mathf.Max(outputDimensions[1], m_StartFrameProperty.intValue);
                }

                break;
            }

            case RecordMode.TimeInterval:
            {
                var outputDimensions = new float[2];
                outputDimensions[0] = m_StartTimeProperty.floatValue;
                outputDimensions[1] = m_EndTimeProperty.floatValue;

                if (UIElementHelper.MultiFloatField(GUIContent.none, new[] { Styles.StartLabel, Styles.EndLabel },
                                                    outputDimensions))
                {
                    m_StartTimeProperty.floatValue = Mathf.Max(outputDimensions[0], 0);
                    m_EndTimeProperty.floatValue   = Mathf.Max(outputDimensions[1], m_StartTimeProperty.floatValue);
                }

                break;
            }
            }

            --EditorGUI.indentLevel;

            serializedObject.ApplyModifiedProperties();

            return(GUI.changed);
        }
Exemple #15
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());
        }
Exemple #16
0
        void OnRecorderSettingsGUI()
        {
            PrepareGUIState(m_RecorderSettingPanel.layout.width);

            if (m_SelectedRecorderItem != null)
            {
                if (m_SelectedRecorderItem.state == RecorderItem.State.HasErrors)
                {
                    EditorGUILayout.LabelField("Missing reference to the recorder.");
                }
                else
                {
                    var editor = m_SelectedRecorderItem.editor;

                    if (editor == null)
                    {
                        EditorGUILayout.LabelField("Error while displaying the recorder inspector");
                    }
                    else
                    {
                        EditorGUIUtility.labelWidth = Mathf.Min(Mathf.Max(m_RecorderSettingPanel.layout.width * 0.45f - 40, 110), 140);
                        EditorGUILayout.Separator();

                        EditorGUILayout.BeginHorizontal();
                        EditorGUILayout.LabelField("Recorder Type",
                                                   ObjectNames.NicifyVariableName(editor.target.GetType().Name));

                        if (!(editor is RecorderEditor))
                        {
                            EditorGUILayout.LabelField(string.Empty, GUI.skin.horizontalSlider);
                        }

                        // Open Manual
                        if (GUILayout.Button(GetIconAndTooltip("_Help", "Open Reference for Recorder"), PresetHelper.presetButtonStyle))
                        {
                            Application.OpenURL(Styles.GetLinkToManual(s_PackageShortVersionNumber));
                        }

                        if (GUILayout.Button(PresetHelper.presetIcon, PresetHelper.presetButtonStyle))
                        {
                            var settings = editor.target as RecorderSettings;

                            if (settings != null)
                            {
                                var presetReceiver = CreateInstance <PresetHelper.PresetReceiver>();
                                presetReceiver.Init(settings, Repaint);

                                PresetSelector.ShowSelector(settings, null, true, presetReceiver);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                        EditorGUILayout.Separator();

                        EditorGUI.BeginChangeCheck();
                        EditorGUILayout.Separator();

                        editor.OnInspectorGUI();

                        if (EditorGUI.EndChangeCheck())
                        {
                            m_ControllerSettings.Save();
                            m_SelectedRecorderItem.UpdateState();
                            UIElementHelper.SetDirty(m_RecorderSettingPanel);
                        }
                    }
                }
            }
            else
            {
                EditorGUILayout.LabelField("No recorder selected");
            }
        }
Exemple #17
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();

#if UNITY_2019_1_OR_NEWER
            m_Toggle.RegisterValueChangedCallback(evt =>
#elif UNITY_2018_3_OR_NEWER
            m_Toggle.OnValueChanged(evt =>
#else
            m_Toggle.OnToggle(() =>
#endif
            {
                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);
        }