-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNetworkCreationManager.cs
79 lines (66 loc) · 2.79 KB
/
NetworkCreationManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.SceneManagement;
using Photon.Voice.PUN;
using UnityEngine.Networking;
using UnityEngine.UI;
[System.Serializable]
public struct JsonResponse {
public string success, userID, message;
}
namespace Spaces {
public class NetworkCreationManager : MonoBehaviourPunCallbacks {
// Start is called before the first frame update
private bool connectToRoom = false;
public GameObject usernameInput;
public GameObject passwordInput;
public AvatarCreation Avatar;
public GameObject avatarGameObject;
void Awake() {
string myRoomID = PlayerPrefs.GetString("myRoomID");
Avatar = avatarGameObject.GetComponent<AvatarCreation>();
// if (myRoomID != "") {
// Debug.Log(myRoomID);
// Debug.Log("going to load main game");
// SceneManager.LoadScene("MainGame");
// }
}
public void OnClickConnectRoom() {
string currentSkin = Avatar.SelectedCharacter();
PlayerPrefs.SetString("CurrentSkin", currentSkin);
// following lines are test (uncomment)
SceneManager.LoadScene("MainGame");
// string username = usernameInput.GetComponent<Text>().text.Trim();
// string password = passwordInput.GetComponent<Text>().text.Trim();
// StartCoroutine(MakeRequest("create-account", username, password));
}
// static IEnumerator MakeRequest(string url, string username, string password) {
// WWWForm form = new WWWForm();
// form.AddField("username", username);
// form.AddField("password", password);
// UnityWebRequest www = UnityWebRequest.Post("https://circles-parellano.herokuapp.com/api/" + url, form);
// yield return www.SendWebRequest();
// if(www.isNetworkError || www.isHttpError) {
// Debug.Log(www.error);
// }
// else {
// string response = www.downloadHandler.text;
// yield return response;
// Debug.Log(response);
// JsonResponse data = JsonUtility.FromJson<JsonResponse>(response);
// if (data.success == "false") {
// Debug.Log(data.message);
// } else {
// string location = "365.285:0.499218:438.6511";
// PlayerPrefs.SetString("positionInWorld", location);
// PlayerPrefs.SetString("myRoomID", data.userID);
// PlayerPrefs.SetString("currentRoomID", data.userID);
// PlayerPrefs.SetString("username", username);
// SceneManager.LoadScene("MainGame");
// }
// }
// }
}
}