ModelResizer.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using UnityEngine;
  2. using System.Collections;
  3. #if UNITY_EDITOR
  4. [ExecuteInEditMode()]
  5. #endif
  6. public class ModelResizer:MonoBehaviour {
  7. // Resizes a model to a desired maximum size
  8. // TODO: Actually get rid of this file.
  9. // Properties
  10. public float desiredHeight;
  11. public float desiredWidth;
  12. public float desiredDepth;
  13. // ================================================================================================================
  14. // MAIN EVENT INTERFACE -------------------------------------------------------------------------------------------
  15. #if UNITY_EDITOR
  16. void Start () {
  17. resize();
  18. }
  19. void Update() {
  20. if (!Application.isPlaying) resize();
  21. }
  22. #endif
  23. // ================================================================================================================
  24. // INTERNAL INTERFACE ---------------------------------------------------------------------------------------------
  25. private void resize() {
  26. foreach (Transform child in transform) {
  27. // Resize
  28. GameObjectUtils.resizeToFit(child.gameObject, desiredWidth, desiredHeight, desiredDepth);
  29. // Center in the bottom
  30. GameObjectUtils.alignToVector(child.gameObject, transform.position, 0.5f, 0, 0.5f);
  31. }
  32. }
  33. }