| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 | 
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 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<object> dataList = viewData as List<object>;            guideTarget = dataList[0] as GObject;            txtContent = (string)dataList[1];            guideId = (int)dataList[2];            guideIndex = (int)dataList[3];            compTxtY = (float)dataList[4];            justHint = (bool)dataList[5];            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_METAL);            GuideCfg cfg1 = GuideCfgArray.Instance.GetCfg(ConstGuideId.STUDIO_FILING);            GuideCfg cfg2 = GuideCfgArray.Instance.GetCfg(ConstGuideId.FIELD);            if (guideId == cfg.id && guideIndex == 2 || guideId == cfg1.id && guideIndex == 2 || guideId == cfg2.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(guideId, guideIndex);        }    }}
 |