Enter The Mansion Card Assets

The next step for Enter The Mansion – my procedural card based adventure game – was to convert the sets of data for each card into assets that can be authored outside of C#.

I inherited from scriptable object for my card asset, which let me generate new instances of the object as resources in the asset database.

using UnityEngine;

[CreateAssetMenu(fileName = "Data", menuName = "ScriptableObjects/Card_Asset", order = 1)]
public class Card_Asset : ScriptableObject
{
    public string ID;
    public string title;
    public string body;
    public string body2;
    public string choice;
}

It was then fairly simple to get all the assets in the cards folder using the AssetDatabase functions which fits into what I’d already written to pick a random card and populate the UI with its information.

    void PopulateList()
    {
        string[] assetNames = AssetDatabase.FindAssets("", new[] { "Assets/Cards" });
        foreach (string name in assetNames) {
            var assetPath = AssetDatabase.GUIDToAssetPath(name);
            var card = AssetDatabase.LoadAssetAtPath<Card_Asset>(assetPath);
            cards.Add(card);
        }
    }

This is a step in the right direction, however the editor for the asset remains unfriendly to the user. There’s not enough room in the box to type out a whole paragraph, and there’s no spellcheck. The ID field also needs to either be generated by the system or forced to be unique. Thinking about how to make this useable is the next step!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s