using UnityEngine;
using UnityEditor;
class MyPostprocessorTexture : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
TextureImporter importer = assetImporter as TextureImporter;
if (importer.textureType != TextureImporterType.Sprite ||
importer.spriteImportMode != SpriteImportMode.Single) {
importer.textureType = TextureImporterType.Sprite;
importer.spriteImportMode = SpriteImportMode.Single;
importer.SaveAndReimport();
return;
}
var sp = AssetDatabase.LoadAssetAtPath<Sprite>(assetPath);
if (sp)
{
GameObject go = new GameObject(sp.name);
go.AddComponent<SpriteRenderer>().sprite = sp;
Object prefab = PrefabUtility.CreateEmptyPrefab(string.Format("Assets/{0}.prefab", go.name));
if (prefab != null)
{
PrefabUtility.ReplacePrefab(go, prefab, ReplacePrefabOptions.ConnectToPrefab);
}
else
{
Debug.Log("Failed to create prefab.");
}
GameObject.DestroyImmediate(go);
}
}
}