WinterJamSnowman/Assets/Scripts/LemonGenericLib/Visual Effects/SpriteFrameSetter.cs

59 lines
1.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace Lemon.GenericLib.VFX
{
public class SpriteFrameSetter : MonoBehaviour
{
private SpriteRenderer sr;
[SerializeField] private SpriteFrame[] spriteFrames;
private void Start()
{
sr = GetComponent<SpriteRenderer>();
}
public void SetFrame(string spriteName)
{
foreach (var item in spriteFrames)
{
if (item.spriteName == spriteName)
{
sr.sprite = item.sprite;
return;
}
}
Debug.LogError("Sprite frame requiested is not available.\nPlease check the spelling error");
}
public void SetFrame(int index)
{
if (index >= 0 && index < spriteFrames.Length)
{
sr.sprite = spriteFrames[index].sprite;
return;
}
Debug.LogError($"Sprite frame requiested {index} is not available.\nPlease check the spelling error");
}
[Serializable]
private class SpriteFrame
{
public string spriteName;
public Sprite sprite;
}
}
}