using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class AvatarController : MonoBehaviour {

	public enum HairType {
		None,
		Hair1,
		Hair2,
		Hair3,
		Hair4,
		Hair5,
		Hair6,
		Hair7
	}

	public enum ClothType {
		None,
		Tie,
		Tuxedo,
		Pants,
		Shirts,
		PantsAndShirts,
	}

	public HairType hair;
	public ClothType cloth;

	private HairType currentHair;
	private ClothType currentCloth;

	public bool wrinkleHead;
	public bool wrinkleFace;
	public bool glass;
	public bool redFace;
	public bool smileFace;

	public GameObject[] hairs;
	public GameObject wrinkleHeadObj;
	public GameObject wrinkleFaceObj;
	public GameObject glassObj;
	public GameObject redFaceObj;
	public GameObject smileFaceObj;
	public GameObject tuxido;
	public GameObject tie;
	public GameObject pants;
	public GameObject shirts;

	private void _DoClothChange() {
		if( hair != currentHair ) {
			foreach(GameObject h in hairs) {
				h.SetActive(false);
			}
			if(hair != HairType.None) {
				hairs[ ((int)hair-1) ].SetActive(true);
			}
			currentHair = hair;
		}
		if( cloth != currentCloth ) {
			tuxido.SetActive(false);
			tie.SetActive(false);
			pants.SetActive(false);
			shirts.SetActive(false);

			switch(cloth) {
			case ClothType.Tie:
				tie.SetActive(true);
				break;
			case ClothType.Tuxedo:
				tie.SetActive(true);
				tuxido.SetActive(true);
				break;
			case ClothType.Pants:
				pants.SetActive(true);
				break;
			case ClothType.Shirts:
				shirts.SetActive(true);
				break;
			case ClothType.PantsAndShirts:
				pants.SetActive(true);
				shirts.SetActive(true);
				break;
			}

			currentCloth = cloth;
		}

		wrinkleFaceObj.SetActive(wrinkleFace);
		wrinkleHeadObj.SetActive(wrinkleHead);
		glassObj.SetActive(glass);
		redFaceObj.SetActive(redFace);
		smileFaceObj.SetActive(smileFace);
	}

	// Use this for initialization
//	void Reset () {
//		_DoClothChange();	
//	}
//
//	void Start () {
//		_DoClothChange();	
//	}
	
	// Update is called once per frame
	void Update () {
		_DoClothChange();
	}
}
