94 lines
2.8 KiB
C#
94 lines
2.8 KiB
C#
using System.Collections;
|
|
|
|
using UnityEngine;
|
|
using Thousandto.Core.Base;
|
|
using Thousandto.Code.Center;
|
|
using Thousandto.Core.Support;
|
|
using Thousandto.Core.Asset;
|
|
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;
|
|
|
|
namespace Thousandto.Code.Logic
|
|
{
|
|
/// <summary>
|
|
/// 预加载状态
|
|
/// </summary>
|
|
public class PreLoadState : GameStateBase
|
|
{
|
|
#region//私有变量
|
|
float m_delay = 0;
|
|
bool _waiting = false;
|
|
|
|
//等2秒
|
|
float _waitTime = 2.0f;
|
|
|
|
private bool _startLoadRes = false;
|
|
|
|
#endregion
|
|
|
|
#region//构造函数
|
|
public PreLoadState(GameStateId id) : base(id)
|
|
{
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region//重写父类GameStateBase的函数
|
|
protected override GameStateId OnGetStateID()
|
|
{
|
|
return GameStateId.PreLoad;
|
|
}
|
|
|
|
|
|
protected override void OnEnter()
|
|
{
|
|
EventManager.SharedInstance.PushFixEvent(PreLoadEventDefine.EID_STEP_START, 3);
|
|
ResourcesEx.IsPreLoadState = true;
|
|
_startLoadRes = false;
|
|
ShaderManager.SharedInstance.DestoryShaderFactory();
|
|
ShaderManager.SharedInstance.CreateShaderFactory();
|
|
}
|
|
|
|
protected override void OnLeave()
|
|
{
|
|
ResourcesEx.IsPreLoadState = false;
|
|
}
|
|
|
|
protected override bool OnUpdate(float deltaTime)
|
|
{
|
|
if (!_startLoadRes)
|
|
{
|
|
if (ShaderManager.SharedInstance.CheckReadyOK())
|
|
{
|
|
//Debug.Log("Shader包加载完毕");
|
|
_startLoadRes = true;
|
|
//启动预加载
|
|
GameCenter.PreloadAssetsSystem.StartLoad();
|
|
//这个时候Shader才加载完毕,防止shader加载失败,对所有的后处理脚本进行初始化处理
|
|
InitPostEffectScript();
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 对所有的后处理脚本进行初始化处理
|
|
/// </summary>
|
|
private void InitPostEffectScript()
|
|
{
|
|
for (int i = 0; i < Camera.allCamerasCount; i++)
|
|
{
|
|
var c = Camera.allCameras[i];
|
|
if (c != null && c.gameObject != null && c.enabled)
|
|
{
|
|
c.gameObject.SendMessage("OnPostEffectInit", SendMessageOptions.DontRequireReceiver);
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|