Hey all,
I am attempting to make a font editable via scripting. I am aware that I can click on the gear icon and choose to create an editable copy, but I would like to achieve the same via editor scripting.
Docs in question are at: http://docs.unity3d.com/Documentation/ScriptReference/TrueTypeFontImporter.GenerateEditableFont.html
My code:
using UnityEngine;
using UnityEditor;
using System;
using System.IO;
public class FontManager : ScriptableObject {
TextureImporter textureImporter = new TextureImporter();
[MenuItem ("Assets/Make Editable Font")]
static void FontManager()
{
System.Object Fonts = new System.Object();
Fonts = Resources.Load("Fonts/nokia", typeof(Font));
Font font = (Font)Fonts;
string path = AssetDatabase.GetAssetPath(font);
Debug.Log("Generating copy of: " + path);
TrueTypeFontImporter fontImporter = AssetImporter.GetAtPath(path) as TrueTypeFontImporter;
fontImporter.GenerateEditableFont(Application.dataPath + "/Resources/Fonts/nokia_copy");
}}
But when I attempt to run the code I get the error:
Could not get texture importer
UnityEditor.TrueTypeFontImporter:GenerateEditableFont(String)
Which is completely useless. For the record, my font is in “Assets/Resources/Fonts/nokia.ttf”. Has anyone managed to get this function to work?
Thanks!