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(); currentSpritePath = null; } private void OnEnable() { unitView = GetComponentInParent(); Update(); } private void Update() { if (currentSpritePath != unitView.SpritePath) { currentSpritePath = unitView.SpritePath; spriteRenderer.sprite = SLResources.GetSprite(currentSpritePath); } } private void OnDisable() { unitView = null; currentSpritePath = null; } }