HideScroll.cs 6.4 KB

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