Preferences.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace AmplifyShaderEditor
  7. {
  8. public partial class Preferences
  9. {
  10. [SettingsProvider]
  11. public static SettingsProvider AmplifyShaderEditorSettings()
  12. {
  13. var provider = new SettingsProvider( "Preferences/Amplify Shader Editor", SettingsScope.User )
  14. {
  15. guiHandler = ( string searchContext ) =>
  16. {
  17. PreferencesGUI();
  18. },
  19. keywords = new HashSet<string>( new[] { "start", "screen", "import", "shader", "templates", "macros", "macros", "define", "symbol" } ),
  20. };
  21. return provider;
  22. }
  23. private static void ResetSettings()
  24. {
  25. User.ResetSettings();
  26. Project.ResetSettings();
  27. User.SaveSettings();
  28. Project.SaveSettings();
  29. }
  30. private static void LoadSettings()
  31. {
  32. User.LoadSettings();
  33. Project.LoadSettings();
  34. }
  35. public static void Initialize()
  36. {
  37. LoadSettings();
  38. }
  39. public static void PreferencesGUI()
  40. {
  41. var cache = EditorGUIUtility.labelWidth;
  42. EditorGUIUtility.labelWidth = 250;
  43. EditorGUI.BeginChangeCheck();
  44. {
  45. EditorGUILayout.LabelField( "User", EditorStyles.boldLabel );
  46. User.InspectorLayout();
  47. }
  48. if ( EditorGUI.EndChangeCheck() )
  49. {
  50. User.SaveSettings();
  51. }
  52. EditorGUI.BeginChangeCheck();
  53. {
  54. EditorGUILayout.LabelField( "Project", EditorStyles.boldLabel );
  55. Project.InspectorLayout();
  56. }
  57. if ( EditorGUI.EndChangeCheck() )
  58. {
  59. Project.SaveSettings();
  60. }
  61. EditorGUILayout.BeginHorizontal();
  62. GUILayout.FlexibleSpace();
  63. if( GUILayout.Button( "Reset and Forget All" ) )
  64. {
  65. ResetSettings();
  66. }
  67. EditorGUILayout.EndHorizontal();
  68. EditorGUIUtility.labelWidth = cache;
  69. }
  70. }
  71. }