Introduction:
When using Unity3d to develop micro-ends or web games, you often need to package resources into AssetBundle, and then dynamically download resources through www. Today I want to share some detours and my final solutions when I download the Animation. There are hundreds of sets of animation resources in our project. Each set of animation is about KB to kb, so an important requirement is to download the required animation dynamically.
Incorrect method:
The first method that comes to mind after I see the requirement is to instantiate the Prefab imported into FBX, save the Animation as an Asset file through ScriptObject, and then export it as an AssetBundle file. When the game is running, assign the downloaded Animation component to the Animation variable of the corresponding GameObject. The tragedy is that I found that the Animation accessors are read-only at this time.
Correct practice:
Export all the AnimationClip objects in Animation to be added to ScriptObject as arrays, save them as Asset files, and export them as AssetBundle files. When the game is running, add the downloaded Clip object to the Animation component to complete the dynamic loading of the Animation.
AnimationClip contains Animation data, which can be flexibly added or deleted from Animation.
Another seemingly feasible method:
Import the Prefab game object imported into Fbx and export the Texture of Mesh (grid data) and Shader in SkinnedMeshRenderer component into AssetBundle, the remaining gameobjects that have deleted the two data are combined with the animation to form a Prefab, Which is dynamically assembled during running. If this method is used to dynamically download role Resources in the project, you can bypass the problems encountered in the previous article to a certain extent. However, the previous solution is a more accurate solution to the problem.