Preferences.User.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEditor;
  4. using UnityEngine;
  5. namespace AmplifyShaderEditor
  6. {
  7. public partial class Preferences
  8. {
  9. public enum ShowOption
  10. {
  11. Always = 0,
  12. OnNewVersion = 1,
  13. Never = 2
  14. }
  15. public class User
  16. {
  17. private class Styles
  18. {
  19. public static readonly GUIContent StartUp = new GUIContent( "Show start screen on Unity launch", "You can set if you want to see the start screen everytime Unity launchs, only just when there's a new version available or never." );
  20. public static readonly GUIContent AlwaysSnapToGrid = new GUIContent( "Always Snap to Grid", "Always snap to grid when dragging nodes around, instead of using control." );
  21. public static readonly GUIContent EnableUndo = new GUIContent( "Enable Undo (unstable)", "Enables undo for actions within the shader graph canvas. Currently unstable, use with caution." );
  22. public static readonly GUIContent ClearLog = new GUIContent( "Clear Log on Update", "Clears the previously generated log each time the Update button is pressed." );
  23. public static readonly GUIContent LogShaderCompile = new GUIContent( "Log Shader Compile", "Log message to console when a shader compilation is finished." );
  24. public static readonly GUIContent LogBatchCompile = new GUIContent( "Log Batch Compile", "Log message to console when a batch compilation is finished." );
  25. public static readonly GUIContent UpdateOnSceneSave = new GUIContent( "Update on Scene save (Ctrl+S)", "ASE is aware of Ctrl+S and will use it to save shader." );
  26. public static readonly GUIContent DisablePreviews = new GUIContent( "Disable Node Previews", "Disable preview on nodes from being updated to boost up performance on large graphs." );
  27. public static readonly GUIContent DisableMaterialMode = new GUIContent( "Disable Material Mode", "Disable enter Material Mode graph when double-clicking on material asset." );
  28. public static readonly GUIContent ForceTemplateMinShaderModel = new GUIContent( "Force Template Min. Shader Model", "If active, when loading a shader its shader model will be replaced by the one specified in template if what is loaded is below the one set over the template." );
  29. public static readonly GUIContent ForceTemplateInlineProperties = new GUIContent( "Force Template Inline Properties", "If active, defaults all inline properties to template values." );
  30. }
  31. private class Defaults
  32. {
  33. public const ShowOption StartUp = ShowOption.Always;
  34. public const bool AlwaysSnapToGrid = true;
  35. public const bool EnableUndo = false;
  36. public const bool ClearLog = true;
  37. public const bool LogShaderCompile = false;
  38. public const bool LogBatchCompile = false;
  39. public const bool UpdateOnSceneSave = true;
  40. public const bool DisablePreviews = false;
  41. public const bool DisableMaterialMode = false;
  42. public const bool ForceTemplateMinShaderModel = true;
  43. public const bool ForceTemplateInlineProperties = false;
  44. }
  45. // @diogo: make this private
  46. public class Keys
  47. {
  48. public static string StartUp = "ASELastSession";
  49. public static string AlwaysSnapToGrid = "ASEAlwaysSnapToGrid";
  50. public static string EnableUndo = "ASEEnableUndo";
  51. public static string ClearLog = "ASEClearLog";
  52. public static string LogShaderCompile = "ASELogShaderCompile";
  53. public static string LogBatchCompile = "ASELogBatchCompile";
  54. public static string UpdateOnSceneSave = "ASEUpdateOnSceneSave";
  55. public static string DisablePreviews = "ASEActivatePreviews";
  56. public static string DisableMaterialMode = "ASEDisableMaterialMode";
  57. public static string ForceTemplateMinShaderModel = "ASEForceTemplateMinShaderModel";
  58. public static string ForceTemplateInlineProperties = "ASEForceTemplateInlineProperties";
  59. }
  60. public static ShowOption StartUp = Defaults.StartUp;
  61. public static bool AlwaysSnapToGrid = Defaults.AlwaysSnapToGrid;
  62. public static bool EnableUndo = Defaults.EnableUndo;
  63. public static bool ClearLog = Defaults.ClearLog;
  64. public static bool LogShaderCompile = Defaults.LogShaderCompile;
  65. public static bool LogBatchCompile = Defaults.LogBatchCompile;
  66. public static bool UpdateOnSceneSave = Defaults.UpdateOnSceneSave;
  67. public static bool DisablePreviews = Defaults.DisablePreviews;
  68. public static bool DisableMaterialMode = Defaults.DisableMaterialMode;
  69. public static bool ForceTemplateMinShaderModel = Defaults.ForceTemplateMinShaderModel;
  70. public static bool ForceTemplateInlineProperties = Defaults.ForceTemplateInlineProperties;
  71. public static void ResetSettings()
  72. {
  73. EditorPrefs.DeleteKey( Keys.StartUp );
  74. EditorPrefs.DeleteKey( Keys.AlwaysSnapToGrid );
  75. EditorPrefs.DeleteKey( Keys.EnableUndo );
  76. EditorPrefs.DeleteKey( Keys.ClearLog );
  77. EditorPrefs.DeleteKey( Keys.LogShaderCompile );
  78. EditorPrefs.DeleteKey( Keys.LogBatchCompile );
  79. EditorPrefs.DeleteKey( Keys.UpdateOnSceneSave );
  80. EditorPrefs.DeleteKey( Keys.DisablePreviews );
  81. EditorPrefs.DeleteKey( Keys.DisableMaterialMode );
  82. EditorPrefs.DeleteKey( Keys.ForceTemplateMinShaderModel );
  83. EditorPrefs.DeleteKey( Keys.ForceTemplateInlineProperties );
  84. StartUp = Defaults.StartUp;
  85. AlwaysSnapToGrid = Defaults.AlwaysSnapToGrid;
  86. EnableUndo = Defaults.EnableUndo;
  87. ClearLog = Defaults.ClearLog;
  88. LogShaderCompile = Defaults.LogShaderCompile;
  89. LogBatchCompile = Defaults.LogBatchCompile;
  90. UpdateOnSceneSave = Defaults.UpdateOnSceneSave;
  91. DisablePreviews = Defaults.DisablePreviews;
  92. DisableMaterialMode = Defaults.DisableMaterialMode;
  93. ForceTemplateMinShaderModel = Defaults.ForceTemplateMinShaderModel;
  94. ForceTemplateInlineProperties = Defaults.ForceTemplateInlineProperties;
  95. }
  96. public static void LoadSettings()
  97. {
  98. StartUp = ( ShowOption )EditorPrefs.GetInt( Keys.StartUp, ( int )Defaults.StartUp );
  99. AlwaysSnapToGrid = EditorPrefs.GetBool( Keys.AlwaysSnapToGrid, Defaults.AlwaysSnapToGrid );
  100. EnableUndo = EditorPrefs.GetBool( Keys.EnableUndo, Defaults.EnableUndo );
  101. ClearLog = EditorPrefs.GetBool( Keys.ClearLog, Defaults.ClearLog );
  102. LogShaderCompile = EditorPrefs.GetBool( Keys.LogShaderCompile, Defaults.LogShaderCompile );
  103. LogBatchCompile = EditorPrefs.GetBool( Keys.LogBatchCompile, Defaults.LogBatchCompile );
  104. UpdateOnSceneSave = EditorPrefs.GetBool( Keys.UpdateOnSceneSave, Defaults.UpdateOnSceneSave );
  105. DisablePreviews = EditorPrefs.GetBool( Keys.DisablePreviews, Defaults.DisablePreviews );
  106. DisableMaterialMode = EditorPrefs.GetBool( Keys.DisableMaterialMode, Defaults.DisableMaterialMode );
  107. ForceTemplateMinShaderModel = EditorPrefs.GetBool( Keys.ForceTemplateMinShaderModel, Defaults.ForceTemplateMinShaderModel );
  108. ForceTemplateInlineProperties = EditorPrefs.GetBool( Keys.ForceTemplateInlineProperties, Defaults.ForceTemplateInlineProperties );
  109. }
  110. public static void SaveSettings()
  111. {
  112. bool prevDisablePreviews = EditorPrefs.GetBool( Keys.DisablePreviews, false );
  113. if ( DisablePreviews != prevDisablePreviews )
  114. {
  115. UIUtils.ActivatePreviews( !DisablePreviews );
  116. }
  117. EditorPrefs.SetInt( Keys.StartUp, ( int )StartUp );
  118. EditorPrefs.SetBool( Keys.AlwaysSnapToGrid, AlwaysSnapToGrid );
  119. EditorPrefs.SetBool( Keys.EnableUndo, EnableUndo );
  120. EditorPrefs.SetBool( Keys.ClearLog, ClearLog );
  121. EditorPrefs.SetBool( Keys.LogShaderCompile, LogShaderCompile );
  122. EditorPrefs.SetBool( Keys.LogBatchCompile, LogBatchCompile );
  123. EditorPrefs.SetBool( Keys.UpdateOnSceneSave, UpdateOnSceneSave );
  124. EditorPrefs.SetBool( Keys.DisablePreviews, DisablePreviews );
  125. EditorPrefs.SetBool( Keys.DisableMaterialMode, DisableMaterialMode );
  126. EditorPrefs.SetBool( Keys.ForceTemplateMinShaderModel, ForceTemplateMinShaderModel );
  127. EditorPrefs.SetBool( Keys.ForceTemplateInlineProperties, ForceTemplateInlineProperties );
  128. }
  129. public static void InspectorLayout()
  130. {
  131. StartUp = ( ShowOption )EditorGUILayout.EnumPopup( Styles.StartUp, StartUp );
  132. AlwaysSnapToGrid = EditorGUILayout.Toggle( Styles.AlwaysSnapToGrid, AlwaysSnapToGrid );
  133. EnableUndo = EditorGUILayout.Toggle( Styles.EnableUndo, EnableUndo );
  134. ClearLog = EditorGUILayout.Toggle( Styles.ClearLog, ClearLog );
  135. LogShaderCompile = EditorGUILayout.Toggle( Styles.LogShaderCompile, LogShaderCompile );
  136. LogBatchCompile = EditorGUILayout.Toggle( Styles.LogBatchCompile, LogBatchCompile );
  137. UpdateOnSceneSave = EditorGUILayout.Toggle( Styles.UpdateOnSceneSave, UpdateOnSceneSave );
  138. DisablePreviews = EditorGUILayout.Toggle( Styles.DisablePreviews, DisablePreviews );
  139. DisableMaterialMode = EditorGUILayout.Toggle( Styles.DisableMaterialMode, DisableMaterialMode );
  140. ForceTemplateMinShaderModel = EditorGUILayout.Toggle( Styles.ForceTemplateMinShaderModel, ForceTemplateMinShaderModel );
  141. ForceTemplateInlineProperties = EditorGUILayout.Toggle( Styles.ForceTemplateInlineProperties, ForceTemplateInlineProperties );
  142. }
  143. }
  144. }
  145. }