TextMeshProを使ったVCIをexe(runtime)実行で出力できない場合の対策


概要

VCIをexe(runtime)実行で出力するときに困ったことを共有します。

Version

Unity 2019.3.0f6
UniVCI-0.24

現象

TextMeshProを含むとexe(runtime)実行で出力できません。

原因

VCI.Exportから参照されるUniGLTF.ShaderPropExporter.ShaderPropsの中身にはUNITY_EDITORの記述があり、EditorはUnityEditor.ShaderUtilを使い、exe(runtime)ではUniVRMがそれ相当の実装を持つのですが、VRMはTextMeshProなど知らないので……、という予想です。

対策

無いなら作る。知らないなら教える。ということで、UniGLTF.ShaderPropExporter.PreShaderPropExporterにTextMeshPro/Distance Fieldをでっちあげます。ホントは中身があった方が良いと思いますが、無くても動いたので気にしないことにしました。

using System.Collections.Generic;


namespace UniGLTF.ShaderPropExporter
{
    public static partial class PreShaderPropExporter
    {
        [PreExportShader]
        static KeyValuePair<string, ShaderProps> TextMeshPro_Distance_Field
        {
            get
            {
                return new KeyValuePair<string, ShaderProps>(
                    "TextMeshPro/Distance Field",
                    new ShaderProps
                    {
                        Properties = new ShaderProperty[]{}
                    }
                );
            }
        }
    }
}

たぶん何処にどんな名前で保存しても良いと思うのですが、私は以下へ保存しました。
.\Assets\VRM\ShaderProperty\Runtime\TextMeshPro_Distance_Field.cs