123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- using UI.Guide;
- using FairyGUI;
- using UnityEngine;
- using System.Collections.Generic;
- using System;
- namespace GFGGame
- {
- public class GuideView : BaseView
- {
- private UI_GuideUI _ui;
- private bool _needUpdate;
- private GObject guideTarget = null;
- private float devWidth;
- private float devHeight;
- private int yTxt;
- private bool showAni;
- private int guideId;
- private int guideIndex;
- private bool isOptionalGuide = false;//弱引导,点击任意地方都可关闭
- private GameObject _gameObject;
- private GoWrapper _wrapper;
- private int sortingOrder;
- public override void Dispose()
- {
- base.Dispose();
- }
- protected override void OnInit()
- {
- base.OnInit();
- viewAnimationType = EnumViewAnimationType.None;
- packageName = UI_GuideUI.PACKAGE_NAME;
- _ui = UI_GuideUI.Create();
- this.viewCom = _ui.target;
- // this.clickBlankToClose = false;
- this.layer = ConstViewLayer.TOP;
- isfullScreen = true;
- _ui.m_rectFrameTemp.visible = false;
- _ui.m_rectFrame.target.visible = false;
- _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Width);
- _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Height);
- _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Left_Left);
- _ui.m_rectFrame.target.AddRelation(_ui.m_mask.m_guideArea, RelationType.Top_Top);
- _ui.target.onClick.Add(() =>
- {
- if (isOptionalGuide) this.Hide();
- });
- string resPath0 = ResPathUtil.GetViewEffectPath("ui_yd/ui_yd_y", "ui_yd_y");
- SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath0, out _gameObject, out _wrapper);
- }
- protected override void OnShown()
- {
- base.OnShown();
- List<object> dataList = viewData as List<object>;
- guideTarget = dataList[0] as GObject;
- string txtContent = (string)dataList[1];
- yTxt = (int)dataList[2];
- isOptionalGuide = (bool)dataList[3];
- devWidth = (float)dataList[4];
- devHeight = (float)dataList[5];
- guideId = (int)dataList[6];
- guideIndex = (int)dataList[7];
- showAni = (bool)dataList[8];
- if (txtContent != null && txtContent.Length > 0)
- {
- _ui.m_compTxt.m_txt.text = txtContent;
- if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 2)
- {
- this._ui.m_compTxt.m_txt.align = AlignType.Left;
- }
- else
- {
- this._ui.m_compTxt.m_txt.align = AlignType.Center;
- }
- _ui.m_compTxt.target.visible = true;
- }
- else
- {
- _ui.m_compTxt.target.visible = false;
- }
- _ui.m_comHolder.target.visible = false;
- _ui.m_rectFrameTemp.width = _ui.m_mask.target.width;
- _ui.m_rectFrameTemp.height = _ui.m_mask.target.height;
- _ui.m_rectFrameTemp.x = 0;
- _ui.m_rectFrameTemp.y = 0;
- if (guideTarget != null)
- {
- UpdateGuideRect();
- Timers.inst.AddUpdate(UpdateGuideRect);
- _ui.m_mask.target.visible = true;
- guideTarget.touchable = false;
- guideTarget.onClick.Add(OnClickTarget);
- if (guideTarget == null) OnClickTarget();
- }
- else
- {
- _ui.m_comHolder.target.visible = false;
- _ui.m_mask.target.visible = false;
- _ui.m_rectFrameTemp.visible = false;
- }
- _ui.m_compTxt.target.y = Math.Min(yTxt, GRoot.inst.height - _ui.m_compTxt.target.height - 3);
- // _ui.m_rectFrame.target.visible = true;
- }
- protected override void OnHide()
- {
- Timers.inst.Remove(UpdateGuideRect);
- base.OnHide();
- if (isOptionalGuide || guideTarget == null)
- {
- OnClickTarget();
- }
- guideTarget = null;
- }
- private void UpdateGuideRect(object param = null)
- {
- if (guideTarget != null)
- {
- Rect rect = guideTarget.TransformRect(new Rect(0 + devWidth, devHeight, guideTarget.width, guideTarget.height), _ui.target);
- _ui.m_mask.m_guideArea.size = new Vector2((int)rect.size.x, (int)rect.size.y);
- _ui.m_mask.m_guideArea.position = new Vector2((int)rect.position.x, (int)rect.position.y);
- Debug.Log("zoya000:" + _ui.m_mask.m_guideArea.position);
- _ui.m_comHolder.target.position = _ui.m_mask.m_guideArea.position;
- Debug.Log("zoya111:" + _ui.m_comHolder.target.position);
- _ui.m_comHolder.target.size = _ui.m_mask.m_guideArea.size;
- int padding = 90;
- bool atBottom = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding + _ui.m_compTxt.target.height + padding > GRoot.inst.height;
- if (yTxt == 0)
- {
- if (atBottom)
- {
- _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y - _ui.m_compTxt.target.height - padding;
- }
- else
- {
- _ui.m_compTxt.target.y = _ui.m_mask.m_guideArea.y + _ui.m_mask.m_guideArea.height + padding;
- }
- Debug.Log("zoya222:" + _ui.m_compTxt.target.y);
- }
- int targetWidth = 20;
- if (showAni)
- {
- if (Mathf.Abs(_ui.m_rectFrameTemp.width - _ui.m_rectFrame.target.width) > targetWidth && Mathf.Abs(_ui.m_rectFrameTemp.height - _ui.m_rectFrame.target.height) > targetWidth)
- {
- _ui.m_rectFrameTemp.visible = true;
- float duration = 0.5f;
- _ui.m_rectFrameTemp.TweenResize(new Vector2(_ui.m_rectFrame.target.width, _ui.m_rectFrame.target.height), duration);
- _ui.m_rectFrameTemp.TweenMove(new Vector2(_ui.m_rectFrame.target.x, _ui.m_rectFrame.target.y), duration);
- }
- else
- {
- guideTarget.touchable = true;
- _ui.m_comHolder.target.visible = true;
- _ui.m_rectFrameTemp.visible = false;
- }
- }
- else
- {
- // if (Mathf.Abs(_ui.m_rectFrameTemp.width - _ui.m_rectFrame.target.width) <= targetWidth && Mathf.Abs(_ui.m_rectFrameTemp.height - _ui.m_rectFrame.target.height) <= targetWidth)
- // {
- // Timers.inst.Remove(UpdateGuideRect);
- // }
- _ui.m_comHolder.target.visible = true;
- guideTarget.touchable = true;
- }
- }
- }
- private void OnClickTarget()
- {
- // if (guideTarget == null) return;
- // if (!ViewManager.CheckIsTopView(this.viewCom)) return;
- if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget);
- GuideController.TryCompleteGuideIndex(guideId, guideIndex);
- }
- }
- }
|