Load in from database instead of local.

Hi guys! I have this app which generates buttons, reads the names of the items on a local map and than names the buttons after those items and when you click the button the right item instantiates. Everything works fine, but now i need to change the local location to a database. And i have no idea where to start.

Code that works:

public class ReadBundles : MonoBehaviour
{

    int AmountOfBundles = 0;

    float testOffset = 0f; //for testing. (delete later)

    List<GameObject> FurnitureObjects = new List<GameObject>();

    string defaultLocation = "C:\\Unity\\Learning\\AssetBundles\\Windows\\meubeltjes";  //Location of bundles
    void Start()
    {

        string[] files = Directory.GetFiles(defaultLocation); //Zet het in een lijst

        foreach (string file in files)
        {

            if (file.Contains(".manifest")) continue; //Skip this file if it's a .manifest
            string assetBundlePath = file;

            //Bij een klik op de knop, laad de assetbundle in:
            AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath);
            foreach (string naam in assetBundle.GetAllAssetNames())
            {
                print(naam);
                GameObject prefab = assetBundle.LoadAsset<GameObject>(naam);
                FurnitureObjects.Add(prefab);

                assetBundle.Unload(false);
            }
        }
    }
    void OnGUI()
    {
        float yOffset = 0f;
        foreach (GameObject Asset in FurnitureObjects)
        {
            if (GUI.Button(new Rect(0, Screen.height - 100 - yOffset, 200, 100), Asset.name))
            {
                Instantiate(Asset, new Vector3(0 + testOffset, 0, 0), Quaternion.Euler(-50, -50, 0));
                print(Asset);
                testOffset--;
            }
            yOffset += 120;
        }
    }
}

For my new locations i can drop the files into: H:\companyname\App
When i do that, they’re available through: http://server.companyname.com/companyname/App/

I have no idea where to start since i already tried a lot of stuff.

Anyone please? I’m really stuck here :frowning:

I have no idea what you’re talking about. There’s a lot of stuff happening if you put stuff in a drive and they then are “are available through this url”. That sounds like some third party file server doing something.

You’re saying “a database”, and then you’re describing something completely different from a database.

I also have no idea what “a lot of stuff” is.

There’s no information here that gives anyone a chance to actually help you with anything.

Well, to answer your questions, Correct me if im wrong but an online url that contains assets,files etc etc is considered a database right? Thats where i need to get the assetbundles from.

Also with a lot of stuff i was refering to: i tried everything possible but i couldnt get it to work.

Further, i have no idea how it actually works since it’s from my internship company, but they gave me a drive and if i put assets or whatever in it, it’s availabe online through the url i provided. How it gets shouldn’t matter ,it’s about me trying to get the assets from the url. Thats all i asked, i just provided the extra information for the sake of it. To make it easyer to understand. It’s an online link available from anywhere in the world, if that matters.

Sorry if i things are /were unclear. Not sure what else i could say to make it more clear. It’s everything i got/need.

Short description: I have an URL that contains assets, i want to reach those assets and download them at runtime. I previously did it through a local map, but want to convert it to an online option now.

A database is a way to store data. It can be placed on the local computer or on a server. A url is an identifier for a thing on a network.

The reason I brought it up is that most people who want help with databased in Unity are people who store large amounts of eg. item data (think Diablo) in something like a MySQL database in their game directory, and want help transfering the data from there to their game.

If you want to grab files over the internet, you need to use the WWW class.

Here’s a modified version of the example:

public class ExampleClass : MonoBehaviour
{
    public string url = "http://server.companyname.com/companyname/App/myBundle.unity3d";
    IEnumerator Start()
    {
        WWW www = new WWW(url);
        yield return www;
        AssetBundle assetBundle = www.assetBundle;
        //use the bundle
    }
}

EDIT: Note that I haven’t actually tested that, it might not work. Give it a go.

1 Like