/
ExampleLoginController.cs
96 lines (84 loc) · 3.27 KB
/
ExampleLoginController.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
using System;
using System.Collections;
using Epic.OnlineServices;
using Epic.OnlineServices.Auth;
using Epic.OnlineServices.Platform;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Unisave.EpicAuthentication.Examples.SimpleDemo
{
public class ExampleLoginController : MonoBehaviour
{
public Button loginButton;
public TMP_Text guideText;
private BasicEOSSDKComponent sdkComponent;
void Start()
{
// get the SDK component responsible for the management of the EOS SDK
sdkComponent = BasicEOSSDKComponent.Instance;
if (sdkComponent == null)
{
guideText.text =
"ERROR: The BasicEOSSDKComponent seems to be " +
"missing from the scene.";
loginButton.interactable = false;
return;
}
// register the button click handler
loginButton.onClick.AddListener(OnLoginClick);
}
async void OnLoginClick()
{
loginButton.interactable = false;
guideText.text = "";
// get the Epic SDK PlatformInterface instance
guideText.text += "Getting platform interface...\n";
PlatformInterface platform = sdkComponent.PlatformInterface;
if (platform == null)
{
guideText.text +=
"ERROR: Platform interface has failed to initialize.\n" +
"Check the console for more info.\n";
return;
}
// login EOS via the Auth interface
guideText.text += "Logging EOS in via Auth interface...\n";
LoginCallbackInfo info = await sdkComponent.AuthLogin(
authToolHost: "localhost:6547",
authToolCredentialName: "me"
);
if (info.ResultCode == Result.Success)
{
guideText.text +=
$"Done. Your EpicAccountId is: {sdkComponent.EpicAccountId}\n";
}
else
{
guideText.text +=
$"ERROR: Auth EOS login failed: {info.ResultCode}\n";
return;
}
// login EOS via Connect interface
guideText.text += "Logging EOS in via Connect interface...\n";
Result connectResult = await sdkComponent.ConnectLoginOrRegister();
if (connectResult == Result.Success)
{
guideText.text +=
$"Done. Your ProductUserId is: {sdkComponent.ProductUserId}\n";
}
else
{
guideText.text +=
$"ERROR: Auth EOS login failed: {connectResult}\n";
return;
}
// call the UnisaveEpicAuthentication code
guideText.text += "Logging into Unisave using the Epic user session...\n";
EpicLoginResponse response = await this.LoginUnisaveViaEpic(platform);
guideText.text += $"Done. Your Unisave player ID is: {response.PlayerId}\n";
// done, now this session is logged-in in unisave
guideText.text += "\n<b>Success!</b>\n";
}
}
}