Downloadable Content

Host files in the cloud with a resumable storage system

Manage all the downloadable content for your game in a fast and easy way. Gamedonia Files allows you to download files for your game, pause the downloads, and resume them whenever you want.

Gamedonia calls will only work under a valid Gamedonia session. This means there needs to be a user logged in with Gamedonia. The main exceptions are, for obvious reasons, creating and logging users in.

Before downloading a file you need to upload it at the Gamedonia Dashboard at the Data Storage > Files section.

Once you have uploaded a file to the Dashboard, you will need to remember its FileId, given by the Dashboard, and use it from your code to download that specific file. GamedoniaFiles is only responsible for downloading files. When the file has been downloaded, the game client will be responsible for any file operation on it.

The location of the downloaded file will depend on the platform the game is running on. When the application goes to the background, all downloads are paused and resumed when the application comes to the foreground.

Events

These are the Gamedonia file events that will trigger under specific circumstances:

  • DownloadDidFinishLoading: A file finished downloading correctly.
  • DownloadDidFail: A file failed to download.
  • DownloadDidReceiveData: A download received a new packet of data.
  • DownloadDidStart: A new file started downloading.
  • DownloadDidFinishLoadingAll: All files finished downloading.
  • DownloadDidStartLoadingAllForManager: All files in the pending queue started downloading.

Data Structures

These are the data structures of the Download Manager:

Download

  • FileId: The provided file id of the download.
  • Downloading: Returns whether the file is currently downloading or not.
  • ExpectedContentLength: The size of the file to download from the server.
  • ProgressContentLength: The current downloaded amount of the file.
  • Filename: The name of the file including the path where the file is stored.
  • Url: URL path of the file in the server.
  • Error: Error number if an error occurs with this download.

DownloadManagerEvent

  • download: The download raises an event.
  • errorCode: If it was an error event, it contains the code of the error.

Usage

Unity configuration

Before you start coding a file download in Unity, you need to add the GamedoniaFiles script to your Gamedonia game object. See the next screenshot on how your Game object should look like with this script ( It's possible that you have other scripts attached to the Gamedonia game object. It's ok, you may need them for other Gamedonia features). The script is located under Assets/Plugins/Gamedonia.

Code example

Here is a code snippet that shows how to code a basic file downlaod process:

// attach event handlers on the script Start() function.
public void Start()
{
    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);
    };
}

public void DownloadClick()
{
    // we can add several files to download
    GamedoniaFiles.Instance.AddDownloadWithFileId("FILE_ID");
    // after adding files to the download list, we must start the download.
    GamedoniaFiles.Instance.Begin();
}

public void PauseDownloadsClick()
{
    // this will pause all downloads. Paused download will not resume automatically
    GamedoniaFiles.Instance.Pause();
}

public void ResumeDownloadsClick()
{
    GamedoniaFiles.Instance.Resume();
}
// need to add this imports in the import section
import com.gamedonia.sdk.dlc.DownloadEvent;
import com.gamedonia.sdk.DownloadFiles;

// then we can add the event listeners for every event
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOAD_DID_FINISH_LOADING, onDownloadFinish);
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOAD_DID_FAIL, onDownloadFail);
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOAD_DID_RECEIVE_DATA, onDownloadUpdate);
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOAD_DID_START, onDownloadStart);
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOADMANAGER_DID_FINISH_LOADING_ALL, onAllDownloadFinish);
GamedoniaFiles.instance.addEventListener(DownloadEvent.DOWNLOADMANAGER_DID_START_LOADING_ALL, onAllDownloadStart);

// example of handler event:
private function onDownloadFinish(downloadEvent:DownloadEvent):void {
    trace("File " + downloadEvent.download.fileId + " download finished correctly.");
}

private function onDownloadStart(downloadEvent:DownloadEvent):void {
    trace("Download start: " + downloadEvent.download.filename);
}
// we can add as much files to download as we want.
GamedoniaFiles.instance.addDownloadWithFileId("FILE_ID");
// after adding files to the download list, we must start the download.
GamedoniaFiles.instance.start();

// this will pause all downloads. Paused download will not resume automatically
GamedoniaFiles.instance.pause();
// resume previously paused downloads.
GamedoniaFiles.instance.resume();