IEnumerator iCreateAccount() { WWW www; WWWForm wForm; www = new WWW(url + "/checkUser/" + username); yield return(www); if (www.error == null) { bool exists = bool.Parse(www.text); if (!exists) { wForm = new WWWForm(); wForm.AddField("username", username); wForm.AddField("password", password); changeToPlayMenu(); yield return(new WWW(url + "/createAccount", wForm)); } else { StartingUI error = thisUI.startUI.GetComponent <StartingUI>(); error.error.text = "An account with the username " + username + " exists, please choose a different username to continue"; } } else { Debug.LogError("ERROR: " + www.error); ConnectionError(www.error); } }
IEnumerator iLogin() { WWW www; WWWForm wForm; www = new WWW(url + "/checkUser/" + username); yield return(www); if (www.error == null) { bool exists = bool.Parse(www.text); if (exists) { wForm = new WWWForm(); wForm.AddField("username", username); wForm.AddField("password", password); www = new WWW(url + "/login", wForm); yield return(www); if (www.error == null) { string level; www.responseHeaders.TryGetValue("token", out Persistent.thisPersist.Token); www.responseHeaders.TryGetValue("level", out level); Persistent.thisPersist.Level = int.Parse(level); Persistent.thisPersist.Username = username; bool logged = bool.Parse(www.text); if (logged) { changeToPlayMenu(); Debug.Log("Logged In"); } else { StartingUI error = thisUI.startUI.GetComponent <StartingUI>(); error.error.text = "Wrong Password"; } } else { Debug.LogError("ERROR: " + www.error); ConnectionError(www.error); } } else { StartingUI error = thisUI.startUI.GetComponent <StartingUI>(); error.error.text = "An account with the username " + username + " does not exist"; } } else { Debug.LogError("ERROR: " + www.error); ConnectionError(www.error); } }
//COROUTINES IEnumerator RoundStarting() { while (currentstate == GAME_STATE.STARTING) { StartingUI.SetActive(true); //CombatUI.SetActive(false); SearchingForPlaneUI.SetActive(false); Touch touch = Input.GetTouch(0); if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { yield break; } else { // Raycast against the location the player touched to search for planes. TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && !placeModel) { var StageInstance = Instantiate(StagePrefab, hit.Pose.position, hit.Pose.rotation); var anchor = hit.Trackable.CreateAnchor(hit.Pose); if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None) { Vector3 cameraPositionSameY = FirstPersonCamera.transform.position; cameraPositionSameY.y = hit.Pose.position.y; StageInstance.transform.LookAt(cameraPositionSameY, StageInstance.transform.up); placeModel = true; } StageInstance.transform.parent = anchor.transform; StartingUI.SetActive(true); yield return(new WaitForSeconds(3)); StartCoroutine(SpawnPlayers()); if (allPlayersSpawned.Value == true) { StartingUI.SetActive(false); CurrentState = GAME_STATE.PLAYING; yield break; } } yield return(null); } } }
IEnumerator RoundPlaying() { while (currentstate == GAME_STATE.PLAYING) { SearchingForPlaneUI.SetActive(false); StartingUI.SetActive(false); PlayingUI.SetActive(true); QuitUI.SetActive(false); yield return(null); } }
IEnumerator RoundIdle() { while (currentstate == GAME_STATE.IDLE) { StatusUI.text = "Idle"; SearchingForPlaneUI.SetActive(false); StartingUI.SetActive(false); PlayingUI.SetActive(false); QuitUI.SetActive(false); yield return(null); } }
//COROUTINES IEnumerator RoundStarting() { while (currentstate == GAME_STATE.STARTING) { StartingUI.SetActive(true); StatusUI.text = "Starting"; if (Input.GetKey(KeyCode.Escape)) { Application.Quit(); } _QuitOnConnectionErrors(); // Check that motion tracking is tracking. if (Session.Status != SessionStatus.Tracking) { const int lostTrackingSleepTimeout = 15; Screen.sleepTimeout = lostTrackingSleepTimeout; if (!m_IsQuitting && Session.Status.IsValid()) { SearchingForPlaneUI.SetActive(true); } yield break; } Screen.sleepTimeout = SleepTimeout.NeverSleep; // Iterate over planes found in this frame and instantiate corresponding GameObjects to visualize them. Session.GetTrackables <TrackedPlane>(m_NewPlanes, TrackableQueryFilter.New); for (int i = 0; i < m_NewPlanes.Count; i++) { // Instantiate a plane visualization prefab and set it to track the new plane. The transform is set to // the origin with an identity rotation since the mesh for our prefab is updated in Unity World // coordinates. GameObject planePrefab = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity, transform); planePrefab.GetComponent <TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]); } // Disable the ARUI when no planes are valid. Session.GetTrackables <TrackedPlane>(m_AllPlanes); bool showSearchingUI = true; for (int i = 0; i < m_AllPlanes.Count; i++) { if (m_AllPlanes[i].TrackingState == TrackingState.Tracking) { showSearchingUI = false; break; } } SearchingForPlaneUI.SetActive(showSearchingUI); //Touch touch = Input.GetTouch(0); if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began) { yield break; } // Raycast against the location the player touched to search for planes. TrackableHit hit; TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinPolygon | TrackableHitFlags.FeaturePointWithSurfaceNormal; if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit) && !placeModel) { var StageInstance = Instantiate(StagePrefab, hit.Pose.position, hit.Pose.rotation); var anchor = hit.Trackable.CreateAnchor(hit.Pose); if ((hit.Flags & TrackableHitFlags.PlaneWithinPolygon) != TrackableHitFlags.None) { Vector3 cameraPositionSameY = FirstPersonCamera.transform.position; cameraPositionSameY.y = hit.Pose.position.y; StageInstance.transform.LookAt(cameraPositionSameY, StageInstance.transform.up); placeModel = true; } StageInstance.transform.parent = anchor.transform; //yield return new WaitForSeconds(3); //StartCoroutine(SpawnPlayers()); //if (allPlayersSpawned.Value == true) { //yield return new WaitForSeconds(3); CurrentState = GAME_STATE.PLAYING; yield break; //} } yield return(null); } }