123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- using System;
- using System.Collections;
- using UnityEngine;
- using wf;
- public class HideScroll : MonoBehaviour
- {
- public void Awake()
- {
- if (string.IsNullOrEmpty(this.ExtensionSaveName))
- {
- this.ExtensionSaveName = string.Empty;
- }
- this.camera_ = GameObject.Find("UI Root/Camera").GetComponent<Camera>();
- this.UpdatePanelPos();
- NDebug.AssertNull(this.camera_ != null && this.TargetPanel != null && this.MoveObject != null && this.Button != null && this.Button.GetComponent<Collider>() != null && this.LockSprite != null);
- if (!GameMain.Instance.VRMode)
- {
- NDebug.Assert(this.TargetPanel.clipping == UIDrawCall.Clipping.SoftClip, "指定UIPanelのClippingはSoftClipでないといけません");
- }
- this.collider_ = this.Button.gameObject.GetComponent<BoxCollider>();
- NDebug.AssertNull(this.collider_ != null);
- this.event_trigger_ = this.Button.gameObject.GetComponent<UIEventTrigger>();
- NDebug.Assert(this.event_trigger_ != null, "UIEventTriggerコンポーネントがありません");
- EventDelegate.Add(this.event_trigger_.onHoverOver, new EventDelegate.Callback(this.OnHoverOver));
- EventDelegate.Add(this.event_trigger_.onClick, new EventDelegate.Callback(this.OnClick));
- Vector4 baseClipRegion = this.TargetPanel.baseClipRegion;
- this.clipping_size_ = new Vector2(this.TargetPanel.baseClipRegion.z, this.TargetPanel.baseClipRegion.w);
- this.clipping_offset_ = this.TargetPanel.clipOffset;
- this.move_pos_ = this.clipping_size_;
- Vector2 vector = new Vector2(this.TargetPanel.baseClipRegion.x, this.TargetPanel.baseClipRegion.y);
- NDebug.Assert(vector.x == 0f && vector.y == 0f, "UIパネルのクリッピングのセンター設定は使えません");
- if (this.Movement == HideScroll.MoveType.HorizontalRigt)
- {
- this.move_pos_.y = 0f;
- }
- else if (this.Movement == HideScroll.MoveType.HorizontalLeft)
- {
- this.move_pos_.y = 0f;
- this.move_pos_.x = this.move_pos_.x * -1f;
- }
- else if (this.Movement == HideScroll.MoveType.VerticalTop)
- {
- this.move_pos_.x = 0f;
- this.move_pos_.y = this.move_pos_.y * -1f;
- }
- else if (this.Movement == HideScroll.MoveType.VerticalBottom)
- {
- this.move_pos_.x = 0f;
- }
- int num = 2;
- this.retention_rect_.x = (this.clipping_size_.x / 2f - this.clipping_offset_.x) * -1f - (float)num;
- this.retention_rect_.y = this.clipping_size_.y / 2f + this.clipping_offset_.y - this.clipping_size_.y - (float)num;
- this.retention_rect_.width = this.clipping_size_.x + (float)(num * 2);
- this.retention_rect_.height = this.clipping_size_.y + (float)(num * 2);
- this.SetPanelFix(true);
- if (this.panel_fixed_)
- {
- this.PanelDisplayIn();
- }
- else
- {
- this.PanelDisplayOut();
- }
- }
- public void Start()
- {
- string text = GameMain.Instance.CMSystem.GetSystemVers(this.GetFlagName());
- if (text == null)
- {
- text = "1";
- if (this.StartReceipt)
- {
- text = "0";
- }
- }
- this.SetPanelFix(text == "1");
- if (this.panel_fixed_)
- {
- this.PanelDisplayIn();
- }
- else
- {
- this.PanelDisplayOut();
- }
- }
- public void SetPanelFix(bool set_fixed)
- {
- this.panel_fixed_ = set_fixed;
- if (this.panel_fixed_)
- {
- this.OnHoverOver();
- }
- this.LockSprite.alpha = ((!this.panel_fixed_) ? 0f : 1f);
- }
- public void OnClick()
- {
- this.SetPanelFix(!this.panel_fixed_);
- string f_strVal = "1";
- if (!this.panel_fixed_)
- {
- f_strVal = "0";
- }
- GameMain.Instance.CMSystem.SetSystemVers(this.GetFlagName(), f_strVal);
- }
- private void UpdatePanelPos()
- {
- if (!GameMain.Instance.VRMode && this.ParentObject != null)
- {
- this.count++;
- if (this.count < 30)
- {
- return;
- }
- this.count = 0;
- Vector3 zero = Vector3.zero;
- if (this.Movement == HideScroll.MoveType.HorizontalLeft)
- {
- zero.x = 0f;
- }
- else if (this.Movement == HideScroll.MoveType.HorizontalRigt)
- {
- zero.x = (float)Screen.width;
- }
- else if (this.Movement == HideScroll.MoveType.VerticalBottom)
- {
- zero.y = (float)Screen.height;
- }
- else if (this.Movement == HideScroll.MoveType.VerticalTop)
- {
- zero.y = 0f;
- }
- Vector3 position = this.camera_.ScreenToWorldPoint(zero);
- Vector3 vector = this.ParentObject.transform.TransformPoint(zero);
- Vector3 vector2 = this.ParentObject.transform.parent.InverseTransformPoint(position);
- if (this.Movement == HideScroll.MoveType.HorizontalLeft || this.Movement == HideScroll.MoveType.HorizontalRigt)
- {
- this.ParentObject.transform.localPosition = new Vector3(vector2.x, this.ParentObject.transform.localPosition.y, 0f);
- }
- else
- {
- this.ParentObject.transform.localPosition = new Vector3(this.ParentObject.transform.localPosition.x, vector2.y, 0f);
- }
- }
- }
- public void Update()
- {
- this.UpdatePanelPos();
- if (this.panel_fixed_ || !this.current_panel_display_)
- {
- return;
- }
- Vector3 vector;
- if (!GameMain.Instance.VRMode)
- {
- vector = this.camera_.ScreenToWorldPoint(Input.mousePosition);
- }
- else
- {
- vector = this.camera_.ScreenToWorldPoint(GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos());
- }
- vector = this.TargetPanel.transform.InverseTransformPoint(vector);
- vector.z = 0f;
- if (!this.retention_rect_.Contains(vector))
- {
- this.PanelDisplayOut();
- }
- }
- public void OnHoverOver()
- {
- if (!this.current_panel_display_)
- {
- this.PanelDisplayIn();
- }
- }
- private void PanelDisplayIn()
- {
- Hashtable hashtable = TweenHash.EaseOutQuint(TweenHash.Type.Position, Vector3.zero, 0.5f);
- hashtable.Add("onUpdate", "UpdateDisplayIn");
- iTween.MoveTo(this.MoveObject, hashtable);
- this.current_panel_display_ = true;
- }
- private void PanelDisplayOut()
- {
- Hashtable args = TweenHash.EaseOutQuint(TweenHash.Type.Position, this.move_pos_, 0.5f);
- iTween.MoveTo(this.MoveObject, args);
- this.current_panel_display_ = false;
- }
- public string GetFlagName()
- {
- return "夜伽_HideScroll_" + this.Movement.ToString() + this.ExtensionSaveName;
- }
- public GameObject ParentObject;
- public UIPanel TargetPanel;
- public GameObject MoveObject;
- public UIButton Button;
- public UISprite LockSprite;
- public HideScroll.MoveType Movement;
- public string ExtensionSaveName;
- public bool StartReceipt;
- private Camera camera_;
- private UIEventTrigger event_trigger_;
- private BoxCollider collider_;
- private Vector2 clipping_size_;
- private Vector2 clipping_offset_;
- private Vector3 move_pos_;
- private Rect retention_rect_;
- private bool panel_fixed_;
- private bool current_panel_display_;
- private int count;
- public enum MoveType
- {
- HorizontalRigt,
- HorizontalLeft,
- VerticalTop,
- VerticalBottom
- }
- }
|