Select Git revision
MasterButtonHandler.cs
-
PET Computação authoredPET Computação authored
MasterButtonHandler.cs 2.97 KiB
/**************************************************/
/* Script porco desenvolvido pela porca da Letícia
/* com ajuda do não-porco do Leandro
/* Feito para uso do PET Computação
/* para o projeto JAPA
/* Esse script tem como função principal cuidar
/* da renderização dos botões
/**************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MasterButtonHandler : MonoBehaviour {
[SerializeField] private GameObject[] buttons;
[SerializeField] private RectTransform[] transfButtons; // armazenar o objeto posiçaõ de cada botão
[SerializeField] private Vector3[] posButtons; // armazenar as possíveis posições de botões
private Vector3 auxV3; // valor para auxiliar o shuffle
private int randRange;
// Use this for initialization
// No start aproveitamos para pegar as posições dos botões (mantendo a responsividade)
// Inicia também o gameObject pra conseguirmos no shuffle mudar de posição
void Start () {
if (PlayerPrefs.GetInt("dificuldade") == 3)
randRange = 6;
else
randRange = 4;
// botão alegria
buttons[0] = transform.Find("Alegria").gameObject;
transfButtons[0] = buttons[0].GetComponent<RectTransform>();
posButtons[0] = transfButtons[0].anchoredPosition;
// botão medo
buttons[1] = transform.Find("Medo").gameObject;
transfButtons[1] = buttons[1].GetComponent<RectTransform>();
posButtons[1] = transfButtons[1].anchoredPosition;
// botão tristeza
buttons[2] = transform.Find("Tristeza").gameObject;
transfButtons[2] = buttons[2].GetComponent<RectTransform>();
posButtons[2] = transfButtons[2].anchoredPosition;
// botão raiva
buttons[3] = transform.Find("Raiva").gameObject;
transfButtons[3] = buttons[3].GetComponent<RectTransform>();
posButtons[3] = transfButtons[3].anchoredPosition;
// botão surpresa
buttons[4] = transform.Find("Surpresa").gameObject;
transfButtons[4] = buttons[4].GetComponent<RectTransform>();
posButtons[4] = transfButtons[4].anchoredPosition;
// se não estamos jogando no difícil não queremos esse botão
if (PlayerPrefs.GetInt("dificuldade") != 3)
buttons[4].SetActive(false);
// botão nojo
buttons[5] = transform.Find("Nojo").gameObject;
transfButtons[5] = buttons[5].GetComponent<RectTransform>();
posButtons[5] = transfButtons[5].anchoredPosition;
// se não estamos jogando no difícil não queremos esse botão
if (PlayerPrefs.GetInt("dificuldade") != 3)
buttons[5].SetActive(false);
Shuffle();
}
// função para trocar a posição dos vetores, a aleatorização é com repetição de posição
// essa função eu basicamente tirei do stack overflow, mas funciona que é uma beleza :D
public void Shuffle ()
{
int i;
for (i = 0; i < randRange; i++)
{
int rnd = Random.Range(0, randRange);
auxV3 = posButtons[rnd];
posButtons[rnd] = posButtons[i];
posButtons[i] = auxV3;
}
for (i = 0; i < randRange; i++)
transfButtons[i].anchoredPosition = posButtons[i];
}
}