123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using System.Linq;
- public class CurrentGameConnect : MonoBehaviour
- {
- private string currentGameNumber;
- public GameObject errorPanel;
- public GameObject connectingPanel;
- public GameObject numberInput;
- public GameObject selectionPanel;
- public GameObject nextPanel;
-
- // Start is called before the first frame update
- void Start()
- {
- currentGameNumber = "0";
- GameObject parent = GameObject.Find("Canvas");
-
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- public void checkIfGameExistsAndNotFinished()
- {
- string gameNumber = numberInput.GetComponent<InputField>().text;
- // SEND THE REQUEST TO SERVER
- // CHECK IF GAME NUMBERS EXISTS
- string serverUrl_check = "https://smarthubs.media.tuwien.ac.at/api/is_game_closed/" + gameNumber;
- connectingPanel.SetActive(true);
- StartCoroutine(CheckGame(serverUrl_check, gameNumber));
- //CHECK IF IT IS NOT FINISHED
- // IF NOT
- //currentGameNumber = GameNumber;
- // ELSE ERROR WINDOW POP-UP
- //onnectionError.SetActive(true);
- }
- public IEnumerator CheckGame(string serverUrl, string gameNumber)
- {
- UnityWebRequest www = UnityWebRequest.Get(serverUrl);
- yield return www.SendWebRequest();
- if (www.result != UnityWebRequest.Result.Success)
- {
- Debug.Log(www.error);
- connectingPanel.SetActive(false);
- errorPanel.SetActive(true);
- }
- else
- {
- // Show results as text
- //Debug.Log(www.downloadHandler.text);
- string is_game_closed = www.downloadHandler.text;
- Debug.Log(is_game_closed );
- // DSISPLAY GAME NUMBER
- // this.gameDisplayNumber.text = next_game_id;
- if(is_game_closed == "False")
- {
- connectingPanel.SetActive(false);
- currentGameNumber = gameNumber;
- selectionPanel.SetActive(false);
- nextPanel.SetActive(true);
- }
- else
- {
- connectingPanel.SetActive(false);
- errorPanel.SetActive(true);
- }
- }
- }
- public string GetGameNumber()
- {
- return this.currentGameNumber;
- }
- }
|