2022-02-06 02:06:25 +00:00
using Epic.OnlineServices ;
using Epic.OnlineServices.Logging ;
using Epic.OnlineServices.Platform ;
using UnityEngine ;
/// <summary>
/// Manages the Epic Online Services SDK
/// Do not destroy this component!
/// The Epic Online Services SDK can only be initialized once,
/// after releasing the SDK the game has to be restarted in order to initialize the SDK again.
/// In the unity editor the OnDestroy function will not run so that we dont have to restart the editor after play.
/// </summary>
2022-03-03 03:46:33 +00:00
namespace EpicTransport ;
[DefaultExecutionOrder(-32000)]
public class EOSSDKComponent : MonoBehaviour
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
// Unity Inspector shown variables
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
[SerializeField]
public EosApiKey apiKeys ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
[Header("User Login")]
public bool authInterfaceLogin = false ;
2022-02-25 05:43:40 +00:00
2022-03-03 03:46:33 +00:00
public Epic . OnlineServices . Auth . LoginCredentialType authInterfaceCredentialType = Epic . OnlineServices . Auth . LoginCredentialType . AccountPortal ;
public uint devAuthToolPort = 7878 ;
public string devAuthToolCredentialName = "" ;
public ExternalCredentialType connectInterfaceCredentialType = ExternalCredentialType . DeviceidAccessToken ;
public string deviceModel = "PC Windows 64bit" ;
[SerializeField] private string displayName = "User" ;
2022-02-25 05:43:40 +00:00
2022-03-03 03:46:33 +00:00
public static string DisplayName
{
get = > Instance . displayName ;
set = > Instance . displayName = value ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
[Header("Misc")]
public LogLevel epicLoggerLevel = LogLevel . Error ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
[SerializeField]
2022-04-04 04:52:05 +00:00
private bool collectPlayerMetrics = true ;
2022-02-25 05:43:40 +00:00
2022-03-03 03:46:33 +00:00
public static bool CollectPlayerMetrics = > Instance . collectPlayerMetrics ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
public bool checkForEpicLauncherAndRestart = false ;
public bool delayedInitialization = false ;
public float platformTickIntervalInSeconds = 0.0f ;
private float platformTickTimer = 0f ;
public uint tickBudgetInMilliseconds = 0 ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// End Unity Inspector shown variables
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
private ulong authExpirationHandle ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
private string authInterfaceLoginCredentialId = null ;
public static void SetAuthInterfaceLoginCredentialId ( string credentialId ) = > Instance . authInterfaceLoginCredentialId = credentialId ;
private string authInterfaceCredentialToken = null ;
public static void SetAuthInterfaceCredentialToken ( string credentialToken ) = > Instance . authInterfaceCredentialToken = credentialToken ;
private string connectInterfaceCredentialToken = null ;
public static void SetConnectInterfaceCredentialToken ( string credentialToken ) = > Instance . connectInterfaceCredentialToken = credentialToken ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
private PlatformInterface EOS ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// Interfaces
public static Epic . OnlineServices . Achievements . AchievementsInterface GetAchievementsInterface ( ) = > Instance . EOS . GetAchievementsInterface ( ) ;
public static Epic . OnlineServices . Auth . AuthInterface GetAuthInterface ( ) = > Instance . EOS . GetAuthInterface ( ) ;
public static Epic . OnlineServices . Connect . ConnectInterface GetConnectInterface ( ) = > Instance . EOS . GetConnectInterface ( ) ;
public static Epic . OnlineServices . Ecom . EcomInterface GetEcomInterface ( ) = > Instance . EOS . GetEcomInterface ( ) ;
public static Epic . OnlineServices . Friends . FriendsInterface GetFriendsInterface ( ) = > Instance . EOS . GetFriendsInterface ( ) ;
public static Epic . OnlineServices . Leaderboards . LeaderboardsInterface GetLeaderboardsInterface ( ) = > Instance . EOS . GetLeaderboardsInterface ( ) ;
public static Epic . OnlineServices . Lobby . LobbyInterface GetLobbyInterface ( ) = > Instance . EOS . GetLobbyInterface ( ) ;
public static Epic . OnlineServices . Metrics . MetricsInterface GetMetricsInterface ( ) = > Instance . EOS . GetMetricsInterface ( ) ; // Handled by the transport automatically, only use this interface if Mirror is not used for singleplayer
public static Epic . OnlineServices . Mods . ModsInterface GetModsInterface ( ) = > Instance . EOS . GetModsInterface ( ) ;
public static Epic . OnlineServices . P2P . P2PInterface GetP2PInterface ( ) = > Instance . EOS . GetP2PInterface ( ) ;
public static Epic . OnlineServices . PlayerDataStorage . PlayerDataStorageInterface GetPlayerDataStorageInterface ( ) = > Instance . EOS . GetPlayerDataStorageInterface ( ) ;
public static Epic . OnlineServices . Presence . PresenceInterface GetPresenceInterface ( ) = > Instance . EOS . GetPresenceInterface ( ) ;
public static Epic . OnlineServices . Sessions . SessionsInterface GetSessionsInterface ( ) = > Instance . EOS . GetSessionsInterface ( ) ;
public static Epic . OnlineServices . TitleStorage . TitleStorageInterface GetTitleStorageInterface ( ) = > Instance . EOS . GetTitleStorageInterface ( ) ;
public static Epic . OnlineServices . UI . UIInterface GetUIInterface ( ) = > Instance . EOS . GetUIInterface ( ) ;
public static Epic . OnlineServices . UserInfo . UserInfoInterface GetUserInfoInterface ( ) = > Instance . EOS . GetUserInfoInterface ( ) ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected EpicAccountId localUserAccountId ;
public static EpicAccountId LocalUserAccountId = > Instance . localUserAccountId ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected string localUserAccountIdString ;
public static string LocalUserAccountIdString = > Instance . localUserAccountIdString ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected ProductUserId localUserProductId ;
public static ProductUserId LocalUserProductId = > Instance . localUserProductId ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected string localUserProductIdString ;
public static string LocalUserProductIdString = > Instance . localUserProductIdString ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected bool initialized ;
public static bool Initialized = > Instance . initialized ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected bool isConnecting ;
public static bool IsConnecting = > Instance . isConnecting ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
protected static EOSSDKComponent instance ;
2022-02-25 05:43:40 +00:00
2022-03-03 03:46:33 +00:00
protected static EOSSDKComponent Instance
{
get
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
if ( instance = = null )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
return new GameObject ( "EOSSDKComponent" ) . AddComponent < EOSSDKComponent > ( ) ;
}
else
{
return instance ;
2022-02-06 04:17:08 +00:00
}
}
2022-03-03 03:46:33 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
public static void Tick ( )
{
instance . platformTickTimer - = Time . deltaTime ;
instance . EOS . Tick ( ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// If we're in editor, we should dynamically load and unload the SDK between play sessions.
// This allows us to initialize the SDK each time the game is run in editor.
2022-02-06 02:06:25 +00:00
#if UNITY_EDITOR_WIN
[DllImport("Kernel32.dll")]
private static extern IntPtr LoadLibrary ( string lpLibFileName ) ;
[DllImport("Kernel32.dll")]
private static extern int FreeLibrary ( IntPtr hLibModule ) ;
[DllImport("Kernel32.dll")]
private static extern IntPtr GetProcAddress ( IntPtr hModule , string lpProcName ) ;
private IntPtr libraryPointer ;
#endif
2022-02-06 04:17:08 +00:00
2022-02-06 02:06:25 +00:00
#if UNITY_EDITOR_LINUX
[DllImport("libdl.so", EntryPoint = "dlopen")]
private static extern IntPtr LoadLibrary ( String lpFileName , int flags = 2 ) ;
[DllImport("libdl.so", EntryPoint = "dlclose")]
private static extern int FreeLibrary ( IntPtr hLibModule ) ;
[DllImport("libdl.so")]
private static extern IntPtr dlsym ( IntPtr handle , String symbol ) ;
[DllImport("libdl.so")]
private static extern IntPtr dlerror ( ) ;
private static IntPtr GetProcAddress ( IntPtr hModule , string lpProcName ) {
// clear previous errors if any
dlerror ( ) ;
var res = dlsym ( hModule , lpProcName ) ;
var errPtr = dlerror ( ) ;
if ( errPtr ! = IntPtr . Zero ) {
throw new Exception ( "dlsym: " + Marshal . PtrToStringAnsi ( errPtr ) ) ;
}
return res ;
}
private IntPtr libraryPointer ;
#endif
2022-03-03 03:46:33 +00:00
private void Awake ( )
{
// Initialize Java version of the SDK with a reference to the VM with JNI
// See https://eoshelp.epicgames.com/s/question/0D54z00006ufJBNCA2/cant-get-createdeviceid-to-work-in-unity-android-c-sdk?language=en_US
if ( Application . platform = = RuntimePlatform . Android )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
var unityPlayer = new AndroidJavaClass ( "com.unity3d.player.UnityPlayer" ) ;
var activity = unityPlayer . GetStatic < AndroidJavaObject > ( "currentActivity" ) ;
var context = activity . Call < AndroidJavaObject > ( "getApplicationContext" ) ;
var EOS_SDK_JAVA = new AndroidJavaClass ( "com.epicgames.mobile.eossdk.EOSSDK" ) ;
EOS_SDK_JAVA . CallStatic ( "init" , context ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// Prevent multiple instances
if ( instance ! = null )
{
Destroy ( gameObject ) ;
return ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
instance = this ;
2022-02-06 02:06:25 +00:00
#if UNITY_EDITOR
var libraryPath = "Assets/Mirror/Runtime/Transport/EpicOnlineTransport/EOSSDK/" + Config . LibraryName ;
libraryPointer = LoadLibrary ( libraryPath ) ;
if ( libraryPointer = = IntPtr . Zero ) {
throw new Exception ( "Failed to load library" + libraryPath ) ;
}
Bindings . Hook ( libraryPointer , GetProcAddress ) ;
#endif
2022-03-03 03:46:33 +00:00
if ( ! delayedInitialization )
{
Initialize ( ) ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
}
protected void InitializeImplementation ( )
{
isConnecting = true ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
var initializeOptions = new InitializeOptions ( )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
ProductName = apiKeys . epicProductName ,
ProductVersion = apiKeys . epicProductVersion
} ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
var initializeResult = PlatformInterface . Initialize ( initializeOptions ) ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// This code is called each time the game is run in the editor, so we catch the case where the SDK has already been initialized in the editor.
var isAlreadyConfiguredInEditor = Application . isEditor & & initializeResult = = Result . AlreadyConfigured ;
if ( initializeResult ! = Result . Success & & ! isAlreadyConfiguredInEditor )
{
throw new System . Exception ( "Failed to initialize platform: " + initializeResult ) ;
}
2022-02-25 06:04:54 +00:00
2022-03-03 03:46:33 +00:00
// The SDK outputs lots of information that is useful for debugging.
// Make sure to set up the logging interface as early as possible: after initializing.
LoggingInterface . SetLogLevel ( LogCategory . AllCategories , epicLoggerLevel ) ;
LoggingInterface . SetCallback ( message = > Logger . EpicDebugLog ( message ) ) ;
var options = new Options ( )
{
ProductId = apiKeys . epicProductId ,
SandboxId = apiKeys . epicSandboxId ,
DeploymentId = apiKeys . epicDeploymentId ,
ClientCredentials = new ClientCredentials ( )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
ClientId = apiKeys . epicClientId ,
ClientSecret = apiKeys . epicClientSecret
} ,
TickBudgetInMilliseconds = tickBudgetInMilliseconds
} ;
EOS = PlatformInterface . Create ( options ) ;
if ( EOS = = null )
{
throw new System . Exception ( "Failed to create platform" ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
if ( checkForEpicLauncherAndRestart )
{
var result = EOS . CheckForLauncherAndRestart ( ) ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// If not started through epic launcher the app will be restarted and we can quit
if ( result ! = Result . NoChange )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
// Log error if launcher check failed, but still quit to prevent hacking
if ( result = = Result . UnexpectedError )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . LogError ( "Unexpected Error while checking if app was started through epic launcher" ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
Application . Quit ( ) ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// If we use the Auth interface then only login into the Connect interface after finishing the auth interface login
// If we don't use the Auth interface we can directly login to the Connect interface
if ( authInterfaceLogin )
{
if ( authInterfaceCredentialType = = Epic . OnlineServices . Auth . LoginCredentialType . Developer )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
authInterfaceLoginCredentialId = "localhost:" + devAuthToolPort ;
authInterfaceCredentialToken = devAuthToolCredentialName ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
// Login to Auth Interface
var loginOptions = new Epic . OnlineServices . Auth . LoginOptions ( )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Credentials = new Epic . OnlineServices . Auth . Credentials ( )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Type = authInterfaceCredentialType ,
Id = authInterfaceLoginCredentialId ,
Token = authInterfaceCredentialToken
} ,
ScopeFlags = Epic . OnlineServices . Auth . AuthScopeFlags . BasicProfile | Epic . OnlineServices . Auth . AuthScopeFlags . FriendsList | Epic . OnlineServices . Auth . AuthScopeFlags . Presence
} ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
EOS . GetAuthInterface ( ) . Login ( loginOptions , null , OnAuthInterfaceLogin ) ;
}
else
{
// Login to Connect Interface
if ( connectInterfaceCredentialType = = ExternalCredentialType . DeviceidAccessToken )
{
var createDeviceIdOptions = new Epic . OnlineServices . Connect . CreateDeviceIdOptions ( ) ;
createDeviceIdOptions . DeviceModel = deviceModel ;
EOS . GetConnectInterface ( ) . CreateDeviceId ( createDeviceIdOptions , null , OnCreateDeviceId ) ;
2022-02-06 04:17:08 +00:00
}
else
{
2022-03-03 03:46:33 +00:00
ConnectInterfaceLogin ( ) ;
2022-02-06 04:17:08 +00:00
}
}
2022-03-03 03:46:33 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
public static void Initialize ( )
{
if ( Instance . initialized | | Instance . isConnecting )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
return ;
2022-02-25 06:04:54 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
Instance . InitializeImplementation ( ) ;
}
private void OnAuthInterfaceLogin ( Epic . OnlineServices . Auth . LoginCallbackInfo loginCallbackInfo )
{
if ( loginCallbackInfo . ResultCode = = Result . Success )
2022-02-25 06:04:54 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( "Auth Interface Login succeeded" ) ;
string accountIdString ;
var result = loginCallbackInfo . LocalUserId . ToString ( out accountIdString ) ;
if ( Result . Success = = result )
2022-02-27 12:40:44 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( "EOS User ID:" + accountIdString ) ;
2022-02-25 06:04:54 +00:00
2022-03-03 03:46:33 +00:00
localUserAccountIdString = accountIdString ;
localUserAccountId = loginCallbackInfo . LocalUserId ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
ConnectInterfaceLogin ( ) ;
}
else if ( Epic . OnlineServices . Common . IsOperationComplete ( loginCallbackInfo . ResultCode ) )
{
Debug . Log ( "Login returned " + loginCallbackInfo . ResultCode ) ;
}
}
2022-02-25 06:04:54 +00:00
2022-03-03 03:46:33 +00:00
private void OnCreateDeviceId ( Epic . OnlineServices . Connect . CreateDeviceIdCallbackInfo createDeviceIdCallbackInfo )
{
if ( createDeviceIdCallbackInfo . ResultCode = = Result . Success | | createDeviceIdCallbackInfo . ResultCode = = Result . DuplicateNotAllowed )
{
ConnectInterfaceLogin ( ) ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
else if ( Epic . OnlineServices . Common . IsOperationComplete ( createDeviceIdCallbackInfo . ResultCode ) )
{
Debug . Log ( "Device ID creation returned " + createDeviceIdCallbackInfo . ResultCode ) ;
}
}
private void ConnectInterfaceLogin ( )
{
var loginOptions = new Epic . OnlineServices . Connect . LoginOptions ( ) ;
2022-02-27 12:40:44 +00:00
2022-03-03 03:46:33 +00:00
if ( connectInterfaceCredentialType = = ExternalCredentialType . Epic )
2022-02-25 06:04:54 +00:00
{
2022-03-03 03:46:33 +00:00
Epic . OnlineServices . Auth . Token token ;
var result = EOS . GetAuthInterface ( ) . CopyUserAuthToken ( new Epic . OnlineServices . Auth . CopyUserAuthTokenOptions ( ) , localUserAccountId , out token ) ;
if ( result = = Result . Success )
2022-02-27 12:40:44 +00:00
{
2022-03-03 03:46:33 +00:00
connectInterfaceCredentialToken = token . AccessToken ;
2022-02-27 12:40:44 +00:00
}
2022-03-03 03:46:33 +00:00
else
2022-02-27 12:40:44 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . LogError ( "Failed to retrieve User Auth Token" ) ;
2022-02-27 12:40:44 +00:00
}
2022-02-25 06:04:54 +00:00
}
2022-03-03 03:46:33 +00:00
else if ( connectInterfaceCredentialType = = ExternalCredentialType . DeviceidAccessToken )
{
loginOptions . UserLoginInfo = new Epic . OnlineServices . Connect . UserLoginInfo ( ) ;
loginOptions . UserLoginInfo . DisplayName = displayName ;
}
loginOptions . Credentials = new Epic . OnlineServices . Connect . Credentials ( ) ;
loginOptions . Credentials . Type = connectInterfaceCredentialType ;
loginOptions . Credentials . Token = connectInterfaceCredentialToken ;
EOS . GetConnectInterface ( ) . Login ( loginOptions , null , OnConnectInterfaceLogin ) ;
}
2022-02-25 06:04:54 +00:00
2022-03-03 03:46:33 +00:00
private void OnConnectInterfaceLogin ( Epic . OnlineServices . Connect . LoginCallbackInfo loginCallbackInfo )
{
if ( loginCallbackInfo . ResultCode = = Result . Success )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( "Connect Interface Login succeeded" ) ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
string productIdString ;
var result = loginCallbackInfo . LocalUserId . ToString ( out productIdString ) ;
if ( Result . Success = = result )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( "EOS User Product ID:" + productIdString ) ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
localUserProductIdString = productIdString ;
localUserProductId = loginCallbackInfo . LocalUserId ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
initialized = true ;
isConnecting = false ;
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
var authExpirationOptions = new Epic . OnlineServices . Connect . AddNotifyAuthExpirationOptions ( ) ;
authExpirationHandle = EOS . GetConnectInterface ( ) . AddNotifyAuthExpiration ( authExpirationOptions , null , OnAuthExpiration ) ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
else if ( Epic . OnlineServices . Common . IsOperationComplete ( loginCallbackInfo . ResultCode ) )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( "Login returned " + loginCallbackInfo . ResultCode + "\nRetrying..." ) ;
EOS . GetConnectInterface ( ) . CreateUser ( new Epic . OnlineServices . Connect . CreateUserOptions ( ) { ContinuanceToken = loginCallbackInfo . ContinuanceToken } , null , ( Epic . OnlineServices . Connect . CreateUserCallbackInfo cb ) = >
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
if ( cb . ResultCode ! = Result . Success )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
Debug . Log ( cb . ResultCode ) ;
return ;
2022-02-06 04:17:08 +00:00
}
2022-03-03 03:46:33 +00:00
localUserProductId = cb . LocalUserId ;
ConnectInterfaceLogin ( ) ;
} ) ;
2022-02-27 12:40:44 +00:00
}
2022-03-03 03:46:33 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
private void OnAuthExpiration ( Epic . OnlineServices . Connect . AuthExpirationCallbackInfo authExpirationCallbackInfo )
{
Debug . Log ( "AuthExpiration callback" ) ;
EOS . GetConnectInterface ( ) . RemoveNotifyAuthExpiration ( authExpirationHandle ) ;
ConnectInterfaceLogin ( ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// Calling tick on a regular interval is required for callbacks to work.
private void LateUpdate ( )
{
if ( EOS ! = null )
2022-02-27 12:40:44 +00:00
{
2022-03-03 03:46:33 +00:00
platformTickTimer + = Time . deltaTime ;
2022-02-27 12:40:44 +00:00
2022-03-03 03:46:33 +00:00
if ( platformTickTimer > = platformTickIntervalInSeconds )
{
platformTickTimer = 0 ;
EOS . Tick ( ) ;
2022-02-06 04:17:08 +00:00
}
}
2022-03-03 03:46:33 +00:00
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
private void OnApplicationQuit ( )
{
if ( EOS ! = null )
2022-02-06 04:17:08 +00:00
{
2022-03-03 03:46:33 +00:00
EOS . Release ( ) ;
EOS = null ;
PlatformInterface . Shutdown ( ) ;
}
2022-02-06 04:17:08 +00:00
2022-03-03 03:46:33 +00:00
// Unhook the library in the editor, this makes it possible to load the library again after stopping to play
2022-02-06 02:06:25 +00:00
#if UNITY_EDITOR
if ( libraryPointer ! = IntPtr . Zero ) {
Bindings . Unhook ( ) ;
// Free until the module ref count is 0
while ( FreeLibrary ( libraryPointer ) ! = 0 ) { }
libraryPointer = IntPtr . Zero ;
}
#endif
2022-02-06 04:17:08 +00:00
}
2022-04-04 04:52:05 +00:00
}