123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- using FairyGUI;
- using UI.Loading;
- using UnityEngine;
- namespace GFGGame
- {
- public class LoadingView : BaseWindow
- {
- private UI_LoadingView _ui;
- private const float SPEED = 0.01f;
- private string[] resNames = { "11", "33" };
- private GameObject _effectObj;
- private GoWrapper _wrapper;
- 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()
- {
- base.Dispose();
- SceneController.DestroyObjectFromView(_effectObj);
- }
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_LoadingView.PACKAGE_NAME;
- _ui = UI_LoadingView.Create();
- this.viewCom = _ui.target;
- isfullScreen = true;
- string resPath1 = ResPathUtil.GetViewEffectPath("ui_dljm", "ui_dljm_jdt_tw");
- SceneController.AddObjectToView(null, null, _ui.m_holder, resPath1, out _effectObj, out _wrapper);
- }
- protected override void OnShown()
- {
- base.OnShown();//1;//
- SetProgress(0);
- _ui.m_txtDescLeft.text = "正在进入游戏";
- int index = Random.Range(0, resNames.Length);
- _ui.m_loaBg.url = string.Format("ui://Loading/{0}", resNames[index]);
- }
- protected override void OnHide()
- {
- base.OnHide();
- }
- /// <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;
- }
- GTweener twener = GTween.GetTween(_ui.m_progressBar1, TweenPropType.Progress);
- if (twener != null)
- {
- twener.Kill(true);
- }
- if (progress < _ui.m_progressBar1.value)
- {
- _ui.m_progressBar1.value = progress;
- _ui.m_imgAni.x = _ui.m_progressBar1.width * (progress / 100) - 120;
- callback?.Invoke();
- }
- else
- {
- float duration = (float)(progress - _ui.m_progressBar1.value) * SPEED;
- GTweener gtweener = _ui.m_progressBar1.TweenValue(progress, duration).OnUpdate((GTweener t) =>
- {
- _ui.m_imgAni.x = _ui.m_progressBar1.width * (t.value.x / 100) - 120;
- });
- if (callback != null)
- {
- gtweener.OnComplete(callback);
- }
- }
- }
- }
- }
|