using UnityEngine;
using System.Collections;

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

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

	void Update () {
		Camera camera = GetComponent<Camera>();

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

		if (theme != null) { 
			Color color = theme.ColorFromColorIndex (colorIndex);
			if (camera.backgroundColor != color) {
				camera.backgroundColor = color;
			}
		}
	}
}
