void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("My custom settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); // create the Preset button at the end of the "MyManager Settings" line. var buttonPosition = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, Styles.iconButton); if (EditorGUI.DropdownButton(buttonPosition, Styles.presetIcon, FocusType.Passive, Styles.iconButton)) { // Create a receiver instance. This destroys itself when the window appears, so you don't need to keep a reference to it. var presetReceiver = ScriptableObject.CreateInstance <MySettingsReceiver>(); presetReceiver.Init(m_SerializedSettings, this); // Show the PresetSelector modal window. The presetReceiver updates your data. PresetSelector.ShowSelector(m_SerializedSettings, null, true, presetReceiver); } EditorGUILayout.EndHorizontal(); // Draw the settings default Inspector and catch any change made to it. EditorGUI.BeginChangeCheck(); m_SettingsEditor.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { // Apply changes made in the settings editor to our instance. m_SerializedSettings.ApplySettings(this); } }
public void OnLoadPresetClicked() { WaterfallPresetReceiver presetRecevier = ScriptableObject.CreateInstance <WaterfallPresetReceiver>(); presetRecevier.Init(waterfallShader); PresetSelector.ShowSelector(waterfallShader, null, false, presetRecevier); }
void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("My custom settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); // 在"MyManager Settings"行的末尾创建 Preset 按钮。 var buttonPosition = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, Styles.iconButton); if (EditorGUI.DropdownButton(buttonPosition, Styles.presetIcon, FocusType.Passive, Styles.iconButton)) { //创建接收器实例。当窗口出现时,此接收器会自行毁坏,所以您不需要保留其引用。 var presetReceiver = ScriptableObject.CreateInstance <MySettingsReceiver>(); presetReceiver.Init(m_SerializedSettings, this); //显示 PresetSelector 模态窗口。presetReceiver 会更新您的数据。 PresetSelector.ShowSelector(m_SerializedSettings, null, true, presetReceiver); } EditorGUILayout.EndHorizontal(); //绘制设置默认 Inspector 并捕获对其所做的任何更改。 EditorGUI.BeginChangeCheck(); m_SettingsEditor.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { //将设置编辑器中所做的更改应用于我们的实例。 m_SerializedSettings.ApplySettings(this); } }
void OnRecorderSettingPresetClicked() { if (m_SelectedRecorderItem != null && m_SelectedRecorderItem.settings != null) { var presetReceiver = CreateInstance <PresetHelper.PresetReceiver>(); presetReceiver.Init(m_SelectedRecorderItem.settings, Repaint, () => m_ControllerSettings.Save()); PresetSelector.ShowSelector(m_SelectedRecorderItem.settings, null, true, presetReceiver); } }
private void ShowPresetSelector(SerializedObject serializedObject) { var target = serializedObject.targetObject; if (!new PresetType(target).IsValid() || (target.hideFlags & HideFlags.NotEditable) != 0) { return; } PresetSelector.ShowSelector(serializedObject.targetObjects, null, true); }
// Update is called once per frame void OnGUI() { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("My Custom Settings", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); var buttonPosition = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, Styles.iconButton); if (EditorGUI.DropdownButton(buttonPosition, Styles.presetIcon, FocusType.Passive, Styles.iconButton)) { var presetReceiver = ScriptableObject.CreateInstance <MySettingsReceiver>(); presetReceiver.Init(m_SerializedSettings, this); PresetSelector.ShowSelector(m_SerializedSettings, null, true, presetReceiver); } EditorGUILayout.EndHorizontal(); EditorGUI.BeginChangeCheck(); m_SettingEditor.OnInspectorGUI(); if (EditorGUI.EndChangeCheck()) { m_SerializedSettings.ApplySettings(this); } }
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"); } }
public override void OnInspectorGUI() { try { if (target == null) { return; } // Bug? work arround: on Stop play, Enable is not called. if (m_Editor != null && m_Editor.target == null) { UnityHelpers.Destroy(m_Editor); m_Editor = null; m_RecorderSelector = null; } if (m_RecorderSelector == null) { m_RecorderSelector = new RecorderSelector(); m_RecorderSelector.OnSelectionChanged += OnRecorderSelected; m_RecorderSelector.Init(((RecorderClip)target).settings); } using (new EditorGUI.DisabledScope(EditorApplication.isPlaying)) { var clip = (RecorderClip)target; if (m_Timeline == null) { m_Timeline = clip.FindTimelineAsset(); } if (m_Timeline != null) { EditorGUILayout.LabelField("Frame Rate"); EditorGUI.indentLevel++; EditorGUILayout.LabelField("Playback", FrameRatePlayback.Constant.ToString()); EditorGUILayout.LabelField("Target (Timeline FPS)", m_Timeline.editorSettings.fps.ToString(CultureInfo.InvariantCulture)); EditorGUI.indentLevel--; EditorGUILayout.Separator(); } EditorGUILayout.BeginHorizontal(); m_RecorderSelector.OnGui(); if (m_Editor != null) { if (GUILayout.Button(PresetHelper.presetIcon, PresetHelper.presetButtonStyle)) { var settings = m_Editor.target as RecorderSettings; if (settings != null) { var presetReceiver = CreateInstance <PresetHelper.PresetReceiver>(); presetReceiver.Init(settings, Repaint); PresetSelector.ShowSelector(settings, null, true, presetReceiver); } } } EditorGUILayout.EndHorizontal(); if (m_Editor != null) { EditorGUILayout.Separator(); var prevValue = RecorderEditor.FromRecorderWindow; RecorderEditor.FromRecorderWindow = false; m_Editor.OnInspectorGUI(); RecorderEditor.FromRecorderWindow = prevValue; serializedObject.Update(); } } } catch (ExitGUIException) { } catch (Exception ex) { EditorGUILayout.HelpBox("An exception was raised while editing the settings. This can be indicative of corrupted settings.", MessageType.Warning); if (GUILayout.Button("Reset settings to default")) { ResetSettings(); } Debug.LogException(ex); } }