docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Installing the Game Foundation package

    1. In the Unity Editor, open the Package Manager window (menu: Window → Package Manager).

      Open the Package Manager

    2. In the Package Manager window, click Advanced and make sure that Show preview packages is enabled.

      Open the Package Manager

    3. In the list of packages on the left, find Game Foundation and select it.

      Open the Package Manager

    4. In the upper-right (bottom-right on some versions of Unity), click on the Install button.

      Open the Package Manager Open the Package Manager

    5. After installation, the Game Foundation menu items and editor windows are available in your Unity project in the Window menu.

      Open the Package Manager

    Quick start

    Before Game Foundation can be used during runtime, it has to be initialized in your code. The following is an example of initializing Game Foundation with the Awake method of a MonoBehaviour.

    using UnityEngine;
    using UnityEngine.GameFoundation;
    
    public class MyGameManager : MonoBehaviour
    {
        void Awake()
        {
            // this data layer will not save any data, it is usually used for examples or tests
            MemoryDataLayer dataLayer = new MemoryDataLayer();
    
            // initialize Game Foundation for runtime access
            GameFoundation.Initialize(dataLayer);
        }
    }
    

    When you initialize Game Foundation, all managers, including InventoryManager, WalletManager, StatManager and TransactionManager will be initialized and ready to use.

    • Tip: To verify that Game Foundation is working and installed correctly, please check the IsInitialized property on any Game Foundation manager.
    using UnityEngine;
    using UnityEngine.GameFoundation;
    
    public class MyGameManager : MonoBehaviour
    {
        void Awake()
        {
            // this data layer will not save any data, it is usually used for examples or tests
            MemoryDataLayer dataLayer = new MemoryDataLayer();
    
            // initialize Game Foundation for runtime access
            GameFoundation.Initialize(dataLayer);
    
            // verify that the manager is initialized
            if (InventoryManager.IsInitialized)
            {
                Debug.Log("Game Foundation is installed and ready!");
            }
            else
            {
                Debug.LogError("Error:  Game Foundation was unable to initialize.  Please check online help or docs for more information.");
            }
        }
    }
    

    After implementing the above code, when you press Play you will see that Game Foundation has been successfully installed and ready to build your game!

    Display Name and Id

    Now you can head over to one of our Tutorials for more information:

    1. Creating an Inventory Item Definition
    2. Playing with items at runtime
    3. Creating a Currency
    4. Playing with currencies at runtime
    5. The Debugger window
    6. Adding static properties with details
    7. Adding mutable properties with Stats
    8. Playing with stats at runtime
    9. Creating a Virtual Transaction
    10. Playing with virtual transaction at runtime
    11. Using IAP Transactions
    12. Filtering transactions with Stores

    Also, please visit Known Issues if you need further assistance.

    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)