How can I make client to load different version of bundles? Let me give you a detailed example.
I have a dog image in the scene, I include this image as an Addressable asset, I put it in a group called “image”, and I labelled it “image”. I have a HTTP Server that stores the catalogs and bundles of the Addressable assets, and here is the folder hierarchy of my HTTP Server (I set the Bundle Naming to “No Hash”):
Android
–0.1
----catalog_2019.10.02.02.39.08.json
----catalog_2019.10.02.02.39.08.hash
----image_all.bundle
–0.2
----catalog_2019.10.02.02.41.13.json
----catalog_2019.10.02.02.41.13.hash
----image_all.bundle
iOS
–0.1
----catalog_2019.10.02.02.39.08.json
----catalog_2019.10.02.02.39.08.hash
----image_all.bundle
–0.2
----catalog_2019.10.02.02.41.13.json
----catalog_2019.10.02.02.41.13.hash
----image_all.bundle
ServerConfig.json
There are three things in the root of my HTTP Server, “Android” and “iOS” are two folders for the two mobile platforms, below them are the folders for each version that has been built, in this case, they are “0.1” and “0.2”. ServerConfig.json is the setting file of my HTTP Server, the client must download this file before download any bundle.
Here is my AddressableAssetSettings:
Everytime client starts the game, the “Downloader” class will download the ServerConfig.json file from server, then use JsonUtility to parse the text of this file into “ServerConfig”. Here is the definition of the ServerConfig.
[Serializable]
public struct ServerConfig
{
public List<VersionCodeToBundleCode> Dictionary;
}
[Serializable]
public struct VersionCodeToBundleCode
{
public string key;
public string value;
}
The Downloader class has a public static string variable named “TargetVersion”. When ServerConfig is read successfully, Downloader will pass “Application.version” into ServerConfig.Dictionary to try to find a VersionCodeToBundleCode with key that is equal to “Application.version”, then assign its value to the public static string variable “TargetVersion”. This way, I should be able to control what version of bundle each version of build should download. For example, build version 0.1 downloads bundle version 0.1 by default, I could let build version 0.1 download bundle version 0.2 instead by modifying the setting of ServerConfig.json.
All these steps are done before Addressables is initialized or loads anything.
Let’s say I target Android platform this time. First, I set the version code to 0.1, the sprite of the image is a dog, I build the Addressable assets, it generates a folder named “0.1” under “Android” which contains remote catalog and bundle file on my HTTP Server. In the meantime, there is a local catalog file generated under C:\Users\h3902340\Documents\MyProject\Library\com.unity.addressables\StreamingAssetsCopy\aa\Android
Then I set the version code to 0.2, I change the sprite of the image to a cat, I build the Addressable assets again, it generates a folder named “0.2” under “Android”, and it contains a catalog file and a bundle file as well, but because I have changed the sprite of the image, Addressable generate a new hash code for the image’s bundle, and the hash code of the local catalog file is also updated. Local catalog file now contains the hash code of the version 0.2, not 0.1.
Finally, I change the version code back to 0.1. When Unity output the apk, this local catalog is also included in the apk. When client runs the game, Unity first load the local catalog file that is in the apk, then try to find the bundle with the same hash code on my HTTP Server. Because the hash codes of the two versions of the bundles are different, if I let this build download the bundle version 0.1. It will try to find the bundle with the hash code that belongs to 0.2 in the folder 0.1, so it simply throws an error saying that it couldn’t find the bundle.
How can I make one version of build to download different versions of bundle while still maintaining all versions of bundles so that I could make it download any version of bundle at any time?
Please help me…