Exemplo n.º 1
0
        /// <summary>
        /// Initialize Game Foundation.
        /// Called at startup as well as when reinitializing.
        /// </summary>
        private IEnumerator InitializeGameFoundation()
        {
            // Disable all buttons while initializing
            findCoinsButton.interactable = false;
            dropCoinsButton.interactable = false;

            // - Initialize must always be called before working with any game foundation code.
            // - GameFoundation requires an IDataAccessLayer object that will provide and persist
            //   the data required for the various services (Inventory, Wallet, ...).
            // - For this sample we don't need to persist any data so we use the MemoryDataLayer
            //   that will store GameFoundation's data only for the play session.
            var initDeferred = GameFoundationSdk.Initialize(_persistenceDataLayer);

            // Wait for initialization to complete, then continue
            yield return(initDeferred.Wait());

            if (initDeferred.isFulfilled)
            {
                OnGameFoundationInitialized();
            }
            else
            {
                OnGameFoundationException(initDeferred.error);
            }

            // Release deferred promise handler.
            initDeferred.Release();
        }
Exemplo n.º 2
0
        private IEnumerator Start()
        {
            PersistenceDataLayer dataLayer = new PersistenceDataLayer(
                new LocalPersistence(
                    localPersistenceFilename,
                    new JsonDataSerializer()
                    ),
                currentCatalog
                );

            // Asynchronous
            using (Deferred initialization = GameFoundationSdk.Initialize(dataLayer))
            {
                if (!initialization.isDone)
                {
                    yield return(initialization.Wait());
                }

                if (!initialization.isFulfilled)
                {
                    Debug.LogError(initialization.error);

                    yield break;
                }
            }
        }
Exemplo n.º 3
0
        private void OnDestroy()
        {
            if (!GameFoundationSdk.IsInitialized)
            {
                Debug.Log("Game Foundation is not initialized.");
                return;
            }

            GameFoundationSdk.Uninitialize();
        }
        public void Load()
        {
            GameFoundationSdk.Uninitialize();

            if (_dataLayer?.persistence == null)
            {
                Debug.LogError("DataLayer is null.");
                return;
            }

            Deferred def = GameFoundationSdk.Initialize(_dataLayer);

            if (def.isDone)
            {
                if (def.isFulfilled)
                {
                    _onInitOrLoadComplete?.Invoke();
                    OnInitOrLoadComplete?.Invoke();
                }
                else
                {
                    Debug.LogError(def.error.Message);
                    _onInitOrLoadFail?.Invoke();
                }
            }
            else
            {
                IEnumerator Routine(Deferred aDef)
                {
                    yield return(aDef.Wait());

                    if (aDef.isFulfilled)
                    {
                        _onInitOrLoadComplete?.Invoke();
                        OnInitOrLoadComplete?.Invoke();
                    }
                    else
                    {
                        Debug.LogError(aDef.error.Message);
                        _onInitOrLoadFail?.Invoke();
                    }
                }

                StartCoroutine(Routine(def));
            }
        }
Exemplo n.º 5
0
    public IEnumerator InitializeGameFoundation()
    {
        var initDeferred = GameFoundationSdk.Initialize(_persistenceDataLayer);

        // Wait for initialization to complete, then continue
        yield return(initDeferred.Wait());

        if (initDeferred.isFulfilled)
        {
            OnGameFoundationInitialized();
        }
        else
        {
            OnGameFoundationException(initDeferred.error);
        }

        // Release deferred promise handler.
        initDeferred.Release();
    }
        public void Initialize()
        {
            var serializer  = new JsonDataSerializer();
            var persistence = new PlayFabPersistence(_key, serializer);

            _dataLayer = new PersistenceDataLayer(persistence);

            Deferred def = GameFoundationSdk.Initialize(_dataLayer);

            if (def.isDone)
            {
                if (def.isFulfilled)
                {
                    _onInitOrLoadComplete?.Invoke();
                    OnInitOrLoadComplete?.Invoke();
                }
                else
                {
                    Debug.LogError(def.error.Message);
                    _onInitOrLoadFail?.Invoke();
                }
            }
            else
            {
                IEnumerator Routine(Deferred aDef)
                {
                    yield return(aDef.Wait());

                    if (aDef.isFulfilled)
                    {
                        _onInitOrLoadComplete?.Invoke();
                        OnInitOrLoadComplete?.Invoke();
                    }
                    else
                    {
                        Debug.LogError(aDef.error.Message);
                        _onInitOrLoadFail?.Invoke();
                    }
                }

                StartCoroutine(Routine(def));
            }
        }