Step 4 - Adding Content

Overview

The purpose of this guide is for game makers to add new content of an existing type provided by Beamable.

Here is everything needed to use the Content Manager Tool WindowTool Window - A group of related Beamable editing functionality for game makers in the "Beamable SDK for Unity". Or watch this video.

Steps

Follow these steps to get started.

Adding Content of Existing Type

Here is the process to add a new object with existing content type of "Item".

Step

Detail

  1. Open the Content Manager Window

• Unity → Window → Beamable → Open Content Manager

  1. Create the "Item" content
• Select the content type in the list • Press the "Create" button • Populate the content name
  1. Open the Unity Project Window

• Unity → Window → General→ Project

  1. Select the "Item" asset

• Search by the name given in step #3
• View the asset in the Unity Inspector Window

  1. Populate all data fields

Note: The icons can be set to any valid Unity’s Addressable object.

  1. Save the Unity Project

• Unity → File → Save Project

Best Practice: If you are working on a team, commit to version control in this step.

  1. Publish the content

• Press the "Publish" button in the Content Manager Window

Code

📘

Beamable SDK Examples

This and all examples are available for download at GitHub.com/Beamable_SDK_Examples

In this snippet, the Item reference is resolved for use at runtime. There are 2 different methods for resolving content. Both are shown here for comparison. In production, choose whichever one method works best for the needs of the project.

See Content » Code (ContentLink vs ContentRef) for more info.

using System;
using Beamable.Common.Content;
using Beamable.Common.Inventory;
using UnityEngine;

namespace Beamable.Examples.Services.ContentService
{
    [Serializable]
    public class ItemLink : ContentLink<ItemContent> {}
    
    /// <summary>
    /// Demonstrates <see cref="ContentService"/>.
    /// </summary>
    public class ContentServiceExistingExample : MonoBehaviour
    {
        //  Fields  ---------------------------------------
        [SerializeField] private ItemLink _itemLink;
        [SerializeField] private ItemRef _itemRef;

        private ItemContent _itemContentFromLink = null;
        private ItemContent _itemContentFromRef = null;
        
        //  Unity Methods  --------------------------------
        protected void Start()
        {
            Debug.Log($"Start()");
            
            SetupBeamable();
        }

        //  Methods  --------------------------------------
        private async void SetupBeamable()
        {
            IBeamableAPI beamableAPI = await Beamable.API.Instance;
      
            Debug.Log($"beamableAPI.User.id = {beamableAPI.User.id}");
            
            await _itemLink.Resolve()
                .Then(content =>
                {
                    _itemContentFromLink = content; 
                    Debug.Log($"_itemContentFromLink.Resolve() Success! " +
                              $"Id = {_itemContentFromLink.Id}");
                })
                .Error(ex =>
                {
                    Debug.LogError($"_itemContentFromLink.Resolve() Error!"); 
                });
            
            await _itemRef.Resolve()
                .Then(content =>
                {
                    _itemContentFromRef = content; 
                    Debug.Log($"_itemContentFromRef.Resolve() Success! " +
                              $"Id = {_itemContentFromRef.Id}");
                    
                }).Error(ex =>
                {
                    Debug.LogError($"_itemContentFromRef.Resolve() Error!"); 
                });
        }
    }
}

Inspector

The Example in the Unity Inspector WindowThe Example in the Unity Inspector Window

The Example in the Unity Inspector Window

Adding Content of Custom Type

Here is the process to add a new object with custom content type of "Armor".

Step

Detail

  1. Create Armor

• See the Armor.cs snippet below

  1. Add Armor

• Repeat steps 1-7 from the section above for the "Armor" content type

Code

📘

Beamable SDK Examples

This and all examples are available for download at GitHub.com/Beamable_SDK_Examples

In this snippet, the custom Armor item type is created.

using Beamable.Common.Content;
using Beamable.Common.Inventory;

namespace Beamable.Examples.Services.ContentService
{
    [ContentType("armor")]
    public class Armor : ItemContent
    {
        public string Name = "";
        public int Defense = 0;
    }
}

In this snippet, the Armor reference is resolved for use at runtime. There are 2 different methods for resolving content. Both are shown here for comparison. In production, choose whichever one method works best for the needs of the project.

See Content » Code (ContentLink vs ContentRef) for more info.

using System;
using Beamable.Common.Content;
using Beamable.Common.Inventory;
using UnityEngine;

namespace Beamable.Examples.Services.ContentService
{
    [Serializable]
    public class ArmorLink : ContentLink<Armor> {}
    
    [Serializable]
    public class ArmorRef : ContentRef<Armor> {}

    
    /// <summary>
    /// Demonstrates <see cref="ContentService"/>.
    /// </summary>
    public class ContentServiceCustomExample : MonoBehaviour
    {
        //  Fields  ---------------------------------------
        [SerializeField] private ArmorLink _armorLink;
        [SerializeField] private ArmorRef _armorRef;

        private Armor _armorFromLink = null;
        private Armor _armorFromRef = null;
        
        //  Unity Methods  --------------------------------
        protected void Start()
        {
            Debug.Log($"Start()");
            
            SetupBeamable();
        }

        //  Methods  --------------------------------------
        private async void SetupBeamable()
        {
            IBeamableAPI beamableAPI = await Beamable.API.Instance;
      
            Debug.Log($"beamableAPI.User.id = {beamableAPI.User.id}");
            
            await _armorLink.Resolve()
                .Then(content =>
                {
                    _armorFromLink = content; 
                    Debug.Log($"_armorFromLink.Resolve() Success! " +
                              $"Id = {_armorFromLink.Id}");
                })
                .Error(ex =>
                {
                    Debug.LogError($"_armorFromLink.Resolve() Error!"); 
                });
            
            await _armorRef.Resolve()
                .Then(content =>
                {
                    _armorFromRef = content; 
                    Debug.Log($"_armorFromRef.Resolve() Success! " +
                              $"Id = {_armorFromRef.Id}");
                    
                }).Error(ex =>
                {
                    Debug.LogError($"_armorFromRef.Resolve() Error!"); 
                });
            

        }
    }
}

Inspector

The Example in the Unity Inspector WindowThe Example in the Unity Inspector Window

The Example in the Unity Inspector Window

Advanced

This section contains any advanced configuration options and workflows.

See Content » Code (Advanced) for more info.

Content Validation

Beamable supports optional validation for each field of a ContentObject subclass. This allows game makers to easily build tooling to facilitate team members with their content administration tasks.

See Adding Content Validation for more info.


Did this page help you?