I am setting up a little game for fun as an opportunity to learn some of Unity’s newer technologies. At first I was going to use AssetBundles, but then found that they are being replaced by the Addressable’s system so I started looking into it. However, I’m having a hard time migrating what I was doing to this system.
What I had going on was a setup where I put each “World” as it’s own AssetBundle and grouped the levels within.
Long term goal with this would be some sort of system that allows for users to create their own levels and add them to the project (maybe through steam workshop or something, right now this is very much a hobby project)
Then at runtime I would load all of my asset bundles, roughly speaking, I had something akin to this:
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class SceneManager : MonoBehaviour
{
private List<string> blackList = new List<string> () { "NonLevelData" };
public Dictionary<string, List<string>> Levels = new Dictionary<string, List<string>> ();
private void Awake ()
{
string[] Bundles = AssetDatabase.GetAllAssetBundleNames ();
foreach(string bundleName in Bundles)
{
if (!blackList.Contains (bundleName))
{
string[] bundledLevels = AssetDatabase.GetAssetPathsFromAssetBundle (bundleName);
Levels[bundleName] = new List<string> (bundledLevels);
}
}
}
public void LoadData(GameObject root, string assetName, int levelNumber)
{
CleanupOldData (root);
GameObject data = AssetDatabase.LoadAssetAtPath<GameObject> (Levels[assetName][levelNumber]);
data.transform.SetParent (root.transform);
}
}
So when I was migrating to an addressable system, I thought: ok, so I can treat each world as it’s own Addressable Group, load the group and find what all of it’s keys are, and that can be used to populate my world/level select menu.
However, as far as I can see, that isn’t what groups are for. Is there any way for me to do something like what I’m doing? Trying to learn the right way to do this in a world with very barebones documentation.