DeletePoints.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. public class DeletePoints : MonoBehaviour
  6. {
  7. private GameObject deleteId;
  8. public GameObject masterConnector;
  9. // Start is called before the first frame update
  10. void Start()
  11. {
  12. deleteId = null;
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. }
  18. public void setDeleteVisible(GameObject delete_id) {
  19. this.deleteId = delete_id;
  20. GameObject parent = GameObject.Find("Canvas");
  21. Transform[] children = parent.GetComponentsInChildren<Transform>(true);
  22. foreach(Transform ch in children)
  23. {
  24. if(ch.gameObject.name == "DeleteButton")
  25. {
  26. ch.gameObject.SetActive(true);
  27. }
  28. }
  29. }
  30. public void setDeleteNonVisible() {
  31. this.deleteId = null;
  32. GameObject parent = GameObject.Find("Canvas");
  33. Transform[] children = parent.GetComponentsInChildren<Transform>(true);
  34. foreach(Transform ch in children)
  35. {
  36. if(ch.gameObject.name == "DeleteButton")
  37. {
  38. ch.gameObject.SetActive(false);
  39. }
  40. }
  41. }
  42. public void deletePoints()
  43. {
  44. if(deleteId == null)
  45. {
  46. return;
  47. }
  48. string gn = masterConnector.GetComponent<MasterCreateGame>().GetGameNumber();
  49. StartCoroutine(DeletePointsOnServer(gn));
  50. }
  51. public IEnumerator DeletePointsOnServer(string thisGame)
  52. {
  53. string serverUrl = "https://smarthubs.media.tuwien.ac.at/api/delete_object";
  54. string obj_id = deleteId.GetComponent<ObjectDropper>().objectId.ToString();
  55. // Create a Web Form
  56. WWWForm form = new WWWForm();
  57. form.AddField("game", thisGame);
  58. form.AddField("oid", obj_id);
  59. using (UnityWebRequest www = UnityWebRequest.Post(serverUrl, form))
  60. {
  61. yield return www.SendWebRequest();
  62. if (www.result != UnityWebRequest.Result.Success)
  63. {
  64. Debug.Log(www.error);
  65. // PROMPT ERROR
  66. //errorPanel.SetActive(true);
  67. }
  68. else
  69. {
  70. Debug.Log("Form upload complete!");
  71. }
  72. }
  73. }
  74. }