void Awake()
        {
            IsConnecting = true;

            var initializeOptions = new InitializeOptions()
            {
                ProductName    = epicProductName,
                ProductVersion = epicProductVersion
            };

            var initializeResult = PlatformInterface.Initialize(initializeOptions);

            // 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);
            }

            // 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, LogLevel.VeryVerbose);
            LoggingInterface.SetCallback((LogMessage logMessage) => {
                Debug.Log(logMessage.Message);
            });

            var options = new Options()
            {
                ProductId         = epicProductId,
                SandboxId         = epicSandboxId,
                DeploymentId      = epicDeploymentId,
                ClientCredentials = new ClientCredentials()
                {
                    ClientId     = epicClientId,
                    ClientSecret = epicClientSecret
                }
            };

            EOS = PlatformInterface.Create(options);
            if (EOS == null)
            {
                throw new System.Exception("Failed to create platform");
            }

            //Login to the Connect Interface
            Epic.OnlineServices.Connect.CreateDeviceIdOptions createDeviceIdOptions = new Epic.OnlineServices.Connect.CreateDeviceIdOptions();
            createDeviceIdOptions.DeviceModel = "PC Windows 64bit";
            EOS.GetConnectInterface().CreateDeviceId(createDeviceIdOptions, null,
                                                     (Epic.OnlineServices.Connect.CreateDeviceIdCallbackInfo createDeviceIdCallbackInfo) => {
                if (createDeviceIdCallbackInfo.ResultCode == Result.Success || createDeviceIdCallbackInfo.ResultCode == Result.DuplicateNotAllowed)
                {
                    var loginOptions                       = new Epic.OnlineServices.Connect.LoginOptions();
                    loginOptions.UserLoginInfo             = new Epic.OnlineServices.Connect.UserLoginInfo();
                    loginOptions.UserLoginInfo.DisplayName = "Justin";
                    loginOptions.Credentials               = new Epic.OnlineServices.Connect.Credentials();
                    loginOptions.Credentials.Type          = Epic.OnlineServices.Connect.ExternalCredentialType.DeviceidAccessToken;
                    loginOptions.Credentials.Token         = null;

                    EOS.GetConnectInterface().Login(loginOptions, null,
                                                    (Epic.OnlineServices.Connect.LoginCallbackInfo loginCallbackInfo) => {
                        if (loginCallbackInfo.ResultCode == Result.Success)
                        {
                            Debug.Log("Login succeeded");

                            string productIdString;
                            Result result = loginCallbackInfo.LocalUserId.ToString(out productIdString);
                            if (Result.Success == result)
                            {
                                Debug.Log("EOS User Product ID:" + productIdString);

                                localUserProductIdString = productIdString;
                                localUserProductId       = loginCallbackInfo.LocalUserId;
                            }

                            Initialized  = true;
                            IsConnecting = false;
                        }
                        else
                        {
                            Debug.Log("Login returned " + loginCallbackInfo.ResultCode);
                        }
                    });
                }
                else
                {
                    Debug.Log("Device ID creation returned " + createDeviceIdCallbackInfo.ResultCode);
                }
            });
        }
Esempio n. 2
0
        protected void InitializeImplementation()
        {
            isConnecting = true;

            var initializeOptions = new InitializeOptions()
            {
                ProductName    = epicProductName,
                ProductVersion = epicProductVersion
            };

            var initializeResult = PlatformInterface.Initialize(initializeOptions);

            // 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);
            }

            // 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         = epicProductId,
                SandboxId         = epicSandboxId,
                DeploymentId      = epicDeploymentId,
                ClientCredentials = new ClientCredentials()
                {
                    ClientId     = epicClientId,
                    ClientSecret = epicClientSecret
                },
                TickBudgetInMilliseconds = tickBudgetInMilliseconds
            };

            EOS = PlatformInterface.Create(options);
            if (EOS == null)
            {
                throw new System.Exception("Failed to create platform");
            }

            if (checkForEpicLauncherAndRestart)
            {
                Result result = EOS.CheckForLauncherAndRestart();

                // If not started through epic launcher the app will be restarted and we can quit
                if (result != Result.NoChange)
                {
                    // Log error if launcher check failed, but still quit to prevent hacking
                    if (result == Result.UnexpectedError)
                    {
                        Debug.LogError("Unexpected Error while checking if app was started through epic launcher");
                    }

                    Application.Quit();
                }
            }

            // 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)
                {
                    authInterfaceLoginCredentialId = "localhost:" + devAuthToolPort;
                    authInterfaceCredentialToken   = devAuthToolCredentialName;
                }

                // Login to Auth Interface
                Epic.OnlineServices.Auth.LoginOptions loginOptions = new Epic.OnlineServices.Auth.LoginOptions()
                {
                    Credentials = new Epic.OnlineServices.Auth.Credentials()
                    {
                        Type  = authInterfaceCredentialType,
                        Id    = authInterfaceLoginCredentialId,
                        Token = authInterfaceCredentialToken
                    },
                    ScopeFlags = Epic.OnlineServices.Auth.AuthScopeFlags.BasicProfile | Epic.OnlineServices.Auth.AuthScopeFlags.FriendsList | Epic.OnlineServices.Auth.AuthScopeFlags.Presence
                };

                EOS.GetAuthInterface().Login(loginOptions, null, OnAuthInterfaceLogin);
            }
            else
            {
                // Login to Connect Interface
                if (connectInterfaceCredentialType == Epic.OnlineServices.Connect.ExternalCredentialType.DeviceidAccessToken)
                {
                    Epic.OnlineServices.Connect.CreateDeviceIdOptions createDeviceIdOptions = new Epic.OnlineServices.Connect.CreateDeviceIdOptions();
                    createDeviceIdOptions.DeviceModel = deviceModel;
                    EOS.GetConnectInterface().CreateDeviceId(createDeviceIdOptions, null, OnCreateDeviceId);
                }
                else
                {
                    ConnectInterfaceLogin();
                }
            }
        }