An update on this, I successfully am using runtime generated signed urls to load asset bundles. Turns out was actually fairly simple. Here’s how I’m achieving this:
Step 1: Download list of all the signed urls
For us this is easy, we’re dumping all the bundles into 1 folder, so our server engineers setup a separate API call for me to get all signed urls for a folder in a Google Bucket. (game specific, aka not a unity call here)
Step 2: Create your own AssetBundleProvider
I simply found the Addressables default AssetBundleProvider
and AssetBundleResource
, copied them into my own ProjectAssetBundleProvider and made the following changes:
UnityWebRequest CreateWebRequest(IResourceLocation loc)
{
// This is your Step 1 which contains all of your signed urls
_assetBundleUrlResolver = AssetBundleUrlResolver.Instance;
// Get the signed url for this particular asset
// The default loc.InternalId here would be the original unsigned url (http://www.storage.google.com/yourbucket/blah.bundle)
string signedUrl = _assetBundleUrlResolver.GetSignedUrl(loc.InternalId);
if (m_Options == null)
return UnityWebRequestAssetBundle.GetAssetBundle(signedUrl);
// Note the rest of this is untouched from original CreateWebRequest function.
var webRequest = !string.IsNullOrEmpty(m_Options.Hash) ?
UnityWebRequestAssetBundle.GetAssetBundle(signedUrl, Hash128.Parse(m_Options.Hash), m_Options.Crc) :
UnityWebRequestAssetBundle.GetAssetBundle(signedUrl, m_Options.Crc);
if (m_Options.Timeout > 0)
webRequest.timeout = m_Options.Timeout;
if (m_Options.RedirectLimit > 0)
webRequest.redirectLimit = m_Options.RedirectLimit;
#if !UNITY_2019_3_OR_NEWER
webRequest.chunkedTransfer = m_Options.ChunkedTransfer;
#endif
if (m_ProvideHandle.ResourceManager.CertificateHandlerInstance != null)
{
webRequest.certificateHandler = m_ProvideHandle.ResourceManager.CertificateHandlerInstance;
webRequest.disposeCertificateHandlerOnDispose = false;
}
return webRequest;
}
The AssetBundleUrlResolver.GetSignedUrl function is simple, just doing a simple string.Contains search of the signed urls using the original url.
public string GetSignedUrl(string originalUrl)
{
// SignedUrls is simply list of string urls that were signed by the server.
foreach (var url in SignedUrls)
{
if (url.Contains(originalUrl))
return url;
}
return null;
}
Step 3: Set your bundle provider in Addressables window to be your own
I hope this helps someone!
EDIT: Btw, I’m also still using a remote catalog. Turns out it runs through my provider to get the remote catalog so it’s checking the signed url version of the catalog.