using UnityEngine;
using System.Collections;

public class CameraManager : MonoBehaviour {
	GameObject goOldCamera, goNewCamera;
	public GameObject[] goaInitialCameras, goaPreCurveCameras, goaCurveCameras, goaTensionCameras, goaDecisionCameras, goaHitMissTrioCameras, goaPostMortemCameras, goaCurrentCameras;
	public GameObject[][] goaaCameraSets;
	public float fTimeCurrent;
	public float fTimeSwap;
	public int iRandomCamera, iLastRandomCamera;

	// Use this for initialization
	void Start () {
		goaaCameraSets = new GameObject[7][];
		goaCurrentCameras = goaInitialCameras;
		goaaCameraSets[0] = goaInitialCameras;
		goaaCameraSets[1] = goaPreCurveCameras;
		goaaCameraSets[2] = goaCurveCameras;
		goaaCameraSets[3] = goaTensionCameras;
		goaaCameraSets[4] = goaDecisionCameras;
		goaaCameraSets[5] = goaHitMissTrioCameras;
		goaaCameraSets[6] = goaPostMortemCameras;
	}
	// Update is called once per frame
	void Update () 
	{
		fTimeCurrent -= Time.unscaledDeltaTime;
		if (fTimeCurrent <= 0) 
		{
			if(goaCurrentCameras.Length>1){
				do
				{
					iRandomCamera = Random.Range(0, goaCurrentCameras.Length);
				}while (iLastRandomCamera == iRandomCamera);
			}else
			{
				iRandomCamera = 0;
			}
			iLastRandomCamera = iRandomCamera;
			ChangeCurrentCamera(goaCurrentCameras[iRandomCamera]);
			fTimeCurrent = fTimeSwap;
		}
	}
	public void ChangeCurrentCamera(GameObject goNewCamera) 
	{
		goOldCamera = Camera.main.gameObject;
		//		goAudioSource = goOldCamera.GetComponentInChildren<AudioSource>().gameObject;
		//		goAudioSource.transform.position = goNewCamera.transform.position;
		//		goAudioSource.transform.parent = null;
		goOldCamera.SetActive(false);
		goNewCamera.SetActive(true);
		//		goAudioSource.transform.parent = goNewCamera.transform;
	}
	public void ChangeCameraSet(int iNewCameraSet) 
	{
//		goaCurrentCameras = new GameObject[goaNewCameraSet.Length];
		goaCurrentCameras = goaaCameraSets[iNewCameraSet];
	}
	public void ChangeTimeSwapCameras(float fNewTime)
	{
		fTimeSwap = fNewTime;
		fTimeCurrent = fTimeSwap;
	}
}
