Assignment for RMIT Mixed Reality in 2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.0 KiB

  1. // Amplify Shader Editor - Visual Shader Editing Tool
  2. // Copyright (c) Amplify Creations, Lda <info@amplify.pt>
  3. using UnityEngine;
  4. using UnityEditor;
  5. using System.Collections.Generic;
  6. namespace AmplifyShaderEditor
  7. {
  8. public class Preferences
  9. {
  10. public enum ShowOption
  11. {
  12. Always = 0,
  13. OnNewVersion = 1,
  14. Never = 2
  15. }
  16. private 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." );
  17. public static readonly string PrefStartUp = "ASELastSession" + Application.productName;
  18. public static ShowOption GlobalStartUp = ShowOption.Always;
  19. private static readonly GUIContent AutoSRP = new GUIContent( "Auto import SRP shader templates", "By default Amplify Shader Editor checks for your SRP version and automatically imports the correct corresponding shader templates.\nTurn this OFF if you prefer to import them manually." );
  20. public static readonly string PrefAutoSRP = "ASEAutoSRP" + Application.productName;
  21. public static bool GlobalAutoSRP = true;
  22. private static readonly GUIContent DefineSymbol = new GUIContent( "Add Amplify Shader Editor define symbol", "Turning it OFF will disable the automatic insertion of the define symbol and remove it from the list while turning it ON will do the opposite.\nThis is used for compatibility with other plugins, if you are not sure if you need this leave it ON." );
  23. public static readonly string PrefDefineSymbol = "ASEDefineSymbol" + Application.productName;
  24. public static bool GlobalDefineSymbol = true;
  25. private static bool PrefsLoaded = false;
  26. #if UNITY_2019_1_OR_NEWER
  27. [SettingsProvider]
  28. public static SettingsProvider ImpostorsSettings()
  29. {
  30. var provider = new SettingsProvider( "Preferences/Amplify Shader Editor", SettingsScope.User )
  31. {
  32. guiHandler = ( string searchContext ) =>
  33. {
  34. PreferencesGUI();
  35. },
  36. keywords = new HashSet<string>( new[] { "start", "screen", "import", "shader", "templates", "macros", "macros", "define", "symbol" } ),
  37. };
  38. return provider;
  39. }
  40. #else
  41. [PreferenceItem( "Amplify Shader Editor" )]
  42. #endif
  43. public static void PreferencesGUI()
  44. {
  45. if( !PrefsLoaded )
  46. {
  47. LoadDefaults();
  48. PrefsLoaded = true;
  49. }
  50. var cache = EditorGUIUtility.labelWidth;
  51. EditorGUIUtility.labelWidth = 250;
  52. EditorGUI.BeginChangeCheck();
  53. GlobalStartUp = (ShowOption)EditorGUILayout.EnumPopup( StartUp, GlobalStartUp );
  54. if( EditorGUI.EndChangeCheck() )
  55. {
  56. EditorPrefs.SetInt( PrefStartUp, (int)GlobalStartUp );
  57. }
  58. EditorGUI.BeginChangeCheck();
  59. GlobalAutoSRP = EditorGUILayout.Toggle( AutoSRP, GlobalAutoSRP );
  60. if( EditorGUI.EndChangeCheck() )
  61. {
  62. EditorPrefs.SetBool( PrefAutoSRP, GlobalAutoSRP );
  63. }
  64. EditorGUI.BeginChangeCheck();
  65. GlobalDefineSymbol = EditorGUILayout.Toggle( DefineSymbol, GlobalDefineSymbol );
  66. if( EditorGUI.EndChangeCheck() )
  67. {
  68. EditorPrefs.SetBool( PrefDefineSymbol, GlobalDefineSymbol );
  69. if( GlobalDefineSymbol )
  70. IOUtils.SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
  71. else
  72. IOUtils.RemoveAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
  73. }
  74. EditorGUILayout.BeginHorizontal();
  75. GUILayout.FlexibleSpace();
  76. if( GUILayout.Button( "Reset and Forget All" ) )
  77. {
  78. EditorPrefs.DeleteKey( PrefStartUp );
  79. GlobalStartUp = ShowOption.Always;
  80. EditorPrefs.DeleteKey( PrefAutoSRP );
  81. GlobalAutoSRP = true;
  82. EditorPrefs.DeleteKey( PrefDefineSymbol );
  83. GlobalDefineSymbol = true;
  84. IOUtils.SetAmplifyDefineSymbolOnBuildTargetGroup( EditorUserBuildSettings.selectedBuildTargetGroup );
  85. }
  86. EditorGUILayout.EndHorizontal();
  87. EditorGUIUtility.labelWidth = cache;
  88. }
  89. public static void LoadDefaults()
  90. {
  91. GlobalStartUp = (ShowOption)EditorPrefs.GetInt( PrefStartUp, 0 );
  92. GlobalAutoSRP = EditorPrefs.GetBool( PrefAutoSRP, true );
  93. GlobalDefineSymbol = EditorPrefs.GetBool( PrefDefineSymbol, true );
  94. }
  95. }
  96. }