【m】框架大更新

This commit is contained in:
2025-10-31 11:18:23 +08:00
parent ae6e7c804b
commit 8e1d52ddbf
1883 changed files with 213934 additions and 640 deletions

View File

@@ -0,0 +1,57 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniFramework.Event;
using YooAsset;
public class GameManager
{
private static GameManager _instance;
public static GameManager Instance
{
get
{
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)
{
YooAssets.LoadSceneAsync("scene_home");
}
else if (message is SceneEventDefine.ChangeToBattleScene)
{
YooAssets.LoadSceneAsync("scene_battle");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6630e7de79efb24b9263519ba4282e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,75 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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);
// 加载背景音乐
_musicHandle = YooAssets.LoadAssetAsync<AudioClip>("music_background");
yield return _musicHandle;
// 播放背景音乐
var audioSource = this.gameObject.AddComponent<AudioSource>();
audioSource.loop = true;
audioSource.clip = _musicHandle.AssetObject as AudioClip;
audioSource.Play();
// 切换场景的时候释放资源
var package = YooAssets.GetPackage("DefaultPackage");
var operation = package.UnloadUnusedAssetsAsync();
yield return operation;
_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;
}
// 切换场景的时候释放资源
if (YooAssets.Initialized)
{
var package = YooAssets.GetPackage("DefaultPackage");
var operation = package.UnloadUnusedAssetsAsync();
operation.WaitForAsyncComplete();
}
}
private void Update()
{
if (_battleRoom != null)
_battleRoom.UpdateRoom();
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 54061fd8bcab2344e87b0faf0464c179
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
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);
// 切换场景的时候释放资源
var package = YooAssets.GetPackage("DefaultPackage");
var operation = package.UnloadUnusedAssetsAsync();
yield return operation;
}
private void OnDestroy()
{
// 释放资源句柄
if (_windowHandle != null)
{
_windowHandle.Release();
_windowHandle = null;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 41730f8e5f2b6e64abc4a03035c61ea5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: