天津23维预案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

35 lines
1.3 KiB

using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class MakeSpritePrafebs : MonoBehaviour {
[MenuItem("MyMenu/AtlasMaker")]
static private void MakeAtlas()
{
string spriteDir = Application.dataPath + "/Resources/UIPrefab/Equipment";
if (!Directory.Exists(spriteDir))
{
Directory.CreateDirectory(spriteDir);
}
DirectoryInfo rootDirInfo = new DirectoryInfo(Application.dataPath + "/Atlas");
foreach (DirectoryInfo dirInfo in rootDirInfo.GetDirectories())
{
foreach (FileInfo pngFile in dirInfo.GetFiles("*.png", SearchOption.AllDirectories))
{
string allPath = pngFile.FullName;
string assetPath = allPath.Substring(allPath.IndexOf("Assets"));
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
GameObject go = new GameObject(sprite.name);
go.AddComponent<SpriteRenderer>().sprite = sprite;
allPath = spriteDir + "/" + sprite.name + ".prefab";
string prefabPath = allPath.Substring(allPath.IndexOf("Assets"));
PrefabUtility.CreatePrefab(prefabPath, go);
GameObject.DestroyImmediate(go);
}
}
}
}