-
Notifications
You must be signed in to change notification settings - Fork 0
/
SigninSampleScript.cs
112 lines (97 loc) · 3.49 KB
/
SigninSampleScript.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
namespace SignInSample {
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Google;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
public class SigninSampleScript : MonoBehaviourPun {
public static SigninSampleScript Instance { get; set; }
public Text statusText;
private string webClientId = "";
private GoogleSignInConfiguration configuration;
public Uri ImageUri;
void Awake() {
configuration = new GoogleSignInConfiguration {
WebClientId = webClientId,
RequestIdToken = true
};
}
private void Update()
{
if(Instance== null)
{
Instance = this;
}
}
public void OnSignIn() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
AddStatusText("Calling SignIn");
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(
OnAuthenticationFinished);
}
public void OnSignOut() {
AddStatusText("Calling SignOut");
GoogleSignIn.DefaultInstance.SignOut();
}
public void OnDisconnect() {
AddStatusText("Calling Disconnect");
GoogleSignIn.DefaultInstance.Disconnect();
}
internal void OnAuthenticationFinished(Task<GoogleSignInUser> task) {
if (task.IsFaulted) {
using (IEnumerator<System.Exception> enumerator =
task.Exception.InnerExceptions.GetEnumerator()) {
if (enumerator.MoveNext()) {
GoogleSignIn.SignInException error =
(GoogleSignIn.SignInException)enumerator.Current;
AddStatusText("Got Error: " + error.Status + " " + error.Message);
} else {
AddStatusText("Got Unexpected Exception?!?" + task.Exception);
}
}
} else if(task.IsCanceled) {
AddStatusText("Canceled");
} else if(task.IsCompleted) {
PhotonNetwork.LocalPlayer.NickName = task.Result.DisplayName;
PhotonNetwork.LoadLevel("HUB");
ImageUri = task.Result.ImageUrl;
statusText.text = "Success";
//AddStatusText("Welcome: " + task.Result.DisplayName + "!" + task.Result.ImageUrl);
}
}
public void OnSignInSilently() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = false;
GoogleSignIn.Configuration.RequestIdToken = true;
AddStatusText("Calling SignIn Silently");
GoogleSignIn.DefaultInstance.SignInSilently()
.ContinueWith(OnAuthenticationFinished);
}
public void OnGamesSignIn() {
GoogleSignIn.Configuration = configuration;
GoogleSignIn.Configuration.UseGameSignIn = true;
GoogleSignIn.Configuration.RequestIdToken = false;
AddStatusText("Calling Games SignIn");
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(
OnAuthenticationFinished);
}
public List<string> messages = new List<string>();
void AddStatusText(string text) {
if (messages.Count == 5) {
messages.RemoveAt(0);
}
messages.Add(text);
string txt = "";
foreach (string s in messages) {
txt += "\n" + s;
}
statusText.text = txt;
}
}
}