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 bool NoTips;//无遮罩,无点击特效 private float compTxtY = 0;//提示语位置 private string txtContent = ""; private EffectUI _effectUI1; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; 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; //this.viewCom.sortingOrder = ConstSortingOrder.Guide; isfullScreen = true; _ui.m_loaMask.onClick.Add(OnClickTarget); _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_comHolder.m_holder, "ui_zjm", "ui_zjm_xszy", 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]; NoTips = (bool)dataList[7]; GRoot.inst.touchable = true; MainDataManager.Instance.CanSwipe = false; UpdateComTxt(txtContent); _ui.m_mask.target.visible = false; _ui.m_loaMask.visible = false; _ui.m_grhMask.visible = false; if (guideTarget != null) { _ui.m_grhMask.visible = true; _ui.m_comHolder.target.visible = false; Timers.inst.Add(0.3f, 1, UpdateTime); // _ui.m_mask.target.visible = true; // _ui.m_comHolder.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; } if (NoTips) { _ui.m_mask.target.visible = false; _ui.m_comHolder.target.visible = false; } //一些特殊引导 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); //书简修复 GuideCfg cfg5 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS); //换装和拍照 if (guideId == cfg.id && guideIndex == 2 || guideId == cfg1.id && guideIndex == 2 || guideId == cfg2.id && guideIndex == 1 || guideId == cfg4.id && guideIndex == 1 || guideId == cfg5.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() { Timers.inst.Remove(UpdateTime); Timers.inst.Remove(UpdateGuideRect); Timers.inst.Remove(UpdateStudioMetalGuide); _ui.m_comHolder.target.visible = false; _ui.m_compTxt.target.visible = false; _ui.m_grhMask.visible = true; guideTarget = null; base.OnHide(); // EventAgent.DispatchEvent(ConstMessage.GUIDE_VIEW_HIDE); } 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 UpdateTime(object param = null) { Timers.inst.AddUpdate(UpdateGuideRect); } private void UpdateGuideRect(object param = null) { if (guideTarget != null) { Vector2 pos = guideTarget.LocalToGlobal(Vector2.zero); Vector2 logicScreenPos = _ui.target.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 = !NoTips; _ui.m_mask.target.visible = !NoTips; _ui.m_grhMask.visible = false; _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); } } }