Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add version for shared assets bundles #3096

Merged
merged 5 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void LoadFromWebWithOldPath()
Assert.That(intent.CommonArguments.URL, Is.EqualTo($"http://www.fakepath.com/{version}/abcd"));
Assert.That(intent.cacheHash, Is.Not.Null);
}

[Test]
public void LoadFromWebWithNewPath()
{
Expand Down Expand Up @@ -102,7 +102,7 @@ public void FailIfAbsentInManifestOldHash()
Assert.That(result.Asset, Is.Null);
Assert.That(result.Exception, Is.TypeOf<ArgumentException>().Or.InnerException.TypeOf<ArgumentException>());
}

[Test]
public void FailIfAbsentInManifestNewHash()
{
Expand All @@ -120,5 +120,60 @@ public void FailIfAbsentInManifestNewHash()
Assert.That(result.Asset, Is.Null);
Assert.That(result.Exception, Is.TypeOf<ArgumentException>().Or.InnerException.TypeOf<ArgumentException>());
}

[Test]
public void ReturnDifferentCacheValuesForDifferentVersions()
{
//First, we simulate creation of a scene and the resolving of one asset budnle
string version = "v" + SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH;
sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024"));
var intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB);
Entity entity1 = world.Create(intent, new StreamableLoadingState());
system.Update(0);
intent = world.Get<GetAssetBundleIntention>(entity1);
string firstStandardURL = intent.CommonArguments.URL;
string firstCacheableHash = intent.CommonArguments.GetCacheableURL();
world.Destroy(entity1);

//Now, we simulate another scene, that has a different asset bundle version
version = "v" + (SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH + 1);
sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024"));
intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB);
Entity entity2 = world.Create(intent, new StreamableLoadingState());
system.Update(0);
intent = world.Get<GetAssetBundleIntention>(entity2);
string secondStandardURL = intent.CommonArguments.URL;
string secondCacheableHash = intent.CommonArguments.GetCacheableURL();

Assert.AreNotEqual(firstStandardURL, secondStandardURL);
Assert.AreNotEqual(firstCacheableHash, secondCacheableHash);
}

[Test]
public void ReturnSameCacheValuesForScenes()
{
//First, we simulate creation of a scene and the resolving of one asset budnle
string version = "v" + SceneAssetBundleManifest.ASSET_BUNDLE_VERSION_REQUIRES_HASH;
sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_1", "04_10_2024"));
var intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB);
Entity entity1 = world.Create(intent, new StreamableLoadingState());
system.Update(0);
intent = world.Get<GetAssetBundleIntention>(entity1);
string firstStandardURL = intent.CommonArguments.URL;
string firstCacheableHash = intent.CommonArguments.GetCacheableURL();
world.Destroy(entity1);

//Now, we simulate another scene, that has a differente scene hash but same version
sceneData.AssetBundleManifest.Returns(new SceneAssetBundleManifest(FAKE_AB_PATH, version, new[] { "abcd" }, "scene_hash_2", "04_10_2024"));
intent = GetAssetBundleIntention.FromHash(typeof(GameObject), "abcd", permittedSources: AssetSource.WEB);
Entity entity2 = world.Create(intent, new StreamableLoadingState());
system.Update(0);
intent = world.Get<GetAssetBundleIntention>(entity2);
string secondStandardURL = intent.CommonArguments.URL;
string secondCacheableHash = intent.CommonArguments.GetCacheableURL();

Assert.AreNotEqual(firstStandardURL, secondStandardURL);
Assert.AreEqual(firstCacheableHash, secondCacheableHash);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ public string GetVersion() =>
public string GetSceneID() =>
sceneID;

//Used for the OngoingRequests cache. We need to avoid version and sceneID in this URL to able to reuse assets.
//Used for the OngoingRequests cache. We need to avoid the sceneID in this URL to able to reuse assets.
//The first loaded hash will be the one used for all the other requests
public URLAddress GetCacheableURL(string hash)
{
return assetBundlesBaseUrl.Append(new URLPath(hash));
}
public URLAddress GetCacheableURL(string hash) =>
assetBundlesBaseUrl.Append(new URLPath($"{version}/{hash}"));
}
}
Loading