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); } }
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); } }
public override void OnSelectionChanged(Preset selection) { if (selection == null) { initialValues.ApplyTo(currentSettings); } else { selection.ApplyTo(currentSettings); } currentSettings.ApplySettings(currentWindow); }
public override void OnSelectionChanged(Preset selection) { if (selection != null) { // Apply the selection to the temporary settings selection.ApplyTo(currentSettings); } else { // None have been selected. Apply the Initial values back to the temporary selection. initialValues.ApplyTo(currentSettings); } // Apply the new temporary settings to our manager instance currentSettings.ApplySettings(currentWindow); }
public override void OnSelectionChanged(Preset selection) { if (selection != null) { //将选择应用于临时设置 selection.ApplyTo(currentSettings); } else { // 未进行任何选择。将初始值反向应用于临时选择。 initialValues.ApplyTo(currentSettings); } //将新的临时设置应用于我们的管理器实例 currentSettings.ApplySettings(currentWindow); }
// 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); } }