コード例 #1
0
    public void RegistrationRequest()
    {
        if (inputField.text.Length > 0)
        {
            warningText.text = "";
            displayName      = UnityEngine.Random.Range(0, 1000000).GetHashCode().ToString();
            userName         = UnityEngine.Random.Range(0, 1000000).GetHashCode().ToString();
            password         = "******";
        }
        else
        {
            warningText.text = "Please Input Name";
            return;
        }

        new RegistrationRequest()
        .SetDisplayName(displayName)
        .SetPassword(password)
        .SetUserName(userName)
        .Send((response) => {
            authToken = response.AuthToken;
            newPlayer = response.NewPlayer;
            RegistrationResponse._Player switchSummary = response.SwitchSummary;
            userId = response.UserId;
        });

        if (newPlayer.Value == false)
        {
            RegistrationRequest();
        }
        else
        {
            StaticInfo.userInfo.dispName = this.inputField.text;
            StaticInfo.userInfo.first    = false;
            StaticInfo.userInfo.passWord = this.password;
            StaticInfo.userInfo.userName = this.userName;

            var json   = JsonUtility.ToJson(StaticInfo.userInfo);
            var path   = Application.dataPath + "/" + SAVE_FILE_PATH;
            var writer = new StreamWriter(path, false);
            Debug.Log(json);
            writer.WriteLine(json);
            writer.Flush();
            writer.Close();

            Debug.Log("New Player:" + userId.ToString());

            SceneManager.LoadScene("Title");
        }
    }
コード例 #2
0
    public void finalizeLoginOrRegister()
    {
        //move to main
        string usernameHere = GameObject.Find("usernameText").GetComponent <Text>().text;
        string passwordHere = GameObject.Find("password").GetComponent <InputField>().text;

        showuser = usernameHere;
        showpass = passwordHere;
        Debug.Log(passwordHere);
        if (usernameHere != null && passwordHere != null)
        {
            if (!registering)
            {
                Debug.Log("Logging-in");
                new AuthenticationRequest()
                .SetPassword(passwordHere)
                .SetUserName(usernameHere)
                .Send((response) => {
                    Debug.Log("response was sent");
                    if (!response.HasErrors)
                    {
                        string authToken   = response.AuthToken;
                        string displayName = response.DisplayName;
                        bool?newPlayer     = response.NewPlayer;
                        GSData scriptData  = response.ScriptData;
                        AuthenticationResponse._Player switchSummary = response.SwitchSummary;
                        string userId = response.UserId;
                        Debug.Log(userId + " was logged in");
                        storedUser = usernameHere;
                        SceneManager.LoadScene(1);
                    }
                    else
                    {
                        Debug.Log("Something went wrong.");
                        //GameObject.Find("errorPanel").GetComponent<CanvasGroup>().alpha = 1f;
                        Debug.Log(response.Errors);
                    }
                });
            }
            else
            {
                Debug.Log("Registering");
                new RegistrationRequest()
                .SetDisplayName(usernameHere)
                .SetPassword(passwordHere)
                .SetUserName(usernameHere)
                .Send((response) => {
                    Debug.Log("response was sent");
                    if (!response.HasErrors)
                    {
                        string authToken   = response.AuthToken;
                        string displayName = response.DisplayName;
                        bool?newPlayer     = response.NewPlayer;
                        GSData scriptData  = response.ScriptData;
                        RegistrationResponse._Player switchSummary = response.SwitchSummary;
                        string userId = response.UserId;
                        storedUser    = userId;
                        Debug.Log(userId + " was registered");
                        storedUser = usernameHere;
                        SceneManager.LoadScene(1);
                    }
                    else
                    {
                        Debug.Log(response.Errors);
                        Debug.Log("Something went wrong.");
                    }
                });
            }
        }
        else
        {
            Debug.Log("Username or password not filled out!");
            return;
        }
    }