Skip to content

Commit

Permalink
add description, move plugin toggle to the left
Browse files Browse the repository at this point in the history
  • Loading branch information
hybridherbst committed Dec 29, 2023
1 parent 595b5f1 commit 437d176
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions Runtime/Scripts/Extensions/MaterialExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public override GltfExportPluginContext CreateInstance(ExportContext context)
}

public override string DisplayName => "Material Extensions";
public override string Description => "Exports various glTF PBR Material model extensions.";
}

public class MaterialExtensions: GltfExportPluginContext
Expand Down
28 changes: 14 additions & 14 deletions Runtime/Scripts/Extensions/TextMeshExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@
using GLTF.Schema;
using UnityEngine;
using UnityGLTF.Extensions;
using UnityGLTF.Plugins;

namespace UnityGLTF
{
public static class TextMeshExport
public class TextMeshExport : GltfExportPlugin
{
#if UNITY_EDITOR
[UnityEditor.InitializeOnLoadMethod]
#else
[RuntimeInitializeOnLoadMethod]
#endif
static void Init()
public override string DisplayName => "TextMeshPro Export as Mesh";
public override string Description => "Bakes 3D TextMeshPro objects (not UI/Canvas) into meshes and attempts to faithfully apply their shader settings to generate the font texture.";
public override GltfExportPluginContext CreateInstance(ExportContext context)
{
GLTFSceneExporter.BeforeMaterialExport += BeforeMaterialExport;
GLTFSceneExporter.AfterSceneExport += CleanUpRenderTextureCache;
return new TextMeshExportContext();
}

private static void CleanUpRenderTextureCache(GLTFSceneExporter _, GLTFRoot __)
}

public class TextMeshExportContext: GltfExportPluginContext
{
public override void AfterSceneExport(GLTFSceneExporter _, GLTFRoot __)
{
if (rtCache == null) return;
foreach (var kvp in rtCache)
kvp.Value.Release();
rtCache.Clear();
}

private static Material tempMat;
private static Dictionary<Texture, RenderTexture> rtCache;
private Material tempMat;
private Dictionary<Texture, RenderTexture> rtCache;

private static bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode)
public override bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode)
{
if (material.shader.name.Contains("TextMeshPro")) // seems to only work for TextMeshPro/Mobile/ right now (SDFAA_HINTED?)
{
Expand Down
9 changes: 5 additions & 4 deletions Runtime/Scripts/GLTFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,24 @@ internal static void OnPluginsGUI(IEnumerable<GltfPlugin> plugins)
var expanded = SessionState.GetBool(key, false);
using (new GUILayout.HorizontalScope())
{
var label = new GUIContent(displayName);
plugin.Enabled = GUILayout.Toggle(plugin.Enabled, "", GUILayout.Width(12));
var label = new GUIContent(displayName, plugin.Description);
var expanded2 = EditorGUILayout.Foldout(expanded, label);
if (expanded2 != expanded)
{
expanded = expanded2;
SessionState.SetBool(key, expanded2);
}
plugin.Enabled = GUILayout.Toggle(plugin.Enabled, "", GUILayout.Width(20));
}
if (expanded)
{
EditorGUI.indentLevel++;
EditorGUI.indentLevel += 2;
EditorGUILayout.HelpBox(plugin.Description, MessageType.None);
editorCache.TryGetValue(plugin.GetType(), out var editor);
Editor.CreateCachedEditor(plugin, null, ref editor);
editorCache[plugin.GetType()] = editor;
editor.OnInspectorGUI();
EditorGUI.indentLevel--;
EditorGUI.indentLevel -= 2;
}
EditorGUILayout.EndFoldoutHeaderGroup();
}
Expand Down
2 changes: 2 additions & 0 deletions Runtime/Scripts/Plugins/GltfPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace UnityGLTF.Plugins
public abstract class GltfPlugin: ScriptableObject
{
public abstract string DisplayName { get; }
public abstract string Description { get; }
public virtual string HelpUrl => "";
public bool Enabled { get; set; } = true;
}
}

0 comments on commit 437d176

Please sign in to comment.