// =========================================================== // Static Methods // =========================================================== public static void CreateFont() { string saveFolder = "Assets"; if (Selection.activeObject != null) { string assetPath = AssetDatabase.GetAssetPath(Selection.activeObject); if (!string.IsNullOrEmpty(assetPath)) { saveFolder = System.IO.Path.GetDirectoryName(assetPath); } } var assetPathAndName = EditorUtility.SaveFilePanel("Save Font", saveFolder, "New Font", "prefab"); if (string.IsNullOrEmpty(assetPathAndName)) { return; } var go = new GameObject(); go.AddComponent <MadFont>(); assetPathAndName = MadPath.MakeRelative(assetPathAndName); var prefab = PrefabUtility.CreatePrefab(assetPathAndName, go); GameObject.DestroyImmediate(go); Selection.activeObject = prefab; }
public static MadAtlas CreateAtlas(Texture2D[] textures) { var modified = MakeReadable(textures); try { var saveFolder = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(textures[0])); var prefabPath = EditorUtility.SaveFilePanel("Save atlas", saveFolder, "New Texture Atlas", "prefab"); if (string.IsNullOrEmpty(prefabPath)) { return(null); } prefabPath = MadPath.MakeRelative(prefabPath); var texturePath = System.IO.Path.ChangeExtension(prefabPath, "png"); List <MadAtlas.Item> items = new List <MadAtlas.Item>(); PackTextures(textures, texturePath, ref items); var go = new GameObject() { name = System.IO.Path.GetFileNameWithoutExtension(prefabPath) }; var atlas = go.AddComponent <MadAtlas>(); atlas.atlasTexture = AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D)) as Texture2D; atlas.AddItemRange(items); var prefab = PrefabUtility.CreateEmptyPrefab(prefabPath); prefab.name = atlas.name; var prefabGo = PrefabUtility.ReplacePrefab(go, prefab); DestroyImmediate(go); AssetDatabase.Refresh(); return(prefabGo.GetComponent <MadAtlas>()); } finally { RevertReadable(modified); AssetDatabase.Refresh(); } }