MB2_UpdateSkinnedMeshBoundsFromBounds.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using DigitalOpus.MB.Core;
  5. public class MB2_UpdateSkinnedMeshBoundsFromBounds : MonoBehaviour {
  6. public List<GameObject> objects;
  7. SkinnedMeshRenderer smr;
  8. void Start () {
  9. smr = GetComponent<SkinnedMeshRenderer>();
  10. if (smr == null){
  11. Debug.LogError("Need to attach MB2_UpdateSkinnedMeshBoundsFromBounds script to an object with a SkinnedMeshRenderer component attached.");
  12. return;
  13. }
  14. if (objects == null || objects.Count == 0){
  15. Debug.LogWarning("The MB2_UpdateSkinnedMeshBoundsFromBounds had no Game Objects. It should have the same list of game objects that the MeshBaker does.");
  16. smr = null;
  17. return;
  18. }
  19. for (int i = 0; i < objects.Count; i++){
  20. if (objects[i] == null || objects[i].GetComponent<Renderer>() == null){
  21. Debug.LogError("The list of objects had nulls or game objects without a renderer attached at position " + i);
  22. smr = null;
  23. return;
  24. }
  25. }
  26. bool origVal = smr.updateWhenOffscreen;
  27. smr.updateWhenOffscreen = true;
  28. smr.updateWhenOffscreen = origVal;
  29. }
  30. void Update () {
  31. if (smr != null && objects != null){
  32. MB3_MeshCombiner.UpdateSkinnedMeshApproximateBoundsFromBoundsStatic(objects,smr);
  33. }
  34. }
  35. }