public void DoExport(GameObject targetObj) { string folderName = EditorUtility.OpenFolderPanel("Select mesh location", "Assets", ""); folderName = FileUtil.GetProjectRelativePath(folderName); if (string.IsNullOrEmpty(folderName)) { return; } string fontName = targetObj.name; string guid = AssetDatabase.CreateFolder(folderName, fontName); string newFolderPath = AssetDatabase.GUIDToAssetPath(guid); MText_Font newFont = ScriptableObject.CreateInstance <MText_Font>(); List <string> meshPaths = new List <string>(); Transform targetTrasnform = targetObj.transform; for (int i = 0; i < targetTrasnform.childCount; i++) { string savePath = newFolderPath + "/" + targetTrasnform.GetChild(i).gameObject.name + ".asset"; AssetDatabase.CreateAsset(targetTrasnform.GetChild(i).gameObject.GetComponent <MeshFilter>().sharedMesh, savePath); AssetDatabase.ImportAsset(savePath); meshPaths.Add(savePath); } EditorApplication.delayCall += () => AddCharacterToFont(newFont, meshPaths, fontName); }
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); }
public void CreateFontFile(string prefabPath, string fontName) { MText_Font newFont = ScriptableObject.CreateInstance <MText_Font>(); GameObject fontSet = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject; newFont.UpdateCharacterList(fontSet); string scriptableObjectSaveLocation = EditorUtility.SaveFilePanel("Save font location", "", fontName, "asset"); scriptableObjectSaveLocation = FileUtil.GetProjectRelativePath(scriptableObjectSaveLocation); AssetDatabase.CreateAsset(newFont, scriptableObjectSaveLocation); AssetDatabase.SaveAssets(); }
private void AddCharacterToFont(MText_Font newFont, List <string> meshPaths, string fontName) { string scriptableObjectSaveLocation = EditorUtility.SaveFilePanel("Save font location", "", fontName, "asset"); scriptableObjectSaveLocation = FileUtil.GetProjectRelativePath(scriptableObjectSaveLocation); for (int i = 0; i < meshPaths.Count; i++) { Mesh newAsset = (Mesh)AssetDatabase.LoadAssetAtPath(meshPaths[i], typeof(Mesh)); newFont.AddCharacter(newAsset); } AssetDatabase.CreateAsset(newFont, scriptableObjectSaveLocation); AssetDatabase.SaveAssets(); }
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(); }