ButtomUICheck.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. [ExecuteInEditMode]
  6. public class ButtomUICheck : MonoBehaviour
  7. {
  8. // Update is called once per frame
  9. void Update()
  10. {
  11. RawImage raw = this.transform.parent.GetComponent<RawImage>();
  12. RawImage raw2 = this.transform.GetComponent<RawImage>();
  13. this.GetComponent<RectTransform>().sizeDelta = new Vector2(raw2.texture.width, raw2.texture.height);
  14. float bl2 = 0;
  15. if (Screen.width<= Screen.height)
  16. {
  17. if ((raw.texture.width * this.transform.parent.localScale.x)> Screen.width)
  18. {
  19. // Debug.Log("44444");
  20. bl2 = (float)Screen.width/((float)(raw2.texture.width) * this.transform.parent.localScale.x) ;
  21. }
  22. else
  23. {
  24. // Debug.Log("33333");
  25. bl2 = (float)raw.texture.width / ((float)(raw2.texture.width * this.transform.parent.localScale.x));
  26. }
  27. }
  28. else
  29. {
  30. if ((raw.texture.width * this.transform.parent.localScale.x) > Screen.width)
  31. {
  32. // Debug.Log("22222");
  33. bl2 = (float)Screen.width / ((float)(raw2.texture.width) * this.transform.parent.localScale.x);
  34. }
  35. else
  36. {
  37. // Debug.Log("11111");
  38. bl2 = (float)raw.texture.width / ((float)(raw2.texture.width));
  39. }
  40. }
  41. float bz = Screen.height / ((raw2.texture.height * bl2 * this.transform.parent.localScale.x));
  42. if(bz<3)
  43. {
  44. float js = 3 * ((raw2.texture.height * this.transform.parent.localScale.x));
  45. bl2 = Screen.height/ js;
  46. }
  47. this.transform.localScale = new Vector3(bl2, bl2, bl2);
  48. }
  49. }