Uploading and Loading AssetBundles

From Graal Bible
Revision as of 04:42, 25 May 2021 by JimmyAkl (talk | contribs) (Created page with "Up until now, we have been using PrimitiveTypes for our GameObjects. In this section, we will start using different GameObjects. I will go over how to upload your assetbundle...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Up until now, we have been using PrimitiveTypes for our GameObjects.

In this section, we will start using different GameObjects. I will go over how to upload your assetbundles containing all your customized prefabs to the server, how to load, instantiate, and manipulate them.

Uploading AssetBundles[edit | edit source]

You will need to have Unity installed for this part.

You will also need to have the “Quattro3D- Unity Project for bundle asset creation.7z" Unity project installed from the google drive.

I will be going through an example, demonstrating how it’s done.

Begin by choosing what prefabs you want to upload. In our case, I will upload a bomb and a character prefab, which I already have ready in a different project.

Note: Remember you cant put scripts in your asset bundles.

Open the Unity project downloaded (“Quattro3D- Unity Project for bundle asset creation.7z"). This project contains a script that builds the assetbundles and puts them in the Assets/StreamingAssets folder, which will hold all our uploadable files.

In the Assets folder, I will create a new folder and name it Example.

Next I will import my prefabs;

In the top left menu hit (Assets>Import New Asset/Import Package). Go to the location of your prefabs and select them and press Import.

Now that we’ve imported our assets, we’ll create an assetbundle to be uploaded to the server;

Using the Unity way of creating assetbundles by flagging the prefabs:

Select all the prefabs in the asset folder, the Inspector Window should open. At the bottom right of your screen, in the Inspector Window, create or select an existing name for your assetbundle.

The bundle will embed all the assets/prefabs under that flagged directory. You can of course put multiple prefabs/files/subdir...etc inside an asset bundle.


Now build your asset by pressing on BuildAssetBundles>PackagesBuilder>buildAssetBundles in that project.

The built asset will be stored in the downloaded Unity Project in “Quattro3D- Unity Project for bundle asset creation\Assets\StreamingAssets”

The file that we’ll use to upload to graal should end with “.txt”

Finally to upload the asset to the server, login on rc, go to levels/assetbundles and drop the “.txt” file there.

It should be automatically downloaded to /Users/”yourusername”/AppData/LocalLow/Graal Worlds/Levels3d/assetbundles

You’re strongly advised to generate a unitypackage too when you generate an asset bundle and upload it to the server, so that everyone can rebuild the bundle on every platform.

To view your asset and your prefabs, login to the Client, hit F10 to open the Bundle Explorer and search for your asset name.

ClientSide Loading Assets[edit | edit source]

Now to load your prefabs using GraalScript; to your code add the following:

You can use the Bundle Explorer (F10) to copy the path of the AssetBundle.

findplayer("Graal5918039").addweapon(this.name);

//#CLIENTSIDE

function onCreated() {

  Quattro::AssetManagement::LoadAssetBundle("documentationexample");

}

function onAssetBundleDownloaded(bundlename) {

  if (bundlename == "documentationexample") {

    player.chat = "example loaded";

    temp.prefab = GameObject::createfromassetbundle("documentationexample", "assets/example/bomb.prefab");

    this.bomb = Object::Instantiate(Type::GameObject, temp.prefab);

    this.bomb.transform.position = Vector3::Create(player.x + 5, player.z, player.y);

  }

}