2023-04-03 11:04:31 +08:00

76 lines
1.5 KiB
C#

using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace BF
{
public class SimpleAtlas : ScriptableObject
{
[SerializeField]
List<Sprite> spriteList = new List<Sprite>();
public bool AddSprite(Sprite sprite)
{
if (sprite == null)
{
return false;
}
spriteList.Add(sprite);
return true;
}
public void RemoveSprite(Sprite sprite)
{
if (sprite == null)
{
return;
}
spriteList.Remove(sprite);
}
public void RemoveNullSprite()
{
EnsureWithoutNull();
}
public bool Contains(Sprite sprite)
{
return spriteList.Contains(sprite);
}
public void Clear()
{
spriteList.Clear();
}
public int GetCount()
{
return spriteList.Count;
}
void EnsureWithoutNull()
{
int count = spriteList.Count;
for (int i = count - 1; i >= 0; i--)
{
if (spriteList[i] == null)
{
spriteList.RemoveAt(i);
}
}
}
public Sprite GetSprite(int index)
{
if (index >= 0 && index < spriteList.Count)
{
return spriteList[index];
}
return null;
}
public List<Sprite> GetSpriteList()
{
return spriteList;
}
}
}