UI_ScreenCover.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System;
  2. using UnityEngine;
  3. public class UI_ScreenCover : UI_ScreenFitBase
  4. {
  5. protected override void Start()
  6. {
  7. this.m_MaskPanel = base.GetComponent<UIPanel>();
  8. this.m_CoverUI = base.GetComponent<UIWidget>();
  9. base.Start();
  10. }
  11. protected override void Update()
  12. {
  13. base.Update();
  14. }
  15. protected override void FitAction()
  16. {
  17. Vector3 point = new Vector3((float)Screen.width, (float)Screen.height);
  18. Vector3 vector = UI_ScreenFitBase.PointToScreenPos(point);
  19. if (!this.m_IsMasking && this.m_CoverUI)
  20. {
  21. UI_ScreenCover.CoverType myType = this.m_MyType;
  22. if (myType != UI_ScreenCover.CoverType.Horizontal)
  23. {
  24. if (myType != UI_ScreenCover.CoverType.Vertical)
  25. {
  26. if (this.m_UseSceenAsspect)
  27. {
  28. this.m_CoverUI.width = (int)(vector.x * 2f * this.m_ScreenRateX);
  29. this.m_CoverUI.height = (int)(vector.y * 2f * this.m_ScreenRateY);
  30. }
  31. else
  32. {
  33. this.m_CoverUI.width = (int)vector.x * 2;
  34. this.m_CoverUI.height = (int)vector.y * 2;
  35. }
  36. }
  37. else
  38. {
  39. this.m_CoverUI.height = (int)vector.y * 2;
  40. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  41. {
  42. this.m_CoverUI.width = (int)((float)this.m_CoverUI.height * (this.m_AsspectRatio.x / this.m_AsspectRatio.y));
  43. }
  44. }
  45. }
  46. else
  47. {
  48. this.m_CoverUI.width = (int)vector.x * 2;
  49. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  50. {
  51. this.m_CoverUI.height = (int)((float)this.m_CoverUI.width * (this.m_AsspectRatio.y / this.m_AsspectRatio.x));
  52. }
  53. }
  54. if (this.m_WidthMax > 0)
  55. {
  56. this.m_CoverUI.width = Mathf.Min(this.m_CoverUI.width, this.m_WidthMax);
  57. }
  58. if (this.m_HeightMax > 0)
  59. {
  60. this.m_CoverUI.height = Mathf.Min(this.m_CoverUI.height, this.m_HeightMax);
  61. }
  62. }
  63. else if (this.m_IsMasking && this.m_MaskPanel)
  64. {
  65. Vector4 zero = Vector4.zero;
  66. UI_ScreenCover.CoverType myType2 = this.m_MyType;
  67. if (myType2 != UI_ScreenCover.CoverType.Horizontal)
  68. {
  69. if (myType2 != UI_ScreenCover.CoverType.Vertical)
  70. {
  71. if (this.m_UseSceenAsspect)
  72. {
  73. zero.z = (float)((int)(vector.x * 2f * this.m_ScreenRateX));
  74. zero.w = (float)((int)(vector.y * 2f * this.m_ScreenRateY));
  75. }
  76. else
  77. {
  78. zero.z = (float)((int)vector.x * 2);
  79. zero.w = (float)((int)vector.y * 2);
  80. }
  81. }
  82. else
  83. {
  84. zero.w = (float)((int)vector.y * 2);
  85. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  86. {
  87. zero.z = (float)((int)((float)this.m_MaskPanel.clipTexture.height * (this.m_AsspectRatio.x / this.m_AsspectRatio.y)));
  88. }
  89. }
  90. }
  91. else
  92. {
  93. zero.z = (float)((int)vector.x * 2);
  94. if (this.m_AsspectRatio.x != 0f && this.m_AsspectRatio.y != 0f)
  95. {
  96. zero.w = (float)((int)((float)this.m_MaskPanel.clipTexture.width * (this.m_AsspectRatio.y / this.m_AsspectRatio.x)));
  97. }
  98. }
  99. if (this.m_WidthMax > 0)
  100. {
  101. zero.z = Mathf.Min(zero.z, (float)this.m_WidthMax);
  102. }
  103. if (this.m_HeightMax > 0)
  104. {
  105. zero.w = Mathf.Min(zero.w, (float)this.m_HeightMax);
  106. }
  107. this.m_MaskPanel.baseClipRegion = zero;
  108. }
  109. }
  110. private UIPanel m_MaskPanel;
  111. private UIWidget m_CoverUI;
  112. [SerializeField]
  113. private UI_ScreenCover.CoverType m_MyType;
  114. [SerializeField]
  115. [Header("解像度に合わせたマスキングを行うか")]
  116. private bool m_IsMasking;
  117. [SerializeField]
  118. [Header("Horizontal・Vertical時の画像の比率((0, 0)で比率固定されない)")]
  119. private Vector2 m_AsspectRatio = Vector2.zero;
  120. [SerializeField]
  121. [Header("解像度に対する割合で比率を固定する")]
  122. private bool m_UseSceenAsspect;
  123. [SerializeField]
  124. [Range(0f, 1f)]
  125. private float m_ScreenRateX = 1f;
  126. [SerializeField]
  127. [Range(0f, 1f)]
  128. private float m_ScreenRateY = 1f;
  129. [SerializeField]
  130. [Header("最大サイズ(-1で無効)")]
  131. private int m_WidthMax = -1;
  132. [SerializeField]
  133. private int m_HeightMax = -1;
  134. private enum CoverType
  135. {
  136. All,
  137. Horizontal,
  138. Vertical
  139. }
  140. }