Unity

Ask tech team
From QuickBlox Developers (API docs, code samples, SDK)
Jump to: navigation, search

Contents

Introduction

QuickBlox’s Unity Cloud Asset Manager consists of two parts: an editor extension, and application access of assets.

The idea behind the editor extension is to allow QuickBlox users to create assets in Unity and then easily upload them to the cloud. This allows teams of developers and designers to share and organize the assets of complex projects.

Users can design their applications so that they download any assets from cloud storage that are addressed to the app. This means that apps can be updated with new assets without requiring users to update the whole app through AppStore or Google Play.

Create your QuickBlox account

Go to admin.quickblox.com and click on Register at the top or just follow the link admin.quickblox.com/register.

Register your account.jpg


Note: you must accept the Terms and Conditions in order to proceed. To read the Terms and Conditions just follow the link next to the checkbox.

Click on the Sign Me Up button at the bottom of the page. You will receive a confirmation e-mail shortly after. Confirm your registration by following the link in the e-mail.

Registration confirmation.jpg


Congratulations, you have registered with QuickBlox!

Sign in to the admin panel

Follow the link admin.quickblox.com/signin, enter your Login and Password and click on the Sign In Now button.

Log In.jpg

Create an app in the admin panel

Upon sign in, you will see the main page where you can find the "Add new application" button. Click on it.

Add new app 1.jpg


The next step is to add a new application, by clicking the ‘Add new application’ button. This will take you to a form where you need to enter information such as the title of your app, its website, type (game, fun, office, productivity, etc.) and description.

Note: the fields ‘Title’ and ‘Type’ are mandatory, while the others are optional.

Add new app form 1.jpg


When the form is complete, click on the ‘Add’ button at the bottom. The app will now appear in your list of apps.

List of apps.jpg


Click on app title to view/edit its credentials.

You will see the auto-generated values of theapplication id, your account id, authorization key and authorization secret. These are important - your app needs to use these credentials so that server knows who's there.

Note:You will also see icons for the modules: Location, Users, Message, Content, Custom Objects, Ratings, Chat - feel free to click on them and explore the other features available for your app.

Info about app.jpg

Using in Unity

Download Unity package

After importing the package, in the Unity editor menu bar there will be a new item called ‘CloudStorage’.

Cloud storage.jpg


And in the Project window there will be two new folders:QuickBlox and Sample.

Project window.jpg

The QuickBlox folder contains the SDK for incorporation of the QuickBlox service. It must be located in the Assets folder’s root, as shown on the screenshot above. The folder should not be moved, renamed or deleted. The sample folder contains a demo scene which will help you become familiar with how the cloud storage works. You may safely remove the sample folder from the project later on.


Connection

In order to use the cloud storage service, some settings must first be defined. To do this, first go to the Unity menu and, under CloudStorage, select Settings.

Settings.jpg


This will bring up the Settings window that looks something like this:

Settings details.jpg


The first parameter to change is the Build target, which specifies the target platform for which the assetbundles will be created.

The next are the application connection parameters: Application id,Authentication key, and Authentication secret. These parameters are required in order to connect to QuickBlox storage. The information in the screenshot below may be obtained from the QuickBlox admin panel when checking your app settings (see page, above):

Qb app settings.jpg


Use the information from the admin panel to fill the relevant fields in the ‘Application Connection Parameters’ section in the Settings window. The connection should be checked by clicking the ‘Check Connection’ button. If all the parameters are filled correctly, and an Internet connection is available, you should get a ‘Connection status: OK’ response from the server, similar to this:

Settings filled.jpg


After a successful connection, click the ‘Save settings’ button and you’re done here. You don’t need the Settings window anymore, unless, for example, you need to change the connection parameters in order to change app credentials, etc. Connection settings for the client application are recorded in the source code of the client application in the fields of QuickBloxConectionSettings class:

Project window 2.jpg


Unity source.jpg


Sign in

All QuickBlox services are carried out on behalf of a specified user. Users need to be signed in before working the editor and/or client app.

First, a new user must be created. This operation is available in the QuickBlox admin panel under the Users section of the previously created application.

Qb app users.jpg


A new user should be created on whose behalf assets will be uploaded to the server. This can be done by clicking the Add new user’ button.

Qb app addUser.jpg


Once the new User is created, go back to Unity’s menu bar, under the CloudStorage menu, click Login, to bring up a login window where the new User’s login and password can be typed in order for them to sign in.

Login menu.jpg


Login menu 2.jpg


If the login and password were entered correctly, and an internet connection is available, you’ll get a response similar to this:

Login menu 3.jpg


Otherwise, the console will display an error message:

Login menu error.jpg


In the client application, the user sign in is carried out using the method Connect (UserName, Password) of theQuickBloxConnection class.

More detailed information can be found by examining the sample in Main.cs class.

Project window 3.jpg


Here is a snippet of the listing that demonstrates the connection principle on the client side.

/// <summary>
/// Login from QuickBlox.
/// </summary>
private string UserName = "****";
 
/// <summary>
/// Password from QuickBlox.
/// </summary>
private string Password = "******";	
 
void Awake()
{	
	//Load all already downloaded elements (game objects and textures)
	PreLoadFiles(ref this.Files);				
 
//Connect with QuickBlox by using Login/Password of any User you have created.
	QuickBloxConection.Current.Connect(this.UserName, this.Password);	
}
 
IEnumerator Start()
{         
	//Null unitll connection is established
	while(!QuickBloxConection.Current.IsDone) yield return null;				
}

Work with the repository

Once the connection and sign-in settings are established the cloud file storage can be used and any assets can now be uploaded to the repository from the Assets folder.

For convenient access to assets, when using the client application, it is better to upload asset bundles to the repository.

Note: asset bundles can only be created in Unity Pro.

Before creating an asset bundle, a target platform should be chosen.

To create an asset bundle within the Unity editor, you should choose a prefab from which you want to create an asset bundle.

Project window 4.jpg

First click on the CloudStorage menu item, and then on ‘Create Asset Bundle’.

Project window 5.jpg

A window will pop up showing the progress of the creation of the asset bundle.

Assetbundle building.jpg

Once the asset bundle is created it will appear in the ‘AssetBundles’ folder.

Project window 6.jpg

It is possible to create several asset bundles at once using group selection.

To upload an asset bundle to cloud storage, click on the CloudStorage menu and then on the submenu item ‘Upload’.

Project window 7.jpg

Note: to complete the operation successfully, you need to sign in as a specified user. Otherwise the console will display an error similar to this one:

Error message.jpg

Uploading files to the server can be done using the group selection as well as asset bundle creation. During the upload you will see a window showing the name of the file currently being uploaded and the progress of the upload.

Uploading.jpg


As mentioned above it is possible to upload any asset to the server, as well as asset bundles. As an example, let’s choose a texture as the asset to be uploaded:

Project window 8.jpg


We may upload it to the server by selecting CloudStorage in the Unity menu, and then Upload.

Uploading 2.jpg


You can manage the repository in both the Unity editor and the QuickBlox admin panel, in the section Content -> Files.

To manage file storage in the Unity editor, click on CloudStorage in the Unity menu, and then on Storage.

Project window 9.jpg


In the Storage window there will be a list of all the files that were uploaded to the server by the current user. (Note: to see the file list you must be signed in.)

Files list.jpg


In the editor, file information may be viewed; files can be saved to the file system, or deleted from the repository.

Downloaded files are moved to the ‘StreamingAssets’ folder.

Note: Once a file is deleted from cloud storage, it cannot be restored.

Sample

Here is a simple code snippet showing how to incorporate asset retrieval from QuickBlox storage into an app:

//Connect with QuickBlox by using Login/Password of any User you have created.
QuickBloxConection.Current.Connect(****, ****)
 
//Check connection
QuickBloxConection.Current.IsDone
 
//Send a command to download the list of available for current user files.
QuickBloxBlobManager.Current.Update()
 
//Check if this list has been downloaded
QuickBloxBlobManager.Current.IsListLoaded
 
//Get the list of available blobs
List<Blob> blobsList = QuickBloxBlobManager.Current.Blobs
 
//Take some blob from the list
Blob file = blobsList[i]
 
if (file.IsDownloaded)
{
//Do something with downloaded object
}
else
{
if (file.IsDownloading)
	//Check current progress in %
Debug.Log(file.Progress)
else
//Send a command to start to download current blob
file.Download()
}

If you need a good sample of working with the file storages on the client side open the Main.cs file in the Scripts folder.