#pragma strict

//============================================================================
//// Enumerations /////
enum ENUM_Difficulty {DIFF_EASY, DIFF_NORMAL, DIFF_HARD, DIFF_NIGHTMARE};
enum ENUM_Alert {ALERT_NORMAL, ALERT_FOUND, ALERT_SEARCHING}

//============================================================================
//// Variables ////
static var consoleEnabled : boolean;

// Game data
static var version : String = "0.01";

// Game mode related things
static var mainMenu : boolean;
static var difficulty : ENUM_Difficulty;

// Instances
static var Player : GameObject;

// In-Game stuff
static var inventory : boolean;
static var alertState : ENUM_Alert;

// Cheats/Console booleans
static var Godmode : boolean;
static var Noclip : boolean;

// Private variables
private static var _staticRectTexture : Texture2D;
private static var _staticRectStyle : GUIStyle;

static function FindPlayer()
{
	var gos : GameObject[];
	gos = GameObject.FindGameObjectsWithTag("Player");
	for (var go : GameObject in gos) 
	{
		if (!Agent.Player)
		{ Agent.Player = go; }
	}
}

static function PlayClipAt(clip : AudioClip, pos : Vector3)
{
	Agent.PlayClipAt(clip, pos, 0);
}

static function PlayClipAt(clip : AudioClip, pos : Vector3, spacBl : float)
{
	var tempGO = GameObject("TempAudio");
	
	if (clip != null)
	{
		tempGO.transform.position = pos;
		var aSource = tempGO.AddComponent(AudioSource);
		aSource.clip = clip;
		//aSource.spatialBlend = spacBl;
		aSource.pitch = Random.Range(0.90, 1.10); //untune

		aSource.Play();
		Destroy(tempGO, clip.length);
	}
	else
	{ Destroy(tempGO, 1); }
	
	return tempGO;
}

static function ClampAngle(angle : float, min : float, max : float)
{
    if (angle < -360) { angle += 360; }
    if (angle > 360) { angle -= 360; }
    return Mathf.Clamp (angle, min, max);
}
 
// Note that this function is only meant to be called from OnGUI() functions.
static function GUIDrawRect( pos : Rect, color : Color )
{
    if( _staticRectTexture == null )
    { _staticRectTexture = new Texture2D( 1, 1 ); }

    if( _staticRectStyle == null )
    { _staticRectStyle = new GUIStyle(); }

    _staticRectTexture.SetPixel( 0, 0, color );
    _staticRectTexture.Apply();

    _staticRectStyle.normal.background = _staticRectTexture;

    GUI.Box( pos, GUIContent.none, _staticRectStyle );
}