HideScroll.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using wf;
  5. public class HideScroll : MonoBehaviour
  6. {
  7. public void Awake()
  8. {
  9. if (string.IsNullOrEmpty(this.ExtensionSaveName))
  10. {
  11. this.ExtensionSaveName = string.Empty;
  12. }
  13. this.camera_ = GameObject.Find("UI Root/Camera").GetComponent<Camera>();
  14. this.UpdatePanelPos();
  15. NDebug.AssertNull(this.camera_ != null && this.TargetPanel != null && this.MoveObject != null && this.Button != null && this.Button.GetComponent<Collider>() != null && this.LockSprite != null);
  16. if (!GameMain.Instance.VRMode)
  17. {
  18. NDebug.Assert(this.TargetPanel.clipping == UIDrawCall.Clipping.SoftClip, "指定UIPanelのClippingはSoftClipでないといけません");
  19. }
  20. this.collider_ = this.Button.gameObject.GetComponent<BoxCollider>();
  21. NDebug.AssertNull(this.collider_ != null);
  22. this.event_trigger_ = this.Button.gameObject.GetComponent<UIEventTrigger>();
  23. NDebug.Assert(this.event_trigger_ != null, "UIEventTriggerコンポーネントがありません");
  24. EventDelegate.Add(this.event_trigger_.onHoverOver, new EventDelegate.Callback(this.OnHoverOver));
  25. EventDelegate.Add(this.event_trigger_.onClick, new EventDelegate.Callback(this.OnClick));
  26. this.UpdatePanelData();
  27. this.SetPanelFix(true);
  28. if (this.panel_fixed_)
  29. {
  30. this.PanelDisplayIn();
  31. }
  32. else
  33. {
  34. this.PanelDisplayOut();
  35. }
  36. }
  37. public void Start()
  38. {
  39. string text = GameMain.Instance.CMSystem.GetSystemVers(this.GetFlagName());
  40. if (text == null)
  41. {
  42. text = "1";
  43. if (this.StartReceipt)
  44. {
  45. text = "0";
  46. }
  47. }
  48. this.SetPanelFix(text == "1");
  49. if (this.panel_fixed_)
  50. {
  51. this.PanelDisplayIn();
  52. }
  53. else
  54. {
  55. this.PanelDisplayOut();
  56. }
  57. }
  58. public void SetPanelFix(bool set_fixed)
  59. {
  60. this.panel_fixed_ = set_fixed;
  61. if (this.panel_fixed_)
  62. {
  63. this.OnHoverOver();
  64. }
  65. this.LockSprite.alpha = ((!this.panel_fixed_) ? 0f : 1f);
  66. }
  67. public void OnClick()
  68. {
  69. this.SetPanelFix(!this.panel_fixed_);
  70. string f_strVal = "1";
  71. if (!this.panel_fixed_)
  72. {
  73. f_strVal = "0";
  74. }
  75. GameMain.Instance.CMSystem.SetSystemVers(this.GetFlagName(), f_strVal);
  76. }
  77. public void UpdatePanelData()
  78. {
  79. Vector4 baseClipRegion = this.TargetPanel.baseClipRegion;
  80. this.clipping_size_ = new Vector2(this.TargetPanel.baseClipRegion.z, this.TargetPanel.baseClipRegion.w);
  81. this.clipping_offset_ = this.TargetPanel.clipOffset;
  82. this.move_pos_ = this.clipping_size_;
  83. Vector2 vector = new Vector2(this.TargetPanel.baseClipRegion.x, this.TargetPanel.baseClipRegion.y);
  84. NDebug.Assert(vector.x == 0f && vector.y == 0f, "UIパネルのクリッピングのセンター設定は使えません");
  85. if (this.Movement == HideScroll.MoveType.HorizontalRigt)
  86. {
  87. this.move_pos_.y = 0f;
  88. }
  89. else if (this.Movement == HideScroll.MoveType.HorizontalLeft)
  90. {
  91. this.move_pos_.y = 0f;
  92. this.move_pos_.x = this.move_pos_.x * -1f;
  93. }
  94. else if (this.Movement == HideScroll.MoveType.VerticalTop)
  95. {
  96. this.move_pos_.x = 0f;
  97. this.move_pos_.y = this.move_pos_.y * -1f;
  98. }
  99. else if (this.Movement == HideScroll.MoveType.VerticalBottom)
  100. {
  101. this.move_pos_.x = 0f;
  102. }
  103. int num = 2;
  104. this.retention_rect_.x = (this.clipping_size_.x / 2f - this.clipping_offset_.x) * -1f - (float)num;
  105. this.retention_rect_.y = this.clipping_size_.y / 2f + this.clipping_offset_.y - this.clipping_size_.y - (float)num;
  106. this.retention_rect_.width = this.clipping_size_.x + (float)(num * 2);
  107. this.retention_rect_.height = this.clipping_size_.y + (float)(num * 2);
  108. }
  109. private void UpdatePanelPos()
  110. {
  111. if (!GameMain.Instance.VRMode && this.ParentObject != null)
  112. {
  113. this.count++;
  114. if (this.count < 30)
  115. {
  116. return;
  117. }
  118. this.count = 0;
  119. Vector3 zero = Vector3.zero;
  120. if (this.Movement == HideScroll.MoveType.HorizontalLeft)
  121. {
  122. zero.x = 0f;
  123. }
  124. else if (this.Movement == HideScroll.MoveType.HorizontalRigt)
  125. {
  126. zero.x = (float)Screen.width;
  127. }
  128. else if (this.Movement == HideScroll.MoveType.VerticalBottom)
  129. {
  130. zero.y = (float)Screen.height;
  131. }
  132. else if (this.Movement == HideScroll.MoveType.VerticalTop)
  133. {
  134. zero.y = 0f;
  135. }
  136. Vector3 position = this.camera_.ScreenToWorldPoint(zero);
  137. Vector3 vector = this.ParentObject.transform.TransformPoint(zero);
  138. Vector3 vector2 = this.ParentObject.transform.parent.InverseTransformPoint(position);
  139. if (this.Movement == HideScroll.MoveType.HorizontalLeft || this.Movement == HideScroll.MoveType.HorizontalRigt)
  140. {
  141. this.ParentObject.transform.localPosition = new Vector3(vector2.x, this.ParentObject.transform.localPosition.y, 0f);
  142. }
  143. else
  144. {
  145. this.ParentObject.transform.localPosition = new Vector3(this.ParentObject.transform.localPosition.x, vector2.y, 0f);
  146. }
  147. }
  148. }
  149. public void Update()
  150. {
  151. this.UpdatePanelPos();
  152. if (this.panel_fixed_ || !this.current_panel_display_)
  153. {
  154. return;
  155. }
  156. Vector3 vector;
  157. if (!GameMain.Instance.VRMode)
  158. {
  159. vector = this.camera_.ScreenToWorldPoint(Input.mousePosition);
  160. }
  161. else
  162. {
  163. vector = this.camera_.ScreenToWorldPoint(GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos());
  164. }
  165. vector = this.TargetPanel.transform.InverseTransformPoint(vector);
  166. vector.z = 0f;
  167. if (!this.retention_rect_.Contains(vector))
  168. {
  169. this.PanelDisplayOut();
  170. }
  171. }
  172. public void OnHoverOver()
  173. {
  174. if (!this.current_panel_display_)
  175. {
  176. this.PanelDisplayIn();
  177. }
  178. }
  179. private void PanelDisplayIn()
  180. {
  181. Hashtable hashtable = TweenHash.EaseOutQuint(TweenHash.Type.Position, Vector3.zero, 0.5f);
  182. hashtable.Add("onUpdate", "UpdateDisplayIn");
  183. iTween.MoveTo(this.MoveObject, hashtable);
  184. this.current_panel_display_ = true;
  185. }
  186. private void PanelDisplayOut()
  187. {
  188. Hashtable args = TweenHash.EaseOutQuint(TweenHash.Type.Position, this.move_pos_, 0.5f);
  189. iTween.MoveTo(this.MoveObject, args);
  190. this.current_panel_display_ = false;
  191. }
  192. public string GetFlagName()
  193. {
  194. return "夜伽_HideScroll_" + this.Movement.ToString() + this.ExtensionSaveName;
  195. }
  196. public GameObject ParentObject;
  197. public UIPanel TargetPanel;
  198. public GameObject MoveObject;
  199. public UIButton Button;
  200. public UISprite LockSprite;
  201. public HideScroll.MoveType Movement;
  202. public string ExtensionSaveName;
  203. public bool StartReceipt;
  204. private Camera camera_;
  205. private UIEventTrigger event_trigger_;
  206. private BoxCollider collider_;
  207. private Vector2 clipping_size_;
  208. private Vector2 clipping_offset_;
  209. private Vector3 move_pos_;
  210. private Rect retention_rect_;
  211. private bool panel_fixed_;
  212. private bool current_panel_display_;
  213. private int count;
  214. public enum MoveType
  215. {
  216. HorizontalRigt,
  217. HorizontalLeft,
  218. VerticalTop,
  219. VerticalBottom
  220. }
  221. }