hz-unity-tmp-resources

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

TextMesh Pro Resources Import

TextMesh Pro 资源导入

When to use this skill

何时使用此技能

Use this skill automatically when any of the following are detected:
  • TMP text appears pink/magenta in the scene
  • Console errors mentioning
    LiberationSans SDF
    ,
    TMP Settings
    , or missing TMP materials
  • Creating the first TMP text element in a project
  • User asks to set up TextMesh Pro or create UI text
  • Assets/TextMesh Pro/Resources/
    folder does not exist
当检测到以下任意一种情况时,可自动使用此技能:
  • 场景中的TMP文本显示为粉色/品红色
  • 控制台出现提及
    LiberationSans SDF
    、
    TMP Settings
    或缺失TMP材质的错误
  • 在项目中创建第一个TMP文本元素
  • 用户要求搭建TextMesh Pro或创建UI文本
  • Assets/TextMesh Pro/Resources/
    文件夹不存在

Step 1: Check if TMP resources are already imported

步骤1:检查TMP资源是否已导入

Before importing, check whether resources already exist using
Unity_RunCommand
:
csharp
using UnityEngine;
using UnityEditor;
using System.IO;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        string resourcesPath = Path.Combine(Application.dataPath, "TextMesh Pro", "Resources");
        bool imported = Directory.Exists(resourcesPath);

        if (imported)
        {
            string fontPath = "Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset";
            var font = AssetDatabase.LoadAssetAtPath<Object>(fontPath);
            result.Log("TMP Essential Resources: ALREADY IMPORTED. Default font present: {0}", font != null);
        }
        else
        {
            result.Log("TMP Essential Resources: NOT IMPORTED. Resources folder missing at {0}", resourcesPath);
        }
    }
}
If already imported, stop here — no action needed.
导入前,使用
Unity_RunCommand
检查资源是否已存在:
csharp
using UnityEngine;
using UnityEditor;
using System.IO;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        string resourcesPath = Path.Combine(Application.dataPath, "TextMesh Pro", "Resources");
        bool imported = Directory.Exists(resourcesPath);

        if (imported)
        {
            string fontPath = "Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset";
            var font = AssetDatabase.LoadAssetAtPath<Object>(fontPath);
            result.Log("TMP Essential Resources: ALREADY IMPORTED. Default font present: {0}", font != null);
        }
        else
        {
            result.Log("TMP Essential Resources: NOT IMPORTED. Resources folder missing at {0}", resourcesPath);
        }
    }
}
如果已导入,到此为止——无需执行其他操作。

Step 2: Import TMP Essential Resources

步骤2:导入TMP基础资源

IMPORTANT: The TMP import process opens a Unity dialog that requires manual user interaction. This cannot be fully automated via MCP.
Use
Unity_RunCommand
to trigger the import dialog:
csharp
using UnityEngine;
using UnityEditor;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        EditorApplication.ExecuteMenuItem("Window/TextMeshPro/Import TMP Essential Resources");
        result.Log("TMP Essential Resources import dialog opened. User must click Import in the Unity Editor.");
    }
}
After executing, you MUST:
  1. Tell the user: "The Import Unity Package dialog has opened in Unity. Please click the Import button, then let me know when it's done."
  2. Wait for the user to confirm before proceeding.
  3. Do NOT assume import succeeded without confirmation.
重要提示:TMP导入过程会打开一个Unity对话框,需要用户手动交互。无法通过MCP完全自动化此过程。
使用
Unity_RunCommand
触发导入对话框:
csharp
using UnityEngine;
using UnityEditor;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        EditorApplication.ExecuteMenuItem("Window/TextMeshPro/Import TMP Essential Resources");
        result.Log("TMP Essential Resources import dialog opened. User must click Import in the Unity Editor.");
    }
}
执行后,必须:
  1. 告知用户:"Unity中已打开「导入Unity包」对话框。请点击导入按钮,完成后告知我。"
  2. 等待用户确认后再继续。
  3. 未得到确认前,请勿默认导入已成功。

Step 3: Verify import succeeded

步骤3:验证导入是否成功

After the user confirms, verify with
Unity_RunCommand
:
csharp
using UnityEngine;
using UnityEditor;
using System.IO;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        string resourcesPath = Path.Combine(Application.dataPath, "TextMesh Pro", "Resources");
        if (!Directory.Exists(resourcesPath))
        {
            result.LogError("Import failed: Resources folder not found at " + resourcesPath);
            return;
        }

        string fontPath = "Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset";
        var font = AssetDatabase.LoadAssetAtPath<Object>(fontPath);
        if (font == null)
        {
            result.LogError("Import incomplete: Default font asset not found at " + fontPath);
            return;
        }

        var settingsGuids = AssetDatabase.FindAssets("t:TMP_Settings");
        if (settingsGuids.Length == 0)
        {
            result.LogError("Import incomplete: TMP_Settings asset not found.");
            return;
        }

        result.Log("TMP Essential Resources verified: folder exists, default font present, TMP_Settings found.");
    }
}
用户确认后,使用
Unity_RunCommand
进行验证:
csharp
using UnityEngine;
using UnityEditor;
using System.IO;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        string resourcesPath = Path.Combine(Application.dataPath, "TextMesh Pro", "Resources");
        if (!Directory.Exists(resourcesPath))
        {
            result.LogError("Import failed: Resources folder not found at " + resourcesPath);
            return;
        }

        string fontPath = "Assets/TextMesh Pro/Resources/Fonts & Materials/LiberationSans SDF.asset";
        var font = AssetDatabase.LoadAssetAtPath<Object>(fontPath);
        if (font == null)
        {
            result.LogError("Import incomplete: Default font asset not found at " + fontPath);
            return;
        }

        var settingsGuids = AssetDatabase.FindAssets("t:TMP_Settings");
        if (settingsGuids.Length == 0)
        {
            result.LogError("Import incomplete: TMP_Settings asset not found.");
            return;
        }

        result.Log("TMP Essential Resources verified: folder exists, default font present, TMP_Settings found.");
    }
}

Troubleshooting

故障排查

Pink/magenta text after import

导入后文本仍显示粉色/品红色

If text still appears pink after importing resources, force a shader recompilation via
Unity_RunCommand
:
csharp
using UnityEngine;
using UnityEditor;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        var shaderGuids = AssetDatabase.FindAssets("t:Shader TextMeshPro");
        int reimported = 0;
        foreach (var guid in shaderGuids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            reimported++;
        }
        result.Log("Reimported {0} TMP shaders.", reimported);
    }
}
如果导入资源后文本仍显示粉色,通过
Unity_RunCommand
强制重新编译着色器:
csharp
using UnityEngine;
using UnityEditor;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        var shaderGuids = AssetDatabase.FindAssets("t:Shader TextMeshPro");
        int reimported = 0;
        foreach (var guid in shaderGuids)
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
            reimported++;
        }
        result.Log("Reimported {0} TMP shaders.", reimported);
    }
}

Menu item grayed out or missing

菜单项变灰或缺失

If
Window/TextMeshPro/Import TMP Essential Resources
is not available:
  • Resources may already be imported — run Step 1 to check.
  • TMP package may not be installed. Install it via
    Unity_RunCommand
    :
csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.PackageManager;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        var request = Client.Add("com.unity.textmeshpro");
        // Busy-wait is required here because Unity_RunCommand scripts run synchronously.
        // This will briefly block the editor (typically < 5 seconds).
        while (!request.IsCompleted) { }

        if (request.Status == StatusCode.Success)
            result.Log("TextMesh Pro package installed: {0}", request.Result.version);
        else
            result.LogError("Failed to install TMP: " + request.Error.message);
    }
}
如果
Window/TextMeshPro/Import TMP Essential Resources
不可用:
  • 资源可能已导入——执行步骤1进行检查。
  • TMP包可能未安装。通过
    Unity_RunCommand
    安装:
csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.PackageManager;

internal class CommandScript : IRunCommand
{
    public void Execute(ExecutionResult result)
    {
        var request = Client.Add("com.unity.textmeshpro");
        // Busy-wait is required here because Unity_RunCommand scripts run synchronously.
        // This will briefly block the editor (typically < 5 seconds).
        while (!request.IsCompleted) { }

        if (request.Status == StatusCode.Success)
            result.Log("TextMesh Pro package installed: {0}", request.Result.version);
        else
            result.LogError("Failed to install TMP: " + request.Error.message);
    }
}

Integration with meta-quest-ui skill

与meta-quest-ui技能的集成

This skill handles importing TMP resources. For VR-specific UI configuration (canvas setup, text sizing, viewing distances), use the meta-quest-ui skill after TMP resources are imported.
此技能负责导入TMP资源。如需VR专属UI配置(画布设置、文本尺寸、可视距离),请在导入TMP资源后使用meta-quest-ui技能。