public static IEnumerator createEggForSelf(GameObject eggMenuItemPrefab, Transform eggMenuContentPanel, int imageIndex, string eggName = "") { if (SpatialClient2.single.isLoggedIn()) { List <SpatialMarker> markersAround = new List <SpatialMarker>(); CoroutineResponse markerResponse = new CoroutineResponse(); yield return(SpatialClient2.single.GetMarkersByDistance(Input.location.lastData.longitude, Input.location.lastData.latitude, UserMetadata.KAIJU_MARKER_RADIUS, true, markersAround, markerResponse)); // assign the hexadecimal representation of the egg creation number as custom part of id Debug.Log("hell yeah"); List <HatchLocationMarker> markersToTake = new List <HatchLocationMarker>(); List <GenericLocation> genericLocationsToTake = new List <GenericLocation>(); yield return(SpatialClient2.single.getLocationsForEgg(SpatialClient2.single.randomLocationFromMarkers(markersAround), markersToTake, genericLocationsToTake)); OwnedEgg egg = new OwnedEgg(imageIndex, SpatialClient2.single.newEggIdForSelf(), new LocationCombination(markersToTake, genericLocationsToTake), eggName, SpatialClient2.single.randomKaijuFromMarkers(markersAround)); yield return(egg.initializeSprite(new CoroutineResponse())); // sprite should already be there since we are coming from the egg screen, but just checking GameObject eggMenuItem = GameObject.Instantiate(eggMenuItemPrefab); eggMenuItem.transform.SetParent(eggMenuContentPanel, false); eggMenuItem.GetComponent <OwnEggMenuItem>().Egg = egg; // also updates the egg menu item's view MainMenuScript.addNewEggToCheckinnables(egg); yield return(SpatialClient2.single.addEggToSelf(egg)); Debug.Log("egg created"); } else { Debug.Log("tried to create egg while not logged in"); } }
public IEnumerator register(string username, string password) { CoroutineResponse response = new CoroutineResponse(); response.reset(); yield return(SpatialClient2.single.CreateUser(response, username, password)); switch (response.Success) { case true: justRegisteredUsername = _registerCanvas.transform.FindChild("UserNameField").GetComponent <InputField>().text; _loginCanvas.enabled = true; _loginCanvas.transform.Find("RegisterSucceedText").gameObject.SetActive(true); _registerCanvas.enabled = false; break; case false: // wrong credentials _registerCanvas.transform.Find("UserExistText").gameObject.SetActive(true); Debug.Log("User Exist"); break; case null: // connection error (possible timeout) _connectionErrorText.enabled = true; Debug.Log("Connection Error"); break; } }
public IEnumerator checkAndDownloadEggSprite(int index, CoroutineResponse response) { response.reset(); while (_eggDownloadingIndex == index) { yield return(null); // this image is currently being downloaded } if (_eggSprites.ContainsKey(index)) { response.setSuccess(true); yield break; } _eggDownloadingIndex = index; WWW www = new WWW(eggSpriteAtIndex(index)); yield return(www); if (string.IsNullOrEmpty(www.error)) { _eggSprites[index] = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0.5f, 0.5f)); response.setSuccess(true); } else { Debug.Log("egg error: " + www.error + "index: " + index.ToString()); MessageController.single.displayError(null, "Failed to load egg image.\n" + SpatialClient2.CHECK_YOUR_INTERNET_CONNECTION); response.setSuccess(false); } _eggDownloadingIndex = NO_DOWNLOAD; }
public IEnumerator addDestoryCityReward(int amount, CoroutineResponse winCoroutineEnded) { // START OF EMRE'S CODE yield return(SpatialClient2.single.updateLastRampageWithMultiplier(amount, currentMarkerId)); //mainMenuCamera.GetComponent<MainMenuScript>().addCheckedLocation(); winCoroutineEnded.setSuccess(true); // END OF EMRE'S CODE }
/********************************** * * Initialization * * ********************************/ void Start() { initSystem(); initLevel(); winCoroutineEnded = new CoroutineResponse(); smesh = gameObject.AddComponent <AudioSource> (); smesh.clip = smeshAudio; smesh.playOnAwake = false; scream = gameObject.AddComponent <AudioSource> (); scream.playOnAwake = false; }
public IEnumerator initialize(int handSpriteIndex, int headSpriteIndex, int bodySpriteIndex, CoroutineResponse response) { response.reset(); CoroutineResponse handResponse = new CoroutineResponse(); CoroutineResponse bodyResponse = new CoroutineResponse(); CoroutineResponse headResponse = new CoroutineResponse(); StartCoroutine(checkAndDownloadBodySprite(bodySpriteIndex, bodyResponse)); StartCoroutine(checkAndDownloadHandSprite(handSpriteIndex, handResponse)); StartCoroutine(checkAndDownloadHeadSprite(headSpriteIndex, headResponse)); while (handResponse.Success == null || bodyResponse.Success == null || headResponse.Success == null) { yield return(null); } response.setSuccess(true); }
private IEnumerator addFriend() { MessageController.single.displayWaitScreen(_friendsCanvas); CoroutineResponse addFriendSuccess = new CoroutineResponse(); yield return(SpatialClient2.single.AddFriend(_userSearchResult.Id, addFriendSuccess)); if (addFriendSuccess.Success == true) { yield return(SpatialClient2.single.GetFriends(true)); refreshFriendButtons(); //_addFriendButton.enabled = false; _userNotFoundText.enabled = false; _userFoundText.enabled = false; _addFriendSucceedText.enabled = true; _enterYourFriendsUsernameText.enabled = true; _userSearchResult = null; //_friendSearchCanvas.enabled = false; } MessageController.single.closeWaitScreen(false); }
// assigns true to result.value if location service is ready, otherwise assigns false IEnumerator checkLocationService(CoroutineResponse result) { // make sure result's success value is null before beginning result.reset(); // base code from https://docs.unity3d.com/ScriptReference/LocationService.Start.html // Wait until service initializes int maxWait = LOCATION_INITIALIZED_QUERY_TIMEOUT * LOCATION_INITIALIZED_QUERIES_PER_SECOND; float timeBetweenQueries = 1.0f / LOCATION_INITIALIZED_QUERIES_PER_SECOND; while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0) { yield return(new WaitForSeconds(timeBetweenQueries)); maxWait--; } if (maxWait > 0) { // false if location service disabled, null if timed out, true otherwise result.setSuccess(!(Input.location.status == LocationServiceStatus.Failed)); } }
public static IEnumerator createEggForFriend(FriendData friend, int imageIndex, string eggName = "") { if (SpatialClient2.single.isLoggedIn()) { List <SpatialMarker> markersAround = new List <SpatialMarker>(); CoroutineResponse markerResponse = new CoroutineResponse(); yield return(SpatialClient2.single.GetMarkersByDistance(Input.location.lastData.longitude, Input.location.lastData.latitude, UserMetadata.KAIJU_MARKER_RADIUS, true, markersAround, markerResponse)); List <HatchLocationMarker> markersToTake = new List <HatchLocationMarker>(); List <GenericLocation> genericLocationsToTake = new List <GenericLocation>(); yield return(SpatialClient2.single.getLocationsForEgg(SpatialClient2.single.randomLocationFromMarkers(markersAround), markersToTake, genericLocationsToTake)); OwnedEgg egg = new OwnedEgg(imageIndex, SpatialClient2.single.newEggIdForFriend(friend), new LocationCombination(markersToTake, genericLocationsToTake), eggName, SpatialClient2.single.randomKaijuFromMarkers(markersAround)); yield return(egg.initializeSprite(new CoroutineResponse())); // sprite should already be there since we are coming from the egg screen, but just checking MainMenuScript.addNewEggToCheckinnables(egg); yield return(SpatialClient2.single.addOrUpdateEggInFriendsEggs(egg)); } else { Debug.Log("tried to create egg while not logged in"); } }
public IEnumerator initializeSprites(CoroutineResponse response) { yield return(KaijuDatabase.instance.initialize(_handType, _headType, _bodyType, response)); }
public void initializeCheckinDataStructures() { int pos = 111; Debug.Log(pos); foreach (GenericEggMenuItem item in Enumerable.Concat <GenericEggMenuItem>(_eggMenuContentPanel.GetComponentsInChildren <OwnEggMenuItem>(), _friendEggMenuContentPanel.GetComponentsInChildren <FriendEggMenuItem>())) { pos++; Debug.Log(pos); if (!item.Egg.Hatchable) { item.Egg.initializeCheckInnables(); } } pos = 211; Debug.Log(pos); _markersByDistance = new List <SpatialMarker>(); _idMarkers = new Dictionary <string, Dictionary <OwnedEgg, HatchLocationMarker> >(); idMarkers = _idMarkers; _spatialResponse = new CoroutineResponse(); _placeTypes = new Dictionary <GenericLocation.GooglePlacesType, Dictionary <OwnedEgg, HashSet <GenericLocation> > >(); placeTypes = _placeTypes; _googleResponses = new Dictionary <GenericLocation.GooglePlacesType, CoroutineResponse>(); _googleMarkers = new Dictionary <GenericLocation.GooglePlacesType, List <BasicMarker> >(); foreach (GenericEggMenuItem item in Enumerable.Concat <GenericEggMenuItem>(_eggMenuContentPanel.GetComponentsInChildren <OwnEggMenuItem>(), _friendEggMenuContentPanel.GetComponentsInChildren <FriendEggMenuItem>())) { pos++; Debug.Log(pos); if (!item.Egg.Hatchable) { foreach (GenericLocation loc in item.Egg.GenericLocationsToTake) { if (loc.needToBeVisited()) { if (!_placeTypes.ContainsKey(loc.LocationType)) { _placeTypes[loc.LocationType] = new Dictionary <OwnedEgg, HashSet <GenericLocation> >(); } if (!_placeTypes[loc.LocationType].ContainsKey(item.Egg)) { _placeTypes[loc.LocationType][item.Egg] = new HashSet <GenericLocation>(); } _placeTypes[loc.LocationType][item.Egg].Add(loc); } } foreach (HatchLocationMarker hlm in item.Egg.MarkersToTake) { if (hlm.needToBeVisited()) { if (!_idMarkers.ContainsKey(hlm.Id)) { _idMarkers[hlm.Id] = new Dictionary <OwnedEgg, HatchLocationMarker>(); } _idMarkers[hlm.Id][item.Egg] = hlm; } } } } pos = 311; Debug.Log(pos); foreach (GenericLocation.GooglePlacesType type in _placeTypes.Keys) { _googleResponses[type] = new CoroutineResponse(); _googleMarkers[type] = new List <BasicMarker>(); } }
public IEnumerator submit() { MessageController.single.displayWaitScreen(_loginCanvas); // start location tracking Debug.Log("GPS ON: " + Input.location.isEnabledByUser); Input.location.Start(); CoroutineResponse response = new CoroutineResponse(); yield return(checkLocationService(response)); if (response.Success != true) { MessageController.single.displayError(_loginCanvas, "Please make sure you are allowing this app to access your location from your phone's settings."); yield break; // could not turn location service on } response.reset(); yield return(SpatialClient2.single.LoginUser(response, _userNameField.text, _passwordField.text)); switch (response.Success) { case true: _connectionErrorText.enabled = false; _wrongPasswordText.enabled = false; // initialize egg menu addButtons(); initializeCheckinDataStructures(); // logged in, switch to main menu //_pleaseWaitCanvas.enabled = false; //_mainMenuCanvas.enabled = true; Debug.Log("loading webpage"); yield return(SpatialClient2.single.checkIfMarkersExist()); // populates with building markers if there are none around if (_userNameField.text == justRegisteredUsername) { justRegisteredUsername = null; showTutorial(); } else { _webView.Load(); } break; case false: // wrong credentials MessageController.single.closeWaitScreen(false); _connectionErrorText.enabled = false; _wrongPasswordText.enabled = true; Debug.Log("Wrong User or Password"); break; case null: // connection error (possible timeout) MessageController.single.closeWaitScreen(false); _wrongPasswordText.enabled = false; _connectionErrorText.enabled = true; Debug.Log("Connection Error"); break; } }
public IEnumerator initializeSprite(CoroutineResponse response) { yield return(KaijuDatabase.instance.checkAndDownloadEggSprite(_imageIndex, response)); }