TriLibSettingsProvider.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using System.Collections.Generic;
  3. using TriLibCore.Mappers;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace TriLibCore.Editor
  7. {
  8. public class TriLibSettingsProvider : SettingsProvider
  9. {
  10. private class Styles
  11. {
  12. public static readonly GUIStyle Group = new GUIStyle { padding = new RectOffset(10, 10, 5, 5) };
  13. }
  14. private static string _settingsFilePath;
  15. public TriLibSettingsProvider(string path, SettingsScope scopes = SettingsScope.User, IEnumerable<string> keywords = null) : base(path, scopes, keywords)
  16. {
  17. var settingsAssetGuids = AssetDatabase.FindAssets("TriLibReaders");
  18. if (settingsAssetGuids.Length > 0)
  19. {
  20. _settingsFilePath = AssetDatabase.GUIDToAssetPath(settingsAssetGuids[0]);
  21. }
  22. else
  23. {
  24. throw new Exception("Could not find TriLibReaders.cs file. Please re-import TriLib package.");
  25. }
  26. }
  27. public override void OnGUI(string searchContext)
  28. {
  29. EditorGUILayout.Space();
  30. var contentWidth = GUILayoutUtility.GetLastRect().width * 0.5f;
  31. EditorGUIUtility.labelWidth = contentWidth;
  32. EditorGUIUtility.fieldWidth = contentWidth;
  33. GUILayout.BeginVertical(Styles.Group);
  34. GUILayout.Label("Runtime Importing", EditorStyles.boldLabel);
  35. GUILayout.Label("You can disable runtime file-formats importing here");
  36. EditorGUILayout.Space();
  37. ShowConditionalToggle("Disable runtime FBX importing", "TRILIB_DISABLE_FBX_IMPORT");
  38. ShowConditionalToggle("Disable runtime gLTF2 importing", "TRILIB_DISABLE_GLTF_IMPORT");
  39. ShowConditionalToggle("Disable runtime OBJ importing", "TRILIB_DISABLE_OBJ_IMPORT");
  40. ShowConditionalToggle("Disable runtime STL importing", "TRILIB_DISABLE_STL_IMPORT");
  41. ShowConditionalToggle("Disable runtime PLY importing", "TRILIB_DISABLE_PLY_IMPORT");
  42. ShowConditionalToggle("Disable runtime 3MF importing", "TRILIB_DISABLE_3MF_IMPORT");
  43. ShowConditionalToggle("Disable runtime DAE importing", "TRILIB_DISABLE_DAE_IMPORT");
  44. EditorGUILayout.Space();
  45. EditorGUILayout.Space();
  46. GUILayout.Label("Editor Importing", EditorStyles.boldLabel);
  47. EditorPrefs.SetInt("TriLibTimeout", EditorGUILayout.IntField("Loading timeout", EditorPrefs.GetInt("TriLibTimeout", 180)));
  48. GUILayout.Label("You can disable in editor file-formats importing to avoid conflicts with other editor importers");
  49. EditorGUILayout.Space();
  50. ShowConditionalToggle("Disable in editor gLTF2 importing", "TRILIB_DISABLE_EDITOR_GLTF_IMPORT");
  51. ShowConditionalToggle("Disable in editor PLY importing", "TRILIB_DISABLE_EDITOR_PLY_IMPORT");
  52. ShowConditionalToggle("Disable in editor 3MF importing", "TRILIB_DISABLE_EDITOR_3MF_IMPORT");
  53. ShowConditionalToggle("Disable in editor STL importing", "TRILIB_DISABLE_EDITOR_STL_IMPORT");
  54. EditorGUILayout.Space();
  55. EditorGUILayout.Space();
  56. GUILayout.Label("Material Mappers", EditorStyles.boldLabel);
  57. GUILayout.Label("Select the material mappers according to your project rendering pipeline");
  58. EditorGUILayout.Space();
  59. for (var i = 0; i < MaterialMapper.RegisteredMappers.Count; i++)
  60. {
  61. var materialMapperName = MaterialMapper.RegisteredMappers[i];
  62. var value = TriLibSettings.GetBool(materialMapperName);
  63. var newValue = EditorGUILayout.Toggle(materialMapperName, value);
  64. if (newValue != value)
  65. {
  66. TriLibSettings.SetBool(materialMapperName, newValue);
  67. }
  68. }
  69. EditorGUILayout.Space();
  70. EditorGUILayout.Space();
  71. GUILayout.Label("Misc Options", EditorStyles.boldLabel);
  72. GUILayout.Label("Advanced and experimental options");
  73. EditorGUILayout.Space();
  74. //todo: fbx sdk will be included in a future update
  75. //ShowConditionalToggle("Use FBX SDK (Experimental)", "TRILIB_USE_FBXSDK");
  76. ShowConditionalToggle("Enable UWP threaded loading (Experimental)", "TRILIB_ENABLE_UWP_THREADS");
  77. ShowConditionalToggle("Enable gLTF2 Draco decompression (Experimental)", "TRILIB_DRACO");
  78. ShowConditionalToggle("Force synchronous loading", "TRILIB_FORCE_SYNC");
  79. ShowConditionalToggle("Change thread names (Debug purposes only)", "TRILIB_USE_THREAD_NAMES");
  80. ShowConditionalToggle("Disable asset loader options validations", "TRILIB_DISABLE_VALIDATIONS");
  81. ShowConditionalToggle("Show advanced memory usage (Windows only)", "TRILIB_SHOW_MEMORY_USAGE");
  82. EditorGUILayout.Space();
  83. GUILayout.BeginHorizontal();
  84. GUILayout.FlexibleSpace();
  85. if (GUILayout.Button("Version Notes"))
  86. {
  87. TriLibVersionNotes.ShowWindow();
  88. }
  89. if (GUILayout.Button("API Reference"))
  90. {
  91. Application.OpenURL("https://ricardoreis.net/trilib/trilib2/docs/");
  92. }
  93. if (GUILayout.Button("Wiki"))
  94. {
  95. Application.OpenURL("https://web.archive.org/web/20221123174306/https://ricardoreis.net/trilibwiki/index.php/Main_Page");
  96. }
  97. if (GUILayout.Button("Support"))
  98. {
  99. Application.OpenURL("https://ricardoreis.net/contact/");
  100. }
  101. GUILayout.EndHorizontal();
  102. GUILayout.EndVertical();
  103. CheckMappers.Initialize();
  104. base.OnGUI(searchContext);
  105. }
  106. private void ShowConditionalToggle(string label, string symbol, Action<bool> onChange = null)
  107. {
  108. var currentValue = TriLibDefineSymbolsHelper.IsSymbolDefined(symbol);
  109. var newValue = EditorGUILayout.Toggle(label, currentValue);
  110. if (newValue != currentValue)
  111. {
  112. TriLibDefineSymbolsHelper.UpdateSymbol(symbol, newValue);
  113. onChange?.Invoke(newValue);
  114. }
  115. }
  116. [SettingsProvider]
  117. public static SettingsProvider TriLib()
  118. {
  119. var provider = new TriLibSettingsProvider("Project/TriLib", SettingsScope.Project)
  120. {
  121. keywords = GetSearchKeywordsFromGUIContentProperties<Styles>()
  122. };
  123. return provider;
  124. }
  125. }
  126. }