| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 | using FairyGUI;using UI.Loading;using UnityEngine;namespace GFGGame{    public class LoadingView : BaseWindow    {        private UI_LoadingView _ui;        //每个进度需要的时间,单位为毫秒        private const float TimePerProgress = 0.005f;        private string[] resNames = { "11", "33" };        private EffectUI _effectUI1;        //每个进度需要的时间,单位为毫秒        private float timePerProgress;        private static LoadingView m_Instance = null;        public static LoadingView Instance        {            get            {                if (m_Instance == null)                {                    // m_Instance = new LauncherView();                    m_Instance = ViewManager.GetUIView(typeof(LoadingView).Name) as LoadingView;                }                return m_Instance;            }        }        public override void Dispose()        {            m_Instance = null;            EffectUIPool.Recycle(_effectUI1);            _effectUI1 = null;            if (_ui != null)            {                _ui.Dispose();                _ui = null;            }            base.Dispose();        }        protected override void OnInit()        {            base.OnInit();            packageName = UI_LoadingView.PACKAGE_NAME;            _ui = UI_LoadingView.Create();            this.viewCom = _ui.target;            isfullScreen = true;            _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holder, "ui_dljm", "ui_dljm_jdt_tw");        }        protected override void OnShown()        {            base.OnShown();//1;//            SetProgress(0);            if(this.viewData != null)            {                timePerProgress = (float)this.viewData;            }            else            {                timePerProgress = TimePerProgress;            }            int index = Random.Range(0, resNames.Length);            _ui.m_loaBg.url = ResPathUtil.GetBgImgPath(resNames[index]);            TipsDescCfg[] tipsArray = TipsDescCfgArray.Instance.dataArray;            System.Random rand = new System.Random();            _ui.m_txtDescTop.text = tipsArray[rand.Next(0, tipsArray.Length)].text;        }        protected override void OnHide()        {            base.OnHide();        }        /// <summary>        /// 设置描述文字        /// </summary>        /// <param name="desc"></param>        public void SetDesc(string desc, string descRight = "")        {            if (!ViewManager.isViewOpen(typeof(LoadingView).Name))            {                return;            }            string str = string.Format("{0}  {1}", desc, descRight);//  + descRight;            _ui.m_txtDescLeft.text = str;            // _ui.m_txtDescLeft.text = desc ?? "";            // _ui.m_txtDescRight.text = descRight ?? "";        }        /// <summary>        /// 设置进度0-100        /// </summary>        /// <param name="progress"></param>        /// <param name="callback"></param>        public void SetProgress(long progress, GTweenCallback callback = null)        {            if (!ViewManager.isViewOpen(typeof(LoadingView).Name))            {                return;            }            double oldValule;            GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);            if (twener != null)            {                oldValule = twener.value.d;            }            else            {                oldValule = _ui.m_progressBar1.value;            }            if (progress < oldValule)            {                _ui.m_progressBar1.value = progress;                float posX = _ui.m_progressBar1.width * (progress / 100) + _ui.m_progressBar1.x;                _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);                callback?.Invoke();            }            else            {                float duration = (float)(progress - oldValule) * timePerProgress;                GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>                {                    float posX = _ui.m_progressBar1.width * (t.value.x / 100) + _ui.m_progressBar1.x;                    _ui.m_imgAni.x = Mathf.Min(posX, _ui.m_progressBar1.width + _ui.m_progressBar1.x);                });                if (callback != null)                {                    gtweener.OnComplete(callback);                }            }        }    }}
 |