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

59 lines
1.3 KiB
C#
Raw Normal View History

2023-01-24 13:51:46 +00:00
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;
}
}
}