GameInfoScript.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class GameInfoScript : MonoBehaviour {
  7. public Button cancelButton;
  8. public Button acceptButton;
  9. public GameObject playerInfoPrefab;
  10. public Transform playersPanel;
  11. public Transform gameSettingsPanel;
  12. // Start is called before the first frame update
  13. void Start() {
  14. cancelButton.onClick.AddListener(Hide);
  15. }
  16. // Update is called once per frame
  17. void Update() {
  18. }
  19. internal void SetOnlineData(OnlineGameScript onlineGameScript) {
  20. String currentPlayer = Database.Instance.GetSignedInUser().Value;
  21. foreach (KeyValuePair<string, string> player in onlineGameScript.PlayerInfos) {
  22. GameObject slp = Instantiate(playerInfoPrefab, new Vector2(0, 0), Quaternion.identity) as GameObject;
  23. OnlinePlayerInfoScript opi = slp.GetComponent<OnlinePlayerInfoScript>();
  24. opi.GameId = onlineGameScript.GetId();
  25. opi.SetPlayerName(player.Key);
  26. if (currentPlayer.Equals(player.Key) && player.Value.Equals("WAITING")) {
  27. opi.ShowDecitionButtons();
  28. } else {
  29. opi.SetPlayerStatus(player.Value);
  30. }
  31. opi.transform.SetParent(playersPanel, false);
  32. }
  33. acceptButton.enabled = false;
  34. acceptButton.interactable = false;
  35. if ("YOUR_TURN".Equals(onlineGameScript.GameStatus)) {
  36. acceptButton.enabled = true;
  37. acceptButton.interactable = true;
  38. }
  39. }
  40. public void Show() {
  41. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  42. cg.alpha = 1;
  43. cg.interactable = true;
  44. cg.blocksRaycasts = true;
  45. }
  46. public void Hide() {
  47. CanvasGroup cg = this.GetComponent<CanvasGroup>();
  48. cg.alpha = 0;
  49. cg.interactable = false;
  50. cg.blocksRaycasts = false;
  51. foreach (OnlinePlayerInfoScript opis in playersPanel.GetComponentsInChildren<OnlinePlayerInfoScript>()) {
  52. Destroy(opis);
  53. Destroy(opis.gameObject);
  54. }
  55. GameObject.Find("Main Panel").GetComponent<MainMenu>().UpdateOnlineGamesLists();
  56. }
  57. }