2using System.Collections.Generic;
4using System.Reflection;
15 public static readonly GUIStyle Group =
new GUIStyle { padding =
new RectOffset(10, 10, 5, 5) };
18 private const string ReadersFileTemplate =
"//Auto-generated: Do not modify this file!\n\nusing System.Collections;\nusing System.Collections.Generic;\n{0}\nnamespace TriLibCore\n{{\n public class Readers\n {{\n public static IList<string> Extensions\n {{\n get\n {{\n var extensions = new List<string>();{1}\n return extensions;\n }}\n }}\n public static ReaderBase FindReaderForExtension(string extension)\n {{\n\t\t\t{2}\n return null;\n }}\n }}\n}}";
20 private readonly List<ImporterOption> _importerOptions =
new List<ImporterOption>();
21 private readonly
string _readersFilePath;
23 public TriLibSettingsProvider(
string path, SettingsScope scopes = SettingsScope.User, IEnumerable<string> keywords =
null) : base(path, scopes, keywords)
25 var triLibReadersAssets = AssetDatabase.FindAssets(
"TriLibReaders");
26 if (triLibReadersAssets.Length > 0)
28 _readersFilePath = AssetDatabase.GUIDToAssetPath(triLibReadersAssets[0]);
32 throw new Exception(
"Could not find TriLibReaders.cs file. Please re-import TriLib package.");
34 _importerOptions.Clear();
35 var pluginImporters = PluginImporter.GetAllImporters();
36 foreach (var pluginImporter
in pluginImporters)
38 if (!pluginImporter.isNativePlugin && pluginImporter.assetPath.Contains(
"TriLibCore."))
40 var assembly = Assembly.LoadFile(pluginImporter.assetPath);
41 foreach (var type
in assembly.ExportedTypes)
43 if (type.BaseType == typeof(ReaderBase))
45 _importerOptions.Add(
new ImporterOption(type.Name, type.Namespace, pluginImporter));
52 public override void OnGUI(
string searchContext)
54 EditorGUILayout.Space();
55 var contentWidth = GUILayoutUtility.GetLastRect().width * 0.5f;
56 EditorGUIUtility.labelWidth = contentWidth;
57 EditorGUIUtility.fieldWidth = contentWidth;
58 GUILayout.BeginVertical(Styles.Group);
59 GUILayout.Label(
"Enabled Readers", EditorStyles.boldLabel);
60 GUILayout.Label(
"You can disable file formats you don't use here");
61 EditorGUILayout.Space();
63 foreach (var importerOption
in _importerOptions)
65 var value = importerOption.PluginImporter.GetCompatibleWithAnyPlatform();
66 var newValue = EditorGUILayout.Toggle(importerOption, value);
67 if (newValue != value)
69 importerOption.PluginImporter.SetCompatibleWithAnyPlatform(newValue);
76 string extensions =
null;
77 string findReader =
null;
78 foreach (var importerOption
in _importerOptions)
80 if (importerOption.PluginImporter.GetCompatibleWithAnyPlatform())
82 extensions += $
"\n\t\t\t\textensions.AddRange({importerOption.text}.GetExtensions());";
83 usings += $
"using {importerOption.Namespace};\n";
84 findReader += $
"\n\t\t\tif (((IList) {importerOption.text}.GetExtensions()).Contains(extension))\n\t\t\t{{\n\t\t\t\treturn new {importerOption.text}();\n\t\t\t}}";
87 var text =
string.Format(ReadersFileTemplate, usings, extensions, findReader);
88 var textAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(_readersFilePath);
89 File.WriteAllText(_readersFilePath, text);
90 EditorUtility.SetDirty(textAsset);
91 AssetDatabase.SaveAssets();
92 AssetDatabase.Refresh();
94 EditorGUILayout.Space();
95 GUILayout.Label(
"Material Mappers", EditorStyles.boldLabel);
96 GUILayout.Label(
"Select the Material Mappers according your project rendering pipeline");
97 EditorGUILayout.Space();
98 foreach (var materialMapperName
in MaterialMapper.RegisteredMappers)
101 var newValue = EditorGUILayout.Toggle(materialMapperName, value);
102 if (newValue != value)
107 CheckMappers.Initialize();
108 EditorGUILayout.Space();
109 GUILayout.Label(
"Misc Options", EditorStyles.boldLabel);
110 GUILayout.Label(
"Advanced Options");
111 EditorGUILayout.Space();
112 ShowConditionalToggle(
"Enable GLTF Draco Decompression (Experimental)",
"TRILIB_DRACO");
113 ShowConditionalToggle(
"Force synchronous loading",
"TRILIB_FORCE_SYNC");
114 ShowConditionalToggle(
"Change Thread names (Debug purposes only)",
"TRILIB_USE_THREAD_NAMES");
115 EditorGUILayout.Space();
116 GUILayout.BeginHorizontal();
117 GUILayout.FlexibleSpace();
118 if (GUILayout.Button(
"Version Notes"))
122 if (GUILayout.Button(
"API Reference"))
124 Application.OpenURL(
"https://ricardoreis.net/trilib/trilib2/docs/");
126 if (GUILayout.Button(
"Support"))
128 Application.OpenURL(
"mailto:contato@ricardoreis.net");
130 GUILayout.EndHorizontal();
131 GUILayout.EndVertical();
132 base.OnGUI(searchContext);
135 private void ShowConditionalToggle(
string label,
string symbol)
137 var currentValue = TriLibDefineSymbolsHelper.IsSymbolDefined(symbol);
138 var newValue = EditorGUILayout.Toggle(label, currentValue);
139 if (newValue != currentValue)
141 TriLibDefineSymbolsHelper.UpdateSymbol(symbol, newValue);
150 keywords = GetSearchKeywordsFromGUIContentProperties<Styles>()
static SettingsProvider Register()
TriLibSettingsProvider(string path, SettingsScope scopes=SettingsScope.User, IEnumerable< string > keywords=null)
override void OnGUI(string searchContext)
Represents the TriLib project settings provider. You can override this behavior to store the settings...
static void SetBool(string key, bool value)
static bool GetBool(string key)