com.alicizax.unity.tuyoogam.../Samples~/Space Shooter/GameScript/Runtime/GameLogic/SceneHome.cs

33 lines
858 B
C#
Raw Normal View History

2025-09-02 19:21:49 +08:00
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;
}
}
}