using UI.Guide; using FairyGUI; using UnityEngine; using System.Collections.Generic; using System; namespace GFGGame { public class GuideView : BaseView { private UI_GuideUI _ui; private GObject guideTarget = null; private string guideKey; private int guideId; private int guideIndex; private bool justHint;//仅提示,无遮罩,点击任何地方可关闭引导 private float compTxtY = 0;//提示语位置 private string txtContent = ""; private GameObject _gameObject; private GoWrapper _wrapper; public override void Dispose() { SceneController.DestroyObjectFromView(_gameObject, _wrapper); if (_ui != null) { _ui.Dispose(); _ui = null; } 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.layer = ConstViewLayer.GUIDE; isfullScreen = true; _ui.m_loaMask.onClick.Add(OnClickTarget); string resPath1 = ResPathUtil.GetViewEffectPath("ui_zjm", "ui_zjm_xszy"); SceneController.AddObjectToView(_gameObject, _wrapper, _ui.m_comHolder.m_holder, resPath1, out _gameObject, out _wrapper, 90); } protected override void OnShown() { base.OnShown(); List dataList = viewData as List; guideTarget = dataList[0] as GObject; guideKey = (string)dataList[1]; txtContent = (string)dataList[2]; guideId = (int)dataList[3]; guideIndex = (int)dataList[4]; compTxtY = (float)dataList[5]; justHint = (bool)dataList[6]; GRoot.inst.touchable = true; MainDataManager.Instance.CanSwipe = false; UpdateComTxt(txtContent); _ui.m_mask.target.visible = false; _ui.m_loaMask.visible = false; if (guideTarget != null) { Timers.inst.AddUpdate(UpdateGuideRect); _ui.m_mask.target.visible = true; guideTarget.onClick.Add(OnClickTarget); } else { _ui.m_loaMask.visible = true; if (compTxtY > 0) { _ui.m_compTxt.target.y = compTxtY; } _ui.m_comHolder.target.visible = false; _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent); } if (justHint) { _ui.m_mask.target.visible = false; _ui.m_loaMask.visible = true; } //一些特殊引导 GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_PORCELAIN); GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_FILING); GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIELD); GuideCfg cfg4 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_PROPERTY); if (guideId == cfg.id && guideIndex == 2 || guideId == cfg1.id && guideIndex == 2 || guideId == cfg2.id && guideIndex == 1 || guideId == cfg4.id && guideIndex == 1) { _ui.m_loaMask.visible = false; MainDataManager.Instance.CanSwipe = true; Timers.inst.AddUpdate(UpdateStudioMetalGuide); } GuideCfg cfg3 = GuideCfgArray.Instance.GetCfg(ConstGuideId.LUCKY_BOX_LINE); if (guideId == cfg3.id && guideIndex == 1) { _ui.m_mask.target.visible = false; _ui.m_loaMask.visible = false; } } protected override void OnHide() { base.OnHide(); _ui.m_comHolder.target.visible = false; _ui.m_compTxt.target.visible = false; guideTarget = null; Timers.inst.Remove(UpdateGuideRect); Timers.inst.Remove(UpdateStudioMetalGuide); } private void UpdateComTxt(string txtContent) { if (String.IsNullOrEmpty(txtContent)) { _ui.m_compTxt.target.visible = false; } else { _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; } this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.initHeight; if (this._ui.m_compTxt.m_txt.textHeight > this._ui.m_compTxt.m_txt.textFormat.size * 3) { this._ui.m_compTxt.m_txtBg.height = this._ui.m_compTxt.m_txtBg.height + this._ui.m_compTxt.m_txt.textFormat.size; } } } private void UpdateGuideRect(object param = null) { if (guideTarget != null) { Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero); Vector2 logicScreenPos = GRoot.inst.GlobalToLocal(pos); // pos = _ui.m_mask.target.GlobalToLocal(pos); logicScreenPos.x = logicScreenPos.x + guideTarget.width / 2; logicScreenPos.y = logicScreenPos.y + guideTarget.height / 2; if (_ui.m_mask.m_guideArea.xy == logicScreenPos) { Timers.inst.Remove(UpdateGuideRect); _ui.m_comHolder.target.xy = _ui.m_mask.m_guideArea.xy; if (logicScreenPos.x > GRoot.inst.width / 2) { _ui.m_comHolder.m_c1.selectedIndex = 0;//手在左边 } else { _ui.m_comHolder.m_c1.selectedIndex = 1;//手在右边 } _ui.m_comHolder.target.visible = true; _ui.m_compTxt.target.visible = !String.IsNullOrEmpty(txtContent); int padding = 100; if (logicScreenPos.y < GRoot.inst.height - 700) { _ui.m_compTxt.target.y = logicScreenPos.y + _ui.m_comHolder.target.height + padding;//在下 } else { _ui.m_compTxt.target.y = logicScreenPos.y - _ui.m_comHolder.target.height - _ui.m_compTxt.target.height - padding;//在上 } if (compTxtY > 0) { _ui.m_compTxt.target.y = compTxtY; } return; } _ui.m_mask.m_guideArea.SetXY(logicScreenPos.x, logicScreenPos.y); } } private void UpdateStudioMetalGuide(object param) { if (MainDataManager.Instance.ViewType == 1) { OnClickTarget(); } } private void OnClickTarget() { if (guideTarget != null) guideTarget.onClick.Remove(OnClickTarget); GuideController.TryCompleteGuideIndex(guideKey, guideIndex); } } }