Downloadable Content Unity tutorial

Add downloadable content to your Unity Project in less than 30min in three steps:

  1. Create a file
  2. Download the file
  3. Mark the information

Create a file on the Dashboard


1. Visit your Gamedonia Dashboard.

2. Go to the section Data Storage > Files.

3. Add a new file just dragging the file to the slashed box in the right side of the screen.

4. Copy the Id to your clipboard, you will need it in few minutes.


File uploaded!

Easy peasy. Let's move on to the next step.

 

Download the file

Downloading a file using Gamedonia Download manager is in fact a 3 step process: adding files to the queue, asking the manager to start downloading files, and adding event listeners or callbacks to be notified when the download is complete.


1. Add the GamedoniaFiles script (located under Assets/Plugins/Gamedonia) to your Gamedonia game object.

You may have other scripts attached to Gamedonia GameObject, it's ok if you add them for other Gamedonia solutions.

2. Create a Download Button on your scene to test the download process.

3. On the OnClick method add the previous file to the queue and start the process:

if (GUI.Button (new Rect (80,205, 220, 50), "DOWNLOAD NOW!")) {
	// we can add as many files to download as we want.    
	GamedoniaFiles.Instance.AddDownloadWithFileId("FILE_ID");
	// after adding files to the download queue, we must start the download process    
	GamedoniaFiles.Instance.Begin();
}

4. On the Start() method of your scene add the following lines of code:

GamedoniaFiles.Instance.DownloadDidFinishLoading += (object sender, DownloadManagerEvent e) => {
	Debug.Log("File " + e.Download.FileId + " download finished correctly.");
};
GamedoniaFiles.Instance.DownloadDidStart += (object sender, DownloadManagerEvent e) => { 
	Debug.Log("Download start: " + e.Download.Filename);
};

These last lines make your scene show a debug line when a file finishes downloading or when the queue starts downloading.


File downloaded!

Nice! Now you've successfully downloaded the file, it's time to mark that info in the DB.

 

Save the information in the database

Now that we know how to start downloading the file and to detect when the file has finished downloading, you'll save that fact on the userstats collection.

In the Data Storage tutorial we created a userstats collection and we recovered it from the server side. You’re going to work on that piece of code.


1. On your Start() method change the following line:

GamedoniaFiles.Instance.DownloadDidFinishLoading += (object sender, DownloadManagerEvent e) => {
	Debug.Log("File " + e.Download.FileId + " download finished correctly.");
};

2. To this:

GamedoniaFiles.Instance.DownloadDidFinishLoading += (object sender, DownloadManagerEvent e) => {
	Debug.Log("File " + e.Download.FileId + " download finished correctly.");
	Dictionary<string,object> myStats = new Dictionary<string,object>();
	myStats["lastdownloadedfile"] = e.Download.FileId;
	GamedoniaData.Update("userstats", myStats, delegate (bool success, IDictionary data){       
		if (success){
		//TODO Your success processing
			Debug.Log("File information Stored successfully on the sever");
		} else {
		//TODO Your failure processing
			Debug.Log("Oooops! Something went wrong");
		}
	}, true);
};

You have downloaded a file to the device and saved the fact on the user collection.


Fact saved!

With all that information you can create new situations that can empower your game.

To see everything is stored correctly, visit the Object Browser in the Dashboard and find the information of that sample user. You're done!

Combination power

At this point, you could imagine some easy ways to combine all you've learnt from the tutorials.

Could you make DLC that will only be downloaded if the user purchases a certain product?

Of course you can! It shouldn't take more than 30 minutes if you have the product already created in the stores.

What's next?

All tutorials completed!

This is the last tutorial of this introductory series. We hope all six tutorials have been useful to get you started using Gamedonia Backend.

You can review any of them whenever you need:

  1. Facebook login
  2. Data storage
  3. Server Code
  4. Push notifications
  5. In-app purchases
  6. Downloadable content