//--------------------------------------------------------
|
// [Author]: 第二世界
|
// [ Date ]: Monday, September 04, 2017
|
//--------------------------------------------------------
|
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using TableConfig;
|
|
namespace Snxxz.UI
|
{
|
|
public class LoadingWin : Window
|
{
|
public static int targetMapResId = 0;
|
|
[SerializeField] Image m_BackGround;
|
[SerializeField] RectTransform m_ContainerFunctions;
|
[SerializeField] LoadingFunctionShow[] m_FunctionShows;
|
[SerializeField] SmoothSlider m_ProgressSlider;
|
[SerializeField] Transform m_EffectPoint;
|
[SerializeField] RectTransform m_ContainerMapName;
|
[SerializeField] Image m_MapName;
|
[SerializeField] RectTransform m_ContainerMapDescription;
|
[SerializeField] Image m_MapDescription;
|
|
float refProgress = 0f;
|
float expectDuration = 5f;
|
|
#region Built-in
|
protected override void BindController()
|
{
|
}
|
|
protected override void AddListeners()
|
{
|
}
|
|
protected override void OnPreOpen()
|
{
|
var mapResConfig = Config.Instance.Get<MapResourcesConfig>(targetMapResId);
|
if (mapResConfig != null && mapResConfig.LoadingBG.Length > 0)
|
{
|
var randomIndex = UnityEngine.Random.Range(0, mapResConfig.LoadingBG.Length > 1 ? mapResConfig.LoadingBG.Length + 1 : 1);
|
if (randomIndex == mapResConfig.LoadingBG.Length)
|
{
|
m_BackGround.SetSprite(GeneralConfig.Instance.LoadLV);
|
m_ContainerFunctions.gameObject.SetActive(true);
|
var functions = GetShowFunctions(PlayerDatas.Instance.baseData.LV == 0 ? PlayerDatas.Instance.loginInfo.LV : PlayerDatas.Instance.baseData.LV);
|
for (int i = 0; i < m_FunctionShows.Length; i++)
|
{
|
var show = m_FunctionShows[i];
|
show.Display(functions[i]);
|
}
|
}
|
else
|
{
|
m_BackGround.SetSprite(mapResConfig.LoadingBG[randomIndex]);
|
m_ContainerFunctions.gameObject.SetActive(false);
|
}
|
}
|
|
if (mapResConfig != null && !string.IsNullOrEmpty(mapResConfig.LoadName))
|
{
|
m_ContainerMapName.gameObject.SetActive(true);
|
m_MapName.SetSprite(mapResConfig.LoadName);
|
}
|
else
|
{
|
m_ContainerMapName.gameObject.SetActive(false);
|
}
|
|
if (mapResConfig != null && !string.IsNullOrEmpty(mapResConfig.LoadDescription))
|
{
|
m_ContainerMapDescription.gameObject.SetActive(true);
|
m_MapDescription.SetSprite(mapResConfig.LoadDescription);
|
}
|
else
|
{
|
m_ContainerMapDescription.gameObject.SetActive(false);
|
}
|
|
m_ProgressSlider.value = refProgress = 0f;
|
StageManager.Instance.loadingProgressEvent += UpdateLoadingProgress;
|
}
|
|
protected override void OnAfterOpen()
|
{
|
}
|
|
protected override void OnPreClose()
|
{
|
StageManager.Instance.loadingProgressEvent -= UpdateLoadingProgress;
|
|
if (!AssetSource.uiFromEditor)
|
{
|
AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loading", true, false);
|
AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loadingbg", true, false);
|
}
|
}
|
|
protected override void OnAfterClose()
|
{
|
}
|
#endregion
|
|
|
protected override void LateUpdate()
|
{
|
base.LateUpdate();
|
|
refProgress = Mathf.Clamp01(refProgress + Time.deltaTime / expectDuration);
|
m_ProgressSlider.value = refProgress;
|
}
|
|
void UpdateLoadingProgress(float _progress)
|
{
|
m_ProgressSlider.value = refProgress = Mathf.Max(_progress, refProgress);
|
}
|
|
|
private List<int> GetShowFunctions(int _level)
|
{
|
var configs = Config.Instance.GetAllValues<LoadingFunctionConfig>();
|
var functions = new List<int>() { configs[0].ID, configs[1].ID, configs[2].ID, configs[3].ID };
|
for (int i = 4; i < configs.Count; i++)
|
{
|
var config = Config.Instance.Get<LoadingFunctionConfig>(functions[2]);
|
if (_level >= config.Level)
|
{
|
functions.RemoveAt(0);
|
functions.Add(configs[i].ID);
|
}
|
}
|
|
return functions;
|
}
|
|
}
|
|
}
|
|
|
|
|