// ============================================================================
// IYooAssetService.cs — YooAsset 资源加载服务接口
// 定义在 Main 程序集中,供所有业务系统使用
// ============================================================================
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine;
using UnityEngine.SceneManagement;
using YooAsset;
namespace ProjSG.Resource
{
///
/// YooAsset 资源加载服务接口。
/// 封装 YooAsset ResourcePackage 的核心加载能力,提供 UniTask 异步 API。
///
public interface IYooAssetService
{
///
/// 服务是否已初始化完成
///
bool IsInitialized { get; }
///
/// 当前运行模式
///
EPlayMode PlayMode { get; }
// ====================================================================
// 初始化
// ====================================================================
///
/// 初始化 YooAsset 资源服务。
/// 在 Launch 阶段由 YooAssetInitializer 调用。
///
/// 运行模式
/// CDN 远程服务(HostPlayMode/WebPlayMode 必需)
/// 初始化完成
UniTask InitializeAsync(EPlayMode playMode, IRemoteServices remoteServices = null);
// ====================================================================
// 资源加载 — Asset
// ====================================================================
///
/// 异步加载指定类型的资源。
///
/// 资源类型(GameObject, Sprite, AudioClip 等)
/// YooAsset 资源地址
/// 加载优先级(0 = 默认)
/// 取消令牌
/// 加载完成的资源对象,加载失败返回 null
UniTask LoadAssetAsync(string location, uint priority = 0,
CancellationToken ct = default) where T : UnityEngine.Object;
///
/// 异步加载指定类型的资源(Type 参数版本)。
///
UniTask LoadAssetAsync(string location, Type type, uint priority = 0,
CancellationToken ct = default);
///
/// 异步加载子资源(如 SpriteAtlas 中的 Sprite)。
///
UniTask LoadSubAssetsAsync(string location, uint priority = 0,
CancellationToken ct = default) where T : UnityEngine.Object;
///
/// 异步加载同一 Bundle 下的所有同类型资源。
///
UniTask LoadAllAssetsAsync(string location, uint priority = 0,
CancellationToken ct = default) where T : UnityEngine.Object;
// ====================================================================
// 资源加载 — RawFile
// ====================================================================
///
/// 异步加载原始文件并返回文本内容。
/// 用于配置文件(.txt, .json, .csv 等)加载。
///
UniTask LoadRawFileTextAsync(string location, CancellationToken ct = default);
///
/// 异步加载原始文件并返回字节数组。
///
UniTask LoadRawFileBytesAsync(string location, CancellationToken ct = default);
// ====================================================================
// 场景加载
// ====================================================================
///
/// 异步加载场景。
///
UniTask LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single,
LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 0, CancellationToken ct = default);
// ====================================================================
// 资源信息查询
// ====================================================================
///
/// 检查资源地址是否有效。
///
bool CheckLocationValid(string location);
///
/// 获取指定标签的所有资源信息。
///
YooAsset.AssetInfo[] GetAssetInfosByTag(string tag);
///
/// 检查资源是否需要从远程下载。
///
bool IsNeedDownloadFromRemote(string location);
// ====================================================================
// 资源下载
// ====================================================================
///
/// 创建资源下载器并开始下载。
///
UniTask DownloadByTagsAsync(string[] tags, int downloadingMaxNumber = 10,
int failedTryAgain = 3, IProgress progress = null, CancellationToken ct = default);
// ====================================================================
// 版本管理
// ====================================================================
///
/// 请求最新包裹版本。
///
UniTask RequestPackageVersionAsync(CancellationToken ct = default);
///
/// 更新包裹 Manifest 到指定版本。
///
UniTask UpdatePackageManifestAsync(string packageVersion, CancellationToken ct = default);
// ====================================================================
// 资源释放
// ====================================================================
///
/// 释放资源句柄(引用计数 -1)。
///
void ReleaseHandle(HandleBase handle);
///
/// 卸载所有引用计数为零的资源。
///
UniTask UnloadUnusedAssetsAsync();
///
/// 强制卸载所有资源。
///
UniTask UnloadAllAssetsAsync();
}
}