using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
[RequireComponent(typeof(SpriteRenderer))]
public class ThemeColoredSprite : MonoBehaviour {
	public ThemeColoredSpriteManager theme;
	public ThemeColoredSpriteManager.ColorIndex colorIndex;
	SpriteRenderer spriteRenderer;

	void Reset () {
		if (theme == null) {
			theme = (ThemeColoredSpriteManager)FindObjectOfType (typeof(ThemeColoredSpriteManager));
		}
	}

	void Update () {
		if(spriteRenderer == null ) {
			spriteRenderer = GetComponent<SpriteRenderer> ();
		}

		if (theme == null) {
			theme = (ThemeColoredSpriteManager)FindObjectOfType (typeof(ThemeColoredSpriteManager));
		}

		Color color = theme.ColorFromColorIndex (colorIndex);
		spriteRenderer.color = color;
	}
}
