update yooasset2.0

This commit is contained in:
hevinci
2023-09-20 16:10:37 +08:00
parent 01cf9ccd54
commit 6687d75090
253 changed files with 1859 additions and 9299 deletions
@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: beab7f759234b61469afb94f517f959b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,45 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Pooling;
using UniFramework.Window;
using UniFramework.Machine;
using UniFramework.Singleton;
using YooAsset;
internal class FsmInitGame : IStateNode
{
private StateMachine _machine;
void IStateNode.OnCreate(StateMachine machine)
{
_machine = machine;
}
void IStateNode.OnEnter()
{
UniSingleton.StartCoroutine(Prepare());
}
void IStateNode.OnUpdate()
{
}
void IStateNode.OnExit()
{
}
private IEnumerator Prepare()
{
var handle = YooAssets.LoadAssetAsync<GameObject>("UICanvas");
yield return handle;
var canvas = handle.InstantiateSync();
var desktop = canvas.transform.Find("Desktop").gameObject;
GameObject.DontDestroyOnLoad(canvas);
// 初始化窗口系统
UniWindow.Initalize(desktop);
// 初始化对象池系统
UniPooling.Initalize();
_machine.ChangeState<FsmSceneHome>();
}
}
@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 35d459ebb0d7dc947b7b62d1f64a412f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,47 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Window;
using UniFramework.Event;
using UniFramework.Machine;
using UniFramework.Singleton;
using YooAsset;
internal class FsmSceneBattle : IStateNode
{
private BattleRoom _battleRoom;
void IStateNode.OnCreate(StateMachine machine)
{
}
void IStateNode.OnEnter()
{
UniSingleton.StartCoroutine(Prepare());
}
void IStateNode.OnUpdate()
{
if(_battleRoom != null)
_battleRoom.UpdateRoom();
}
void IStateNode.OnExit()
{
if(_battleRoom != null)
{
_battleRoom.DestroyRoom();
_battleRoom = null;
}
}
private IEnumerator Prepare()
{
yield return YooAssets.LoadSceneAsync("scene_battle");
_battleRoom = new BattleRoom();
yield return _battleRoom.LoadRoom();
// 释放资源
var package = YooAssets.GetPackage("DefaultPackage");
package.UnloadUnusedAssets();
}
}
@@ -1,38 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Machine;
using UniFramework.Window;
using UniFramework.Singleton;
using YooAsset;
internal class FsmSceneHome : IStateNode
{
private StateMachine _machine;
void IStateNode.OnCreate(StateMachine machine)
{
_machine = machine;
}
void IStateNode.OnEnter()
{
UniSingleton.StartCoroutine(Prepare());
}
void IStateNode.OnUpdate()
{
}
void IStateNode.OnExit()
{
UniWindow.CloseWindow<UIHomeWindow>();
}
private IEnumerator Prepare()
{
yield return YooAssets.LoadSceneAsync("scene_home");
yield return UniWindow.OpenWindowAsync<UIHomeWindow>("UIHome");
// 释放资源
var package = YooAssets.GetPackage("DefaultPackage");
package.UnloadUnusedAssets();
}
}
@@ -2,63 +2,56 @@
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Event;
using UniFramework.Machine;
using UniFramework.Singleton;
using YooAsset;
public class GameManager : SingletonInstance<GameManager>, ISingleton
public class GameManager
{
private bool _isRun = false;
private EventGroup _eventGroup = new EventGroup();
private StateMachine _machine;
void ISingleton.OnCreate(object createParam)
private static GameManager _instance;
public static GameManager Instance
{
}
void ISingleton.OnDestroy()
{
_eventGroup.RemoveAllListener();
}
void ISingleton.OnUpdate()
{
if (_machine != null)
_machine.Update();
}
public void Run()
{
if (_isRun == false)
get
{
_isRun = true;
// 注册监听事件
_eventGroup.AddListener<SceneEventDefine.ChangeToHomeScene>(OnHandleEventMessage);
_eventGroup.AddListener<SceneEventDefine.ChangeToBattleScene>(OnHandleEventMessage);
Debug.Log("开启游戏流程...");
_machine = new StateMachine(this);
_machine.AddNode<FsmInitGame>();
_machine.AddNode<FsmSceneHome>();
_machine.AddNode<FsmSceneBattle>();
_machine.Run<FsmInitGame>();
}
else
{
Debug.LogWarning("补丁更新已经正在进行中!");
if (_instance == null)
_instance = new GameManager();
return _instance;
}
}
private readonly EventGroup _eventGroup = new EventGroup();
/// <summary>
/// 协程启动器
/// </summary>
public MonoBehaviour Behaviour;
private GameManager()
{
// 注册监听事件
_eventGroup.AddListener<SceneEventDefine.ChangeToHomeScene>(OnHandleEventMessage);
_eventGroup.AddListener<SceneEventDefine.ChangeToBattleScene>(OnHandleEventMessage);
}
/// <summary>
/// 开启一个协程
/// </summary>
public void StartCoroutine(IEnumerator enumerator)
{
Behaviour.StartCoroutine(enumerator);
}
/// <summary>
/// 接收事件
/// </summary>
private void OnHandleEventMessage(IEventMessage message)
{
if(message is SceneEventDefine.ChangeToHomeScene)
if (message is SceneEventDefine.ChangeToHomeScene)
{
_machine.ChangeState<FsmSceneHome>();
YooAssets.LoadSceneAsync("scene_home");
}
else if(message is SceneEventDefine.ChangeToBattleScene)
else if (message is SceneEventDefine.ChangeToBattleScene)
{
_machine.ChangeState<FsmSceneBattle>();
YooAssets.LoadSceneAsync("scene_battle");
}
}
}
@@ -0,0 +1,67 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Event;
using UniFramework.Machine;
using YooAsset;
internal class SceneBattle : MonoBehaviour
{
public GameObject CanvasDesktop;
private AssetHandle _windowHandle;
private AssetHandle _musicHandle;
private BattleRoom _battleRoom;
private IEnumerator Start()
{
// 加载战斗页面
_windowHandle = YooAssets.LoadAssetAsync<GameObject>("UIBattle");
yield return _windowHandle;
_windowHandle.InstantiateSync(CanvasDesktop.transform);
// 加载背景音乐
var package = YooAssets.GetPackage("DefaultPackage");
_musicHandle = package.LoadAssetAsync<AudioClip>("music_background");
yield return _musicHandle;
// 播放背景音乐
var audioSource = this.gameObject.AddComponent<AudioSource>();
audioSource.loop = true;
audioSource.clip = _musicHandle.AssetObject as AudioClip;
audioSource.Play();
_battleRoom = new BattleRoom();
_battleRoom.IntRoom();
}
private void OnDestroy()
{
if (_windowHandle != null)
{
_windowHandle.Release();
_windowHandle = null;
}
if (_musicHandle != null)
{
_musicHandle.Release();
_musicHandle = null;
}
if (_battleRoom != null)
{
_battleRoom.DestroyRoom();
_battleRoom = null;
}
// 切换场景的时候释放资源
var package = YooAssets.GetPackage("DefaultPackage");
package.UnloadUnusedAssets();
}
private void Update()
{
if (_battleRoom != null)
_battleRoom.UpdateRoom();
}
}
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YooAsset;
public class SceneHome : MonoBehaviour
{
public GameObject CanvasDesktop;
private AssetHandle _windowHandle;
private IEnumerator Start()
{
// 加载登录页面
_windowHandle = YooAssets.LoadAssetAsync<GameObject>("UIHome");
yield return _windowHandle;
_windowHandle.InstantiateSync(CanvasDesktop.transform);
}
private void OnDestroy()
{
if (_windowHandle != null)
{
_windowHandle.Release();
_windowHandle = null;
}
// 切换场景的时候释放资源
var package = YooAssets.GetPackage("DefaultPackage");
package.UnloadUnusedAssets();
}
}