private MText_Font GetKerning(MText_FontCreator fontCreator, MText_Font newFont) { fontCreator.GetKerningInfo(out List <ushort> lefts, out List <ushort> rights, out List <short> offsets); for (int i = 0; i < lefts.Count; i++) { newFont.kernTable.Add(new MText_KernPairHolder(new MText_KernPair(lefts[i], rights[i]), offsets[i])); } return(newFont); }
private void CreateFont() { GameObject gameObject = new GameObject(); bool exportAsObj = ExportAs(); List <char> listOfChar = GetCharacterList(); MText_FontCreator fontCreator = new MText_FontCreator(); fontCreator.CreateFont(gameObject, listOfChar, settings.sizeXY, settings.sizeZ, settings.vertexDensity, settings.smoothingAngle, settings.defaultTextMaterial, exportAsObj); //if (!fontCreator.WasEverythingProcessed()) //{ // //EditorUtility.DisplayDialog("") //} EditorUtility.DisplayProgressBar("Creating font", "Mesh creation started", 75 / 100); if (gameObject.transform.childCount > 0) { if (exportAsObj) { MText_ObjExporter objExporter = new MText_ObjExporter(); string prefabPath = objExporter.DoExport(gameObject, true); if (string.IsNullOrEmpty(prefabPath)) { Debug.Log("Object save failed"); EditorUtility.ClearProgressBar(); return; } MText_FontExporter fontExporter = new MText_FontExporter(); fontExporter.CreateFontFile(prefabPath, gameObject.name); } else { MText_MeshAssetExporter meshAssetExporter = new MText_MeshAssetExporter(); meshAssetExporter.DoExport(gameObject); } } EditorUtility.ClearProgressBar(); if (Application.isPlaying) { Destroy(gameObject); } else { DestroyImmediate(gameObject); } }
public void CreateFontFile(string prefabPath, string fontName, MText_FontCreator fontCreator) { MText_Font newFont = ScriptableObject.CreateInstance <MText_Font>(); GameObject fontSet = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; newFont.UpdateCharacterList(fontSet); for (int i = 0; i < newFont.characters.Count; i++) { newFont.characters[i].glyphIndex = fontCreator.Index(newFont.characters[i].character); } if (fontCreator.KerningSupported()) { newFont = GetKerning(fontCreator, newFont); } string scriptableObjectSaveLocation = EditorUtility.SaveFilePanel("Save font location", "", fontName, "asset"); scriptableObjectSaveLocation = FileUtil.GetProjectRelativePath(scriptableObjectSaveLocation); AssetDatabase.CreateAsset(newFont, scriptableObjectSaveLocation); AssetDatabase.SaveAssets(); }