using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SystemGame : Singleton<SystemGame> 
{
	[System.Serializable]
	class OceanParticle
	{
		public GameObject m_prefab = null;
		public MinMaxRange m_frequency = new MinMaxRange(1.0f,2.0f);	
	}

	[SerializeField] Camera m_gameCamera = null;

	[SerializeField] float m_windSpeed = 100;
	[SerializeField] float m_windAngle = -35;
	
	
	[SerializeField] List<OceanParticle> m_particles = new List<OceanParticle>();
		
	Vector2 m_windVelocity = Vector2.zero;
	
	public static float GetWindSpeed() { return Get.m_windSpeed; }
	public static float GetWindAngle() { return Get.m_windAngle; }
	public static Vector2 GetWindVelocity() { return Get.m_windVelocity; }
	public static Camera GetGameCamera() { return Get.m_gameCamera; }
	
	
	// Use this for initialization
	void Start () 
	{
		m_windVelocity = Quaternion.Euler(0,0,m_windAngle) * new Vector2(m_windSpeed, 0);
	
	}
	
	// Update is called once per frame
	void Update () 
	{	
		m_windVelocity = Quaternion.Euler(0,0,m_windAngle) * new Vector2(m_windSpeed, 0);
	
		// Generate particles

		foreach ( OceanParticle particle in m_particles )
		{
			if (  SystemTime.TimePassed( particle.m_frequency ) && particle.m_prefab != null )
			{
				GameObject obj = GameObject.Instantiate( particle.m_prefab, (Vector2) m_gameCamera.ViewportToWorldPoint(  new Vector2(Random.Range(-1.0f,2.0f), Random.Range(-1.0f,2.0f))), Quaternion.identity ) as GameObject;
				obj.transform.parent = transform;
				particle.m_frequency.Randomise();
			}
		}
	}
}


