Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
maverick89atwor's avatar
6 years ago

Fetching DLC download progress in Unity

Hi all,

I am trying to implement DLC download in Unity. These are my environment details: Unity: 2018.3.6f1, Oculus Integration 1.35.

I am able to get the list of DLC files that I've uploaded and also able to download them. However, I am not sure how to get the progress of the download. The documentation suggests subscribing to notifications. https://developer.oculus.com/documentation/platform/latest/concepts/dg-dlc/

Can anyone please share some sample code on how this can be done? I'll share what I have so far below.

Core.AsyncInitialize().OnComplete((Message InitMsg) =>
{
AssetFile.GetList().OnComplete((Message msg) =>
{
if (msg.IsError)
{
Debug.LogError("Error fetching DLC List: " + msg.GetError().Message);
}
else
{
var assetList = msg.GetAssetDetailsList();

foreach (var item in assetList)
{
Debug.Log("AssetID: " + item.AssetId);
Debug.Log("AssetType: " + item.AssetType);
Debug.Log("DownloadStatus: " + item.DownloadStatus);
Debug.Log("Filepath: " + item.Filepath);

//Download it
if (string.Equals(item.DownloadStatus, "available"))
{
AssetFile.DownloadById(item.AssetId).OnComplete((msg1) =>
{
if (msg1.IsError)
{
Debug.Log("Error downloading assetID: " + item.AssetId + " " + msg1.GetError().Message);
}
else
{
Debug.Log("Downloaded intiated at: " + msg1.GetAssetFileDownloadResult().Filepath);

var r = msg1.GetAssetFileDownloadUpdate();
}
});
}
else
{
Debug.Log("--------------------------------Asset ID: " + item.AssetId + " Status: " + item.DownloadStatus);
}
}
}
});
});

4 Replies

Replies have been turned off for this discussion
  • Doing this worked for me:

    Callback.SetNotificationCallback(Message.MessageType.Notification_AssetFile_DownloadUpdate, (Message<AssetFileDownloadUpdate> updateMsg) => {

    AssetFileDownloadUpdate downloadUpdate = updateMsg.GetAssetFileDownloadUpdate();

    if (downloadUpdate != null)
    {
    Debug.Log("UpdateStatus: " + downloadUpdate.AssetId + " : " + downloadUpdate.BytesTransferred + " / " + downloadUpdate.BytesTotal);
    }
    else
    {
    Debug.Log("Download Update is null");
    }
    });


    • Luis.Zan's avatar
      Luis.Zan
      Protege

      Thanks for the solution.

       

      One question: Should I add your code sample inside the body of DownloadById's OnComplete function or somewhere else?

    • npsoftware's avatar
      npsoftware
      Honored Guest

      Hi!
      I am not that familiar with Unity and Callbacks.

      I need to download the files, but I do not want to trigger 70 downloads at a time. So I made a loop and I am checking the status of the first file needed to download. (By asking for the list..)
      What I can see is, that the download is triggered 2x as even after 10 seconds, the GetAssetDetailsList() returns the status as "available" instead of "in-progress" in the third run, the file is downloaded and the status is then finished. My logic takes the next file in the list..
      Is it possible to trigger the download of the file and have some sort of event when finished, this would trigger another file to be downloaded..
      The snippet with the Callback does not work for me, as I do not know, where to place it correctly and what to include where.. Please advice. thanks