/////////////////////////////////////////////////////////////////////////////////////////////////
// GF - System
// various system utilitary functions
/////////////////////////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using System.Collections;

public class GFSystem
{
	public static void Assert(bool condition, string error = "")
	{
		if (!condition) 
		{
			Debug.LogError(error);
			// throw new System.Exception();
		}
	} 
	
	public static Vector2 ScreenToUnit(Vector2 pos)
	{
		return new Vector2(pos.x / Screen.width, pos.y / Screen.height);
	}

    public static Vector2 WorldToCanvas(Vector3 pos)
    {
        pos = Camera.main.WorldToScreenPoint(pos);
        pos = ScreenToUnit(pos);
        return new Vector2((pos.x - 0.5f) * 1920f, (pos.y - 0.5f) * 1080f);
        
    }

    public static string FormatTime(float seconds)
	{
		int s = (int)seconds;
		int hours = s / (60 * 60);
		s -= hours * 60 * 60;
		int minutes = s / 60;
		s -= minutes * 60;
		return string.Format("{0:00}:{1:00}:{2:00}", hours, minutes, s);
	}

	// as defined by unity (shader)
	public const int RenderQueueBackground = 1000;
	public const int RenderQueueGeometry = 2000;
	public const int RenderQueueAlphaTest = 2450;
	public const int RenderQueueTransparent = 3000;
	public const int RenderQueueOverlay = 4000;
	public const int RenderQueueDefault = RenderQueueGeometry;

	// set the render queue value to object and children
	public static void SetRenderQueue(GameObject obj, int value)
	{
		var renderers = obj.GetComponentsInChildren<MeshRenderer>();
		foreach(var renderer in renderers) 
		{
			foreach(var mat in renderer.materials)
			{
				mat.renderQueue = value;
			}
		}
	}
}
