116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using Thousandto.Core.Base;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using Thousandto.Cfg.Data;
|
||
using Thousandto.Code.Center;
|
||
using Thousandto.Core.Asset;
|
||
using UnityEngine;
|
||
using EventManager = UnityEngine.Gonbest.MagicCube.EventManager;
|
||
using EventSystemHandler = UnityEngine.Gonbest.MagicCube.EventSystemHandler;
|
||
using EventMessage = UnityEngine.Gonbest.MagicCube.EventMessage;
|
||
using EventConstDefine = UnityEngine.Gonbest.MagicCube.EventConstDefine;
|
||
using PreLoadEventDefine = UnityEngine.Gonbest.MagicCube.PreLoadEventDefine;
|
||
using FLogger = UnityEngine.Gonbest.MagicCube.FLogger;
|
||
using FFileReader = UnityEngine.Gonbest.MagicCube.FFileReader;
|
||
|
||
namespace Thousandto.Code.Logic
|
||
{
|
||
/// <summary>
|
||
/// 资源预加载
|
||
/// </summary>
|
||
public class PreloadAssetsSystem
|
||
{
|
||
private AssetPreLoader _loader = new AssetPreLoader();
|
||
|
||
public void Initialize()
|
||
{
|
||
_loader.OnFinishedHandler = EnterGame;
|
||
_loader.OnProgressHandler = OnProgress;
|
||
|
||
|
||
}
|
||
|
||
public void Unitialize()
|
||
{
|
||
_loader.OnFinishedHandler = null;
|
||
_loader.OnProgressHandler = null;
|
||
}
|
||
|
||
//预加载完成,进入游戏
|
||
public void EnterGame()
|
||
{
|
||
EventManager.SharedInstance.PushFixEvent(PreLoadEventDefine.EID_STEP_START, 5);
|
||
GameCenter.GameStateSystem.ChangeState((int)GameStateId.Login);
|
||
}
|
||
|
||
public void OnProgress(float pValue)
|
||
{
|
||
GameCenter.UpdateSystem.SetPreloadedCount(_loader.LoadedCount);
|
||
}
|
||
|
||
//开始预加载
|
||
public void StartLoad()
|
||
{
|
||
EventManager.SharedInstance.PushFixEvent(PreLoadEventDefine.EID_STEP_START, 4);
|
||
ReadyAllChars(x=> {
|
||
_loader.AllChars = x;
|
||
FLogger.Log("ReadAllChars Count:", x.Length.ToString());
|
||
});
|
||
_loader.PathList = ReadyAssetPaths();
|
||
#if !UNITY_EDITOR || FUNCELL_LAUNCHER
|
||
//这里特效纹理的Bundle必须预先加载,要不然第一个显示的特效就会出现方块。
|
||
VFXTextureAssetsLoader.PreLoadBundle(() =>
|
||
{
|
||
GameCenter.UpdateSystem.SetPreloadTotal(_loader.PathList.Count);
|
||
_loader.Start();
|
||
});
|
||
#else
|
||
GameCenter.UpdateSystem.SetPreloadTotal(_loader.PathList.Count);
|
||
_loader.Start();
|
||
#endif
|
||
}
|
||
|
||
//准备资源路径
|
||
private List<PreLoadAssetInfo> ReadyAssetPaths()
|
||
{
|
||
List<PreLoadAssetInfo> result = new List<PreLoadAssetInfo>();
|
||
var itor = DeclarePreload.CacheData.GetEnumerator();
|
||
while (itor.MoveNext())
|
||
{
|
||
result.Add(new PreLoadAssetInfo() { Type = itor.Current.Value.Type, AssetName = itor.Current.Value.Path });
|
||
}
|
||
//强制预加载主界面
|
||
#if USE_PC_MODEL
|
||
result.Add(new PreLoadAssetInfo() { Type = 9, AssetName = "UIMainFormPC" });
|
||
#else
|
||
result.Add(new PreLoadAssetInfo() { Type = 9, AssetName = "UIMainForm" });
|
||
#endif
|
||
return result;
|
||
}
|
||
|
||
|
||
//处理所有的字体字符串
|
||
private void ReadyAllChars(Action<string> callBack)
|
||
{
|
||
//只针对中文和台湾进行字符串处理
|
||
if (LanguageSystem.Lang == LanguageConstDefine.CH || LanguageSystem.Lang == LanguageConstDefine.TW)
|
||
{
|
||
//如果空余内存大于300M,或者总内存为1200,则重新刷新UIFont
|
||
if (HardwareManager.MemoryInfo.GetFreeMemory() > 300 || HardwareManager.MemoryInfo.GetSumMemory() > 1200)
|
||
{
|
||
//如果系统能支持2048大小的图片
|
||
if (SystemInfo.maxTextureSize >= 2048)
|
||
{
|
||
var fileName = string.Format(FileUtils.AllCharConfigPath, LanguageSystem.Lang);
|
||
FLogger.Log("ReadAllChars File:", fileName);
|
||
FFileReader.ReadTextAsync(fileName, callBack);
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
callBack(string.Empty);
|
||
}
|
||
}
|
||
}
|