| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.UI;
- public class GameInfoScript : MonoBehaviour {
- public Button cancelButton;
- public Button acceptButton;
- public GameObject playerInfoPrefab;
- public Transform playersPanel;
- public Transform gameSettingsPanel;
- private int gameId;
- private int questionTimer;
- private int winNumber;
- [SerializeField] Text answerTimeValueText;
- [SerializeField] Text questionsToWinValueText;
- [SerializeField] Text DaysToStartRoundValueText;
- // Start is called before the first frame update
- void Start() {
- cancelButton.onClick.AddListener(Hide);
- acceptButton.onClick.AddListener(OpenGame);
- }
- // Update is called once per frame
- void Update() {
- }
- internal void SetOnlineData(OnlineGameScript onlineGameScript) {
- String currentPlayer = Database.Instance.GetSignedInUser().Value;
- gameId = onlineGameScript.GetId();
- questionTimer = onlineGameScript.AnswerTimer;
- winNumber = onlineGameScript.WinNumber;
- answerTimeValueText.text = onlineGameScript.AnswerTimer.ToString();
- questionsToWinValueText.text = onlineGameScript.WinNumber.ToString();
- DaysToStartRoundValueText.text = onlineGameScript.RoundTimeLimit.ToString();
- foreach (KeyValuePair<string, string> player in onlineGameScript.PlayerInfos) {
- GameObject slp = Instantiate(playerInfoPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
- OnlinePlayerInfoScript opi = slp.GetComponent<OnlinePlayerInfoScript>();
- opi.GameId = gameId;
- opi.SetPlayerName(player.Key);
- if (currentPlayer.Equals(player.Key, StringComparison.InvariantCultureIgnoreCase) && player.Value.Equals("WAITING")) {
- opi.ShowDecitionButtons();
- } else {
- opi.SetPlayerStatus(player.Value);
- }
- opi.transform.SetParent(playersPanel, false);
- }
- acceptButton.enabled = false;
- acceptButton.interactable = false;
- if (onlineGameScript.GameStatus.Equals("ACTIVE")) {
- acceptButton.enabled = true;
- acceptButton.interactable = true;
- }
- }
- private void OpenGame() {
- PlayerPrefs.SetString("GameMode", "Online");
- PlayerPrefs.SetInt("GameId", gameId);
- PlayerPrefs.SetInt("QuestionTimer", questionTimer);
- PlayerPrefs.SetInt("NeededForWin", winNumber);
- SceneManager.LoadSceneAsync("narKampen");
- }
- public void Show() {
- CanvasGroup cg = this.GetComponent<CanvasGroup>();
- cg.alpha = 1;
- cg.interactable = true;
- cg.blocksRaycasts = true;
- }
- public void Hide() {
- CanvasGroup cg = this.GetComponent<CanvasGroup>();
- cg.alpha = 0;
- cg.interactable = false;
- cg.blocksRaycasts = false;
- foreach (OnlinePlayerInfoScript opis in playersPanel.GetComponentsInChildren<OnlinePlayerInfoScript>()) {
- Destroy(opis);
- Destroy(opis.gameObject);
- }
- GameObject.Find("Main Panel").GetComponent<MainMenu>().UpdateOnlineGamesLists();
- }
- }
|