Пример #1
0
        /// <summary>
        /// First frame
        /// </summary>
        void Start()
        {
            _ins = this;

            var initializeOptions = new InitializeOptions();

            initializeOptions.ProductName    = productName;
            initializeOptions.ProductVersion = productVersion;
            var result = PlatformInterface.Initialize(initializeOptions);

            // * Unity Editor becomes AlreadyConfigured after the second time.
            if (result == Result.Success
#if UNITY_EDITOR
                || result == Result.AlreadyConfigured
#endif
                )

            {
                var clientCredentials = new ClientCredentials();
                clientCredentials.ClientId     = clientId;
                clientCredentials.ClientSecret = clientSecret;

                var options = new Options();
                options.ClientCredentials = clientCredentials;
                options.ProductId         = productId;
                options.SandboxId         = sandboxId;
                options.DeploymentId      = deploymentId;

                m_platformInterface = PlatformInterface.Create(options);
                if (m_platformInterface == null)
                {
                    throw new Exception("Failed to create platform");
                }
            }
            else
            {
                throw new Exception("Failed to initialize platform:" + result);
            }

            Debug.Log($"Login:{result}");
        }
        /// <summary>
        /// 開始
        /// </summary>
        void Start()
        {
            _ins = this;

            var initializeOptions = new InitializeOptions();

            initializeOptions.ProductName    = settings.ProductName;
            initializeOptions.ProductVersion = settings.ProductVersion;
            var result = PlatformInterface.Initialize(initializeOptions);

            // ※ Unity Editor は AlreadyConfigured を飛ばさないとアプリが動かない。
            if (result == Result.Success || result == Result.AlreadyConfigured)
            {
                var clientCredentials = new ClientCredentials();
                clientCredentials.ClientId     = settings.ClientId;
                clientCredentials.ClientSecret = settings.ClientSecret;

                var options = new Options();
                options.ClientCredentials = clientCredentials;
                options.ProductId         = settings.ProductId;
                options.SandboxId         = settings.SandboxId;
                options.DeploymentId      = settings.DeploymentId;

                m_platformInterface = PlatformInterface.Create(options);
                if (m_platformInterface == null)
                {
                    throw new Exception("Failed to create platform");
                }
            }
            else
            {
                throw new Exception("Failed to initialize platform:" + result);
            }

            Debug.Log($"Init:{result}");
        }
        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);
                }
            });
        }
Пример #4
0
        /// <summary>
        ///     Initialize epic sdk.
        /// </summary>
        /// <returns>Returns back whether or not the engine initialized correctly.</returns>
        private void Initialize()
        {
            if (_enableDebugLogs)
            {
                DebugLogger.RegularDebugLog("[EpicManager] - Initializing epic services.");
            }

            InitializeOptions initializeOptions =
                new InitializeOptions {
                ProductName = _options.ProductName, ProductVersion = _options.ProductVersion
            };

            Result 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.
            bool isAlreadyConfiguredInEditor = Application.isEditor && initializeResult == Result.AlreadyConfigured;

            if (initializeResult != Result.Success && !isAlreadyConfiguredInEditor)
            {
                throw new Exception("[EpicManager] - Failed to initialize platform: " + initializeResult);
            }

            if (_enableDebugLogs)
            {
                LoggingInterface.SetLogLevel(LogCategory.AllCategories, _epicLoggingLevel);
                LoggingInterface.SetCallback(message => DebugLogger.EpicDebugLog(message));
            }

            ClientCredentials clientCredentials =
                new ClientCredentials {
                ClientId = _options.ClientId, ClientSecret = _options.ClientSecret
            };

            OnlineServices.Platform.Options options =
                new OnlineServices.Platform.Options
            {
                ProductId                = _options.ProductId,
                SandboxId                = _options.SandboxId,
                ClientCredentials        = clientCredentials,
                IsServer                 = false,
                DeploymentId             = _options.DeploymentId,
                TickBudgetInMilliseconds = (uint)_tickTime * 1000
            };

            Platform = PlatformInterface.Create(options);

            if (Platform != null)
            {
                if (_enableDebugLogs)
                {
                    DebugLogger.RegularDebugLog("[EpicManager] - Initialization of epic services complete.");
                }

                // Process epic services in a separate task.
                _ = UniTask.Run(Tick);

                // 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 == LoginCredentialType.Developer)
                    {
                        _authInterfaceLoginCredentialId = $"localhost:{_devAuthToolPort}";
                        _authInterfaceCredentialToken   = _devAuthToolName;
                    }

                    // Login to Auth Interface
                    LoginOptions loginOptions = new LoginOptions
                    {
                        Credentials = new OnlineServices.Auth.Credentials
                        {
                            Type  = _authInterfaceCredentialType,
                            Id    = _authInterfaceLoginCredentialId,
                            Token = _authInterfaceCredentialToken
                        },
                        ScopeFlags = AuthScopeFlags.BasicProfile | AuthScopeFlags.FriendsList | AuthScopeFlags.Presence
                    };

                    AuthInterface.Login(loginOptions, null, OnAuthInterfaceLogin);
                }
                else
                {
                    // Login to Connect Interface
                    if (_connectInterfaceCredentialType == ExternalCredentialType.DeviceidAccessToken)
                    {
                        CreateDeviceIdOptions createDeviceIdOptions =
                            new CreateDeviceIdOptions
                        {
                            DeviceModel = Application.platform.ToString()
                        };
                        ConnectInterface.CreateDeviceId(createDeviceIdOptions, null, OnCreateDeviceId);
                    }
                    else
                    {
                        ConnectInterfaceLogin();
                    }
                }

                OnInitialized?.Invoke();

                return;
            }

            DebugLogger.RegularDebugLog(
                $"[EpicManager] - Failed to create platform. Ensure the relevant {typeof(Options)} are set or passed into the application as arguments.");
        }
Пример #5
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();
                }
            }
        }