using System; using System.Linq; using UnityEditor; using UnityEngine;
public static class SpriteUtility
{
public static byte GetSpriteIndex(Sprite sp)
{
if (sp)
{
string spriteSheet = AssetDatabase.GetAssetPath(sp.texture);
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(spriteSheet)
.OfType<Sprite>().ToArray();
int index = Array.FindIndex(sprites, s => s.name == sp.name);
return (byte)index;
}
else
{
return 0;
}
}
}
沒有留言:
張貼留言