Files
taptap2024_GJ_chidouren/Assets/Scripts/System/StateSystem/State/StateRoom.cs
2024-10-23 18:46:37 +08:00

85 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.StateSystem;
using Framework.Asset;
using Framework.Audio;
using Framework.FSMLite;
using Framework.GamePool.manager;
using Framework.UI;
using Game;
using Game.Data;
using Game.Manager;
using Runtime.ADAggregator;
using StateSystem.Loader;
using UnityEngine;
using UnityEngine.SceneManagement;
using Views;
using Object = UnityEngine.Object;
namespace StateSystem.State
{
public class StateRoom : StateMachine<GameGlobalState>
{
public static string RoomGroup = "ROOM_OBJECT_GROUP";
private SceneLoader _loader;
protected override void OnEnter(params object[] args)
{
ADManager.Instance.LoadAD (AD_Type.AwardVideo);
//预加载资源
Debug.Log ("Asset pre load " + AssetManager.ResRootPath + "AutoSource/");
AssetManager.Instance.LoadAssets<Object>(AssetManager.ResRootPath + "AutoSource/");
PoolObjectPreload ();
// GameManager.Instance.StartAutoSave ();
// LoadScene ();
OnActived ();
}
private void LoadScene ()
{
var activeScene = SceneManager.GetActiveScene();
if (activeScene.name != SceneName.GameScene.ToString())
{
Debug.Log("进入Home开始加载场景" + SceneName.GameScene);
this._loader = new SceneLoader(SceneName.GameScene);
this._loader.BeginLoad(OnLoading, OnActived);
}
else
{
OnActived();
}
}
private void OnLoading(float obj)
{
Debug.Log("加载进度: " + obj);
if (obj >= 1)
{
// Debug.Log("加载完成");
this._loader.Active();
}
}
private void OnActived()
{
RoomManager.Instance.JoinGame ();
}
private void PoolObjectPreload ()
{
GamePoolManager.Instance.LoadPoolObjects("",RoomGroup , 5);
// GamePoolManager.Instance.LoadPoolObjects("Object/",RoomGroup , 5);
}
protected override void OnExit()
{
UIManager.Instance.CloseViewWithGroup (RoomGroup);
GamePoolManager.Instance.KillForGroup (RoomGroup);
GameManager.Instance.EndAutoSave ();
Account.Instance.Save();
AssetManager.Instance.UnLoadAssets(AssetManager.ResRootPath + "AutoSource/" , false);
SpriteLoaderMgr.Instance.Clear ();
}
}
}