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(); this.UpdatePanelPos(); NDebug.AssertNull(this.camera_ != null && this.TargetPanel != null && this.MoveObject != null && this.Button != null && this.Button.GetComponent() != 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(); NDebug.AssertNull(this.collider_ != null); this.event_trigger_ = this.Button.gameObject.GetComponent(); 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)); this.UpdatePanelData(); 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); } public void UpdatePanelData() { 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); } 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 } }