WidthUITexture.cs 998 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using System.Collections;
  3. public class WidthUITexture : MonoBehaviour {
  4. private UITexture uiTexture;
  5. private UISprite uiSprite;
  6. void Start()
  7. {
  8. uiTexture = GetComponent<UITexture>();
  9. uiSprite = GetComponent<UISprite>();
  10. if (uiTexture != null && UIRoot.Instance != null)
  11. {
  12. uiTexture.width = (int)(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height));
  13. }
  14. if (uiSprite != null)
  15. {
  16. uiSprite.width = (int)(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height));
  17. }
  18. }
  19. void Update()
  20. {
  21. if (uiTexture != null)
  22. {
  23. uiTexture.width = (int)(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height));
  24. }
  25. if (uiSprite != null)
  26. {
  27. uiSprite.width = (int)(Screen.width * UIRoot.Instance.GetPixelSizeAdjustment(Screen.height));
  28. }
  29. }
  30. }