FadeFX.cs 1.77 KB
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class FadeFX : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler {

	private BoxCollider COMPONENT_COLLIDER;
	public GameObject update_box;
	//Cria referência para o colider do avatar e torna a barra transparente
	public void Start()
	{

		COMPONENT_COLLIDER = GameObject.FindGameObjectWithTag("avatar").GetComponent<BoxCollider>();
		Deactivate();

	}

	//Listeners de eventos do mouse
	public void OnPointerEnter(PointerEventData eventData){ Activate(); }
	public void OnPointerExit(PointerEventData eventData){ Deactivate(); }

	/*
	 *	Desabilita o colider do avatar para bloquear a rotação
	 *	Em seguida retorna o visual padrão da barra de controles
	 *	e reativa a interação com os botões
	 */
	private void Activate()
	{

		COMPONENT_COLLIDER.enabled = false;

		foreach(GameObject GO in GameObject.FindGameObjectsWithTag("FADENEEDED"))
			GO.GetComponent<CanvasRenderer>().SetAlpha(1f);

		foreach(GameObject GO in GameObject.FindGameObjectsWithTag("BUTTONS"))
			GO.GetComponent<Button>().interactable = true;

	}

	/*
	 *	Habilita o colider do avatar para desbloquear a rotação
	 *	Em seguida diminui o alpha dos componentes da barra de controles tornando-os transparentes
	 *	Logo após desativa a interação com os botões para impedir que fiquem em status "highlighted"
	 */
	private void Deactivate(){

		if(!SwitchResolution.showbox && !update_box.activeSelf){

			COMPONENT_COLLIDER.enabled = true;

			foreach(GameObject GO in GameObject.FindGameObjectsWithTag("FADENEEDED"))
				GO.GetComponent<CanvasRenderer>().SetAlpha(.2f);

			foreach(GameObject GO in GameObject.FindGameObjectsWithTag("BUTTONS"))
				GO.GetComponent<Button>().interactable = false;

		}

	}

}