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;
        }
    }
示例#2
0
    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;
    }
示例#3
0
    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);
    }
    // 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 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;
        }
    }