Пример #1
0
        public void OnPreprocessBuild(BuildReport report)
        {
            var    waitingMappers = false;
            string materialMapper = null;
            var    arguments      = Environment.GetCommandLineArgs();

            foreach (var argument in arguments)
            {
                if (waitingMappers)
                {
                    materialMapper = argument;
                    continue;
                }
                switch (argument)
                {
                case "-trilib_mappers":
                {
                    waitingMappers = true;
                    break;
                }
                }
            }
            if (materialMapper != null)
            {
                Debug.Log($"Using the given material mapper:{materialMapper}.");
                CheckMappers.SelectMapper(materialMapper);
            }
            else
            {
                CheckMappers.Initialize();
            }
        }
        public override void OnGUI(string searchContext)
        {
            EditorGUILayout.Space();
            var contentWidth = GUILayoutUtility.GetLastRect().width * 0.5f;

            EditorGUIUtility.labelWidth = contentWidth;
            EditorGUIUtility.fieldWidth = contentWidth;
            GUILayout.BeginVertical(Styles.Group);
            GUILayout.Label("Enabled Readers", EditorStyles.boldLabel);
            GUILayout.Label("You can disable file formats you don't use here");
            EditorGUILayout.Space();
            var changed = false;

            foreach (var importerOption in _importerOptions)
            {
                var value    = importerOption.PluginImporter.GetCompatibleWithAnyPlatform();
                var newValue = EditorGUILayout.Toggle(importerOption, value);
                if (newValue != value)
                {
                    importerOption.PluginImporter.SetCompatibleWithAnyPlatform(newValue);
                    changed = true;
                }
            }
            if (changed)
            {
                string usings     = null;
                string extensions = null;
                string findReader = null;
                foreach (var importerOption in _importerOptions)
                {
                    if (importerOption.PluginImporter.GetCompatibleWithAnyPlatform())
                    {
                        extensions += $"\n\t\t\t\textensions.AddRange({importerOption.text}.GetExtensions());";
                        usings     += $"using {importerOption.Namespace};\n";
                        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}}";
                    }
                }
                var text      = string.Format(ReadersFileTemplate, usings, extensions, findReader);
                var textAsset = AssetDatabase.LoadAssetAtPath <TextAsset>(_settingsFilePath);
                File.WriteAllText(_settingsFilePath, text);
                EditorUtility.SetDirty(textAsset);
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }
            EditorGUILayout.Space();
            GUILayout.Label("Material Mappers", EditorStyles.boldLabel);
            GUILayout.Label("Select the Material Mappers according your project rendering pipeline");
            EditorGUILayout.Space();
            foreach (var materialMapperName in MaterialMapper.RegisteredMappers)
            {
                var value    = TriLibSettings.GetBool(materialMapperName);
                var newValue = EditorGUILayout.Toggle(materialMapperName, value);
                if (newValue != value)
                {
                    TriLibSettings.SetBool(materialMapperName, newValue);
                }
            }
            CheckMappers.Initialize();
            EditorGUILayout.Space();
            GUILayout.Label("Misc Options", EditorStyles.boldLabel);
            GUILayout.Label("Advanced Options");
            EditorGUILayout.Space();
            ShowConditionalToggle("Enable GLTF Draco Decompression (Experimental)", "TRILIB_DRACO");
            ShowConditionalToggle("Force synchronous loading", "TRILIB_FORCE_SYNC");
            ShowConditionalToggle("Change Thread names (Debug purposes only)", "TRILIB_USE_THREAD_NAMES");
            ShowConditionalToggle("Use Unity internal image loader instead of stb_image (Experimental)", "TRILIB_USE_UNITY_TEXTURE_LOADER");
            EditorGUILayout.Space();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Version Notes"))
            {
                TriLibVersionNotes.ShowWindow();
            }
            if (GUILayout.Button("API Reference"))
            {
                Application.OpenURL("https://ricardoreis.net/trilib/trilib2/docs/");
            }
            if (GUILayout.Button("Support"))
            {
                Application.OpenURL("mailto:[email protected]");
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            base.OnGUI(searchContext);
        }