123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using Cysharp.Threading.Tasks;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using YooAsset;
- public class YooAssetManager : MonoBehaviour
- {
- public static YooAssetManager Instance { get; private set; }
- /// <summary> 栗都관 </summary>
- public ResourcePackage package;
- /// <summary> Asset얌깨 </summary>
- public Dictionary<string, AssetHandle> handles = new Dictionary<string, AssetHandle>();
- /// <summary> AllAsset얌깨 </summary>
- public Dictionary<string,AllAssetsHandle>allHandles=new Dictionary<string,AllAssetsHandle>();
- /// <summary> SceneAsset얌깨 </summary>
- public Dictionary<string, SceneHandle> sceneHandles = new Dictionary<string, SceneHandle>();
- private void Awake()
- {
- Instance = this;
- package = YooAssets.GetPackage("DefaultPackage");
- //await this.gameObject.AddComponent<Boot>().InitYooAsset();
- //package = YooAssets.GetPackage("DefaultPackage");
- //var ui = await LoadAsset<GameObject>("DlgFaceBuildUI");
- //var go =GameObject.Instantiate(ui);
- //go.transform.SetParent(GameObject.Find("Canvas").transform);
- //go.transform.localPosition = Vector3.zero;
- }
- /// <summary>
- /// 속潼栗都
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="location"></param>
- /// <returns></returns>
- public async UniTask<T> LoadAsset<T>(string location) where T : Object
- {
- AssetHandle handler;
- if (!handles.TryGetValue(location,out handler))
- {
- handler = package.LoadAssetAsync<T>(location);
- await handler.Task;
- handles.Add(location, handler);
- }
- return (T)((AssetHandle)handler).AssetObject;
- }
- /// <summary>
- /// 속潼杰唐栗都
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="location"></param>
- /// <returns></returns>
- public async UniTask<Dictionary<string, T>> LoadAllAsset<T>(string location) where T : Object
- {
- AllAssetsHandle handler;
- if (!allHandles.TryGetValue(location, out handler))
- {
- handler = package.LoadAllAssetsAsync<T>(location);
- await handler.Task;
- allHandles.Add(location, handler);
- }
- Dictionary<string, T> dictionary = new Dictionary<string, T>();
- foreach (UnityEngine.Object assetObj in ((AllAssetsHandle)handler).AllAssetObjects)
- {
- T t = assetObj as T;
- dictionary.Add(t.name, t);
- }
- return dictionary;
- }
- /// <summary>
- /// 속潼끝쒼
- /// </summary>
- /// <param name="location"></param>
- /// <returns></returns>
- public async UniTask LoadScene(string location)
- {
- if (handles.ContainsKey(location))
- return;
- bool activeOnLoad = true;
- SceneHandle handle = package.LoadSceneAsync(location, LoadSceneMode.Additive, activeOnLoad);
- ScenesManager.Instance.handle = handle;
- sceneHandles.Add(location, handle);
- await handle.Task;
- }
- public async UniTask ActivateScene(SceneHandle handle)
- {
- if (handle.Progress >= 0.9)
- {
- handle.ActivateScene();
- await handle.Task;
- }
- }
- }
|