﻿using UnityEngine;
using System.Collections;

public class CursorMovement : MonoBehaviour {
	public Texture2D cursorTex;
	public GameObject ObjectAcceptInputs;
    public InputFlow InputFlowScript;

	/// <summary>
	/// The cursor in original game.
	/// </summary>
	public Transform oldCursor;
	void Awake () {

	  if(GameObject.Find("GameObject").ToString() != null){
			ObjectAcceptInputs = GameObject.Find("GameObject");
			InputFlowScript = ObjectAcceptInputs.GetComponent<InputFlow>();
	  }
    }
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
	void OnGUI(){
	  if(InputFlowScript.showMenu){  // when the customised GUI menu is active
		 
		if(Screen.showCursor){
				/*disable the cusor in the original game*/
				oldCursor.gameObject.SetActive(false);
				Screen.showCursor = false; //disable the system cursor
		}
		GUI.depth = 0;
		/*render the "fake" cursor*/
		GUI.DrawTexture(new Rect(InputFlowScript.serverCurrentMousePos.x-9,Screen.height - InputFlowScript.serverCurrentMousePos.y + 9,18,18), cursorTex);
	  }
	    else{
			if(!Screen.showCursor){
				/*enable the cusor in the original game*/
				oldCursor.gameObject.SetActive(true);
				Screen.showCursor = true; //enable the system cursor
			}

		}
	}
}
