- Home /
About bundle asset and update
Our game is a MMO on PC.When players have installed our game, all resources include meshes, shaders, textures would have been saved on disk.I am a programer, and I am in charge of finishing resources loading and update.
Any given asset in a bundle may depend on other assets. For example, a model may incorporate materials which in turn make use of textures and shaders. It is possible to include all an asset's dependencies along with it in its bundle. However, several assets from different bundles may all depend on a common set of other assets (eg, several different models of buildings may use the same brick texture). If a separate copy of a shared dependency is included in each bundle that has objects using it, then redundant instances of the assets will be created when the bundles are loaded. This will result in wasted memory.
First, I compress each resources into asset bundles like this. Code:
[MenuItem("BundleAsset/Prefab [Regenerate All]", false, 1)]
static public void BundlePrefab()
{
// Create folders.
if (!hasInitialized)
Initialize();
BuildPipeline.PushAssetDependencies();
// Bundle all sub resources
BundleTexture();
BundleMaterial();
BundleModel();
BundleAudio();
// Bundle main resources
BundleObject();
BundleScenery();
BundleEffect();
BuildPipeline.PopAssetDependencies();
}
static private void BundleObject()
{
string[] fileNames = Directory.GetFiles(objectPathName);
for (int i = 0; i < fileNames.Length; ++i)
{
string fileName = GetFileName(fileNames[i]);
if (IsMetaFile(fileName))
continue;
Object obj = AssetDatabase.LoadMainAssetAtPath(fileName);
BuildPipeline.BuildAssetBundle(obj, null, objectBundlePathName + @"/" + obj.name + suffix, BuildAssetBundleOptions.CollectDependencies, targetPlatform);
}
}
Trouble is resource update.For example, a desk model depends on a texture named T, when update happens, a chair depends on the same texture T should be added.If I build a chair bundle and a T bundle, and update them, desk's texture will be missing.To solve this program, I must bundle desk, chair and T at the same time and update them.I have to update some resources I don't want to update, it is a trouble, how to solve it ?