コード例 #1
0
        private void ConnectInterfaceLogin()
        {
            var loginOptions = new Epic.OnlineServices.Connect.LoginOptions();

            if (connectInterfaceCredentialType == Epic.OnlineServices.Connect.ExternalCredentialType.Epic)
            {
                Epic.OnlineServices.Auth.Token token;
                Result result = EOS.GetAuthInterface().CopyUserAuthToken(new Epic.OnlineServices.Auth.CopyUserAuthTokenOptions(), localUserAccountId, out token);

                if (result == Result.Success)
                {
                    connectInterfaceCredentialToken = token.AccessToken;
                }
                else
                {
                    Debug.LogError("Failed to retrieve User Auth Token");
                }
            }
            else if (connectInterfaceCredentialType == Epic.OnlineServices.Connect.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);
        }
コード例 #2
0
        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);
                }
            });
        }