MB_Example.cs 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. using UnityEngine;
  2. using System.Collections;
  3. public class MB_Example : MonoBehaviour {
  4. public MB3_MeshBaker meshbaker;
  5. public GameObject[] objsToCombine;
  6. void Start(){
  7. //Add the objects to the combined mesh
  8. //Must have previously baked textures for these in the editor
  9. meshbaker.AddDeleteGameObjects(objsToCombine, null, true);
  10. //apply the changes we made this can be slow. See documentation
  11. meshbaker.Apply();
  12. }
  13. void LateUpdate(){
  14. //Apply changes after this and other scripts have made changes
  15. //Only to vertecies, tangents and normals
  16. //Only want to call this once per frame since it is slow
  17. meshbaker.UpdateGameObjects(objsToCombine);
  18. meshbaker.Apply(false,true,true,true,false,false,false,false,false);
  19. }
  20. void OnGUI(){
  21. GUILayout.Label ("Dynamically updates the vertices, normals and tangents in combined mesh every frame.\n" +
  22. "This is similar to dynamic batching. It is not recommended to do this every frame.\n" +
  23. "Also consider baking the mesh renderer objects into a skinned mesh renderer\n" +
  24. "The skinned mesh approach is faster for objects that need to move independently of each other every frame.");
  25. }
  26. }