From an optimization perspective, the mesh needs to be merged.
From the angle of the dress up (here refers to change the shape, change the composition of the parts of the dress, rather than the hanging point type of dress up), all need mesh merging, material merging. If it is a person's dress up, then you need to merge skinnedmeshrenderer and brush the corresponding list of bones. The rendering of the model after the merging of meshes can reduce the load on the GPU, but after testing, although the mesh is merged but because the sub-object mesh material is different and does not reduce the drawcall, if the material is changed to the same, unity itself will be batch merge, so the Drawcall will be reduced! In MMO games, grid dynamic merging is also very necessary!
Grid Merge Code:
Private voidCombinemesh () {//obtains all meshrenderer components in itself and all sub-objectsmeshrenderer[] Meshrenderers = getcomponentsinchildren<meshrenderer>(); //Material Sphere Arraymaterial[] Materials =NewMaterial[meshrenderers.length]; for(inti =0; i < meshrenderers.length; i++) {Materials[i]=meshrenderers[i].sharedmaterial; } //Merging Mesh//all msehfilter components in the back and sub-objectsmeshfilter[] Meshfilters = getcomponentsinchildren<meshfilter>(); Combineinstance[] Combines=NewCombineinstance[meshrenderers.length]; for(inti =0; i < meshfilters.length; i++) {Combines[i].mesh=Meshfilters[i].sharedmesh; //The point of the Matrix's own spatial coordinates into world space coordinatesCombines[i].transform =Meshfilters[i].transform.localtoworldmatrix; Meshfilters[i].gameobject.setactive (false); } //Regenerate MeshMeshfilter Meshfilter = transform. Getcomponent<meshfilter>(); if(Meshfilter = =NULL) {Meshfilter= gameobject.addcomponent<meshfilter>(); } //mesh assignment to the Meshfilter componentMeshfilter.mesh =NewMesh (); //Merge Mesh, the second parameter is false, which means that it is not merged into a grid, but a self-grid listTransform. Getcomponent<meshfilter> (). Mesh.combinemeshes (Combines,false); Transform.gameObject.SetActive (true); //assign a material to a merged new mesh//transform. Getcomponent<meshrenderer> (). sharedmaterials = materials;Meshrenderer Meshrender= transform. Getcomponent<meshrenderer>(); if(Meshrender = =NULL) {Meshrender= gameobject.addcomponent<meshrenderer>(); } meshrender.sharedmaterials=materials; }
Before running:
After merging:
After merging, the material of three sub-objects is found on the parent object, and the material is merged into a meshrender.
Project address: [Email protected]:wuzhang/unitycombinemeshrender.git
Unity Grid Merge