Skip to content

Commit 38efd3b

Browse files
authored
Merge pull request #16 from modio/v2024.9
Syncing v2024.9
2 parents 98cd2b6 + 5cb453a commit 38efd3b

File tree

77 files changed

+3393
-176
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3393
-176
lines changed

Platform/Editor/ModIO.Implementation.Platform/PlatformConfiguration_Editor.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ internal static partial class PlatformConfiguration
99
{
1010
#if UNITY_EDITOR_WIN
1111
/// <summary>Holds the value for the platform header value to use in requests.</summary>
12-
public static string RESTAPI_HEADER = RestApiPlatform.Windows.ToString();
12+
public static RestApiPlatform RESTAPI_HEADER = RestApiPlatform.Windows;
1313
#elif UNITY_EDITOR_OSX
1414
/// <summary>Holds the value for the platform header value to use in requests.</summary>
15-
public static string RESTAPI_HEADER = RestApiPlatform.Mac.ToString();
15+
public static RestApiPlatform RESTAPI_HEADER = RestApiPlatform.Mac;
1616
#elif UNITY_EDITOR_LINUX
1717
/// <summary>Holds the value for the platform header value to use in requests.</summary>
18-
public static string RESTAPI_HEADER = RestApiPlatform.Linux.ToString();
18+
public static RestApiPlatform RESTAPI_HEADER = RestApiPlatform.Linux;
1919
#endif
2020
public const bool SynchronizedDataJobs = false;
2121

Platform/Mobile/Android.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using UnityEngine;
2+
3+
#if UNITY_ANDROID
4+
using GooglePlayGames;
5+
#endif
6+
7+
namespace ModIO.Implementation.Platform
8+
{
9+
public class ModioPlatformExampleGoogleGames : MonoBehaviour
10+
{
11+
private void Awake()
12+
{
13+
#if UNITY_ANDROID
14+
// Enable debug logging for Play Games Platform
15+
PlayGamesPlatform.DebugLogEnabled = true;
16+
PlayGamesPlatform.Activate();
17+
18+
// Authenticate with Play Games Services
19+
PlayGamesPlatform.Instance.Authenticate((success) =>
20+
{
21+
// Check if authentication was successful
22+
if (success)
23+
{
24+
// --- This is the important line to include in your own implementation ---
25+
ModioPlatformGoogleGames.SetAsPlatform();
26+
}
27+
else
28+
{
29+
// Handle unsuccessful authentication:
30+
// Disable your integration with Play Games Services or show a login button to ask users to sign-in.
31+
// Clicking it should call PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication);
32+
}
33+
});
34+
#endif
35+
}
36+
37+
}
38+
}

Platform/Mobile/Android/ModioPlatformExampleGoogleGames.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using UnityEngine;
2+
3+
#if UNITY_ANDROID
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading.Tasks;
7+
using Google;
8+
#endif
9+
10+
namespace ModIO.Implementation.Platform
11+
{
12+
public class ModioPlatformExampleGoogleSignIn : MonoBehaviour
13+
{
14+
[SerializeField] string clientId = "<your client id here>";
15+
string idToken;
16+
17+
private void Awake()
18+
{
19+
#if UNITY_ANDROID
20+
SignInSilently();
21+
#endif
22+
}
23+
24+
#if UNITY_ANDROID
25+
async void SignInSilently()
26+
{
27+
if (Application.isEditor)
28+
return;
29+
30+
GoogleSignIn.Configuration = new GoogleSignInConfiguration
31+
{
32+
WebClientId = clientId,
33+
RequestIdToken = true
34+
};
35+
GoogleSignIn.Configuration.UseGameSignIn = false;
36+
GoogleSignIn.Configuration.RequestIdToken = true;
37+
Logger.Log(LogLevel.Verbose, "Calling SignIn Silently");
38+
39+
var task = GoogleSignIn.DefaultInstance.SignInSilently();
40+
await task;
41+
FinishSignIn(task);
42+
}
43+
44+
public async Task SignIn()
45+
{
46+
if (Application.isEditor)
47+
return;
48+
49+
GoogleSignIn.Configuration = new GoogleSignInConfiguration
50+
{
51+
WebClientId = clientId,
52+
RequestIdToken = true
53+
};
54+
GoogleSignIn.Configuration.UseGameSignIn = false;
55+
GoogleSignIn.Configuration.RequestIdToken = true;
56+
Logger.Log(LogLevel.Verbose, "Calling SignIn");
57+
58+
var task = GoogleSignIn.DefaultInstance.SignIn();
59+
await task;
60+
FinishSignIn(task);
61+
}
62+
63+
void FinishSignIn(Task<GoogleSignInUser> task)
64+
{
65+
if (task.IsFaulted)
66+
{
67+
using (IEnumerator<Exception> enumerator = task.Exception.InnerExceptions.GetEnumerator())
68+
{
69+
if (enumerator.MoveNext())
70+
{
71+
GoogleSignIn.SignInException error = (GoogleSignIn.SignInException)enumerator.Current;
72+
Logger.Log(LogLevel.Verbose, "Error: " + error.Status + " " + error.Message);
73+
}
74+
else
75+
{
76+
Logger.Log(LogLevel.Verbose, task.Exception.Message);
77+
}
78+
}
79+
}
80+
else if (task.IsCanceled)
81+
{
82+
Logger.Log(LogLevel.Verbose, "Google Sign In task was Canceled");
83+
}
84+
else
85+
{
86+
// --- This is the important line to include in your own implementation ---
87+
ModioPlatformGoogleSignIn.SetAsPlatform(task.Result.IdToken);
88+
Logger.Log(LogLevel.Verbose, "Sign in completed!");
89+
}
90+
}
91+
92+
public void SignOut()
93+
{
94+
if (Application.isEditor)
95+
return;
96+
97+
Logger.Log(LogLevel.Verbose, "Calling SignOut");
98+
GoogleSignIn.DefaultInstance.SignOut();
99+
}
100+
101+
public void Disconnect()
102+
{
103+
if (Application.isEditor)
104+
return;
105+
106+
Logger.Log(LogLevel.Verbose, "Calling Disconnect");
107+
GoogleSignIn.DefaultInstance.Disconnect();
108+
}
109+
#endif
110+
}
111+
}

Platform/Mobile/Android/ModioPlatformExampleGoogleSignIn.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
3+
#if UNITY_ANDROID
4+
using GooglePlayGames;
5+
using UnityEngine;
6+
#endif
7+
8+
namespace ModIO.Implementation.Platform
9+
{
10+
public class ModioPlatformGoogleGames : ModioPlatform, IModioSsoPlatform
11+
{
12+
public static void SetAsPlatform()
13+
{
14+
ActivePlatform = new ModioPlatformGoogleGames();
15+
}
16+
17+
public void PerformSso(TermsHash? displayedTerms, Action<Result> onComplete, string optionalThirdPartyEmailAddressUsedForAuthentication = null)
18+
{
19+
#if UNITY_ANDROID
20+
GetIdToken(token =>
21+
{
22+
ModIOUnity.AuthenticateUserViaGoogle(token,
23+
optionalThirdPartyEmailAddressUsedForAuthentication,
24+
displayedTerms,
25+
onComplete);
26+
});
27+
#endif
28+
}
29+
30+
#if UNITY_ANDROID
31+
void GetIdToken(Action<string> onReceivedAuthCode)
32+
{
33+
if (Application.isEditor)
34+
return;
35+
36+
try
37+
{
38+
// Request server-side auth code from Play Games Platform
39+
var idToken = PlayGamesPlatform.Instance.GetIdToken();
40+
Logger.Log(LogLevel.Verbose, $"Id Token: {idToken}");
41+
onReceivedAuthCode?.Invoke(idToken);
42+
}
43+
catch (Exception e)
44+
{
45+
Logger.Log(LogLevel.Error, e.Message);
46+
}
47+
}
48+
#endif
49+
}
50+
}

Platform/Mobile/Android/ModioPlatformGoogleGames.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
3+
namespace ModIO.Implementation.Platform
4+
{
5+
public class ModioPlatformGoogleSignIn : ModioPlatform, IModioSsoPlatform
6+
{
7+
private string idToken;
8+
9+
public static void SetAsPlatform(string idToken)
10+
{
11+
ActivePlatform = new ModioPlatformGoogleSignIn
12+
{
13+
idToken = idToken,
14+
};
15+
}
16+
public void PerformSso(TermsHash? displayedTerms, Action<Result> onComplete, string optionalThirdPartyEmailAddressUsedForAuthentication = null)
17+
{
18+
#if UNITY_ANDROID
19+
ModIOUnity.AuthenticateUserViaGoogle(idToken,
20+
optionalThirdPartyEmailAddressUsedForAuthentication,
21+
displayedTerms,
22+
onComplete);
23+
#endif
24+
}
25+
}
26+
}

Platform/Mobile/Android/ModioPlatformGoogleSignIn.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Platform/Mobile/Android/Resources.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &890429863644987089
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 24952581316947064}
12+
- component: {fileID: 9178692787153453301}
13+
m_Layer: 0
14+
m_Name: ModioPlatformExampleGoogleGames
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &24952581316947064
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 890429863644987089}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_Children: []
31+
m_Father: {fileID: 0}
32+
m_RootOrder: 0
33+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
34+
--- !u!114 &9178692787153453301
35+
MonoBehaviour:
36+
m_ObjectHideFlags: 0
37+
m_CorrespondingSourceObject: {fileID: 0}
38+
m_PrefabInstance: {fileID: 0}
39+
m_PrefabAsset: {fileID: 0}
40+
m_GameObject: {fileID: 890429863644987089}
41+
m_Enabled: 1
42+
m_EditorHideFlags: 0
43+
m_Script: {fileID: 11500000, guid: a8c3b83c1f3494b37a244bbff4ae835e, type: 3}
44+
m_Name:
45+
m_EditorClassIdentifier:

Platform/Mobile/Android/Resources/ModioPlatformExampleGoogleGames.prefab.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!1 &890429863644987089
4+
GameObject:
5+
m_ObjectHideFlags: 0
6+
m_CorrespondingSourceObject: {fileID: 0}
7+
m_PrefabInstance: {fileID: 0}
8+
m_PrefabAsset: {fileID: 0}
9+
serializedVersion: 6
10+
m_Component:
11+
- component: {fileID: 24952581316947064}
12+
- component: {fileID: -8228732916061347725}
13+
m_Layer: 0
14+
m_Name: ModioPlatformExampleGoogleSignIn
15+
m_TagString: Untagged
16+
m_Icon: {fileID: 0}
17+
m_NavMeshLayer: 0
18+
m_StaticEditorFlags: 0
19+
m_IsActive: 1
20+
--- !u!4 &24952581316947064
21+
Transform:
22+
m_ObjectHideFlags: 0
23+
m_CorrespondingSourceObject: {fileID: 0}
24+
m_PrefabInstance: {fileID: 0}
25+
m_PrefabAsset: {fileID: 0}
26+
m_GameObject: {fileID: 890429863644987089}
27+
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28+
m_LocalPosition: {x: 0, y: 0, z: 0}
29+
m_LocalScale: {x: 1, y: 1, z: 1}
30+
m_Children: []
31+
m_Father: {fileID: 0}
32+
m_RootOrder: 0
33+
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
34+
--- !u!114 &-8228732916061347725
35+
MonoBehaviour:
36+
m_ObjectHideFlags: 0
37+
m_CorrespondingSourceObject: {fileID: 0}
38+
m_PrefabInstance: {fileID: 0}
39+
m_PrefabAsset: {fileID: 0}
40+
m_GameObject: {fileID: 890429863644987089}
41+
m_Enabled: 1
42+
m_EditorHideFlags: 0
43+
m_Script: {fileID: 11500000, guid: d7c2768ec28364d04adb96f24535f9bd, type: 3}
44+
m_Name:
45+
m_EditorClassIdentifier:
46+
clientId: 163019015440-9kjmrqfgi6aavepdn33a695dc2002l9m.apps.googleusercontent.com

Platform/Mobile/Android/Resources/ModioPlatformExampleGoogleSignIn.prefab.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)