42 lines
930 B
C#
42 lines
930 B
C#
using UnityEngine;
|
|
|
|
public interface IUnitSpriteBinder
|
|
{
|
|
string SpritePath { get; }
|
|
}
|
|
|
|
public class UnitSpriteController : MonoBehaviour
|
|
{
|
|
private IUnitSpriteBinder unitView;
|
|
|
|
private SpriteRenderer spriteRenderer;
|
|
|
|
private string currentSpritePath;
|
|
|
|
private void Awake() // TODO: 빌드시점으로 옮길수 있으면 좋음
|
|
{
|
|
spriteRenderer = GetComponentInChildren<SpriteRenderer>();
|
|
currentSpritePath = null;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
unitView = GetComponentInParent<IUnitSpriteBinder>();
|
|
Update();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (currentSpritePath != unitView.SpritePath)
|
|
{
|
|
currentSpritePath = unitView.SpritePath;
|
|
spriteRenderer.sprite = SLResources.GetSprite(currentSpritePath);
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
unitView = null;
|
|
currentSpritePath = null;
|
|
}
|
|
} |