using System.Collections.Generic; using UnityEditor.UI; using UnityEngine; using YooAsset; namespace ET { public class YooAssetComponentAwakeSystem: AwakeSystem { public override void Awake(YooAssetComponent self) { self.Awake(); } } [FriendClass(typeof(YooAssetComponent))] public static partial class YooAssetComponentSystem { public static void Awake(this YooAssetComponent self) { YooAssetComponent.Instance = self; } public static async ETTask Init(this YooAssetComponent self) { // var locationService = new DefaultLocationServices("Assets/Bundles"); // string url = "http://127.0.0.1/CDN1/Android"; // var playMode = YooAssets.EPlayMode.HostPlayMode; // if (Define.IsEditor) // { // playMode = YooAssets.EPlayMode.EditorSimulateMode; // } // // await YooAssetWrapper.InitializeAsync(playMode, url, new AddressLocationServices()); } public static async ETTask InstantiateAsyncAuto(this YooAssetComponent self, int autoResLoaderCompHashCode, string location, Transform parent_transform = null, bool stay_world_space = false) { var go = await YooAssetWrapper.InstantiateAsync(location, parent_transform, stay_world_space); self.AutoLoaderGameObjects.TryGetValue(autoResLoaderCompHashCode, out List gameObjList); if (gameObjList == null) { gameObjList = new List(); self.AutoLoaderGameObjects.Add(autoResLoaderCompHashCode, gameObjList); } if (!gameObjList.Contains(go)) { gameObjList.Add(go); } return go; } public static GameObject InstantiateSyncAuto(this YooAssetComponent self, int autoResLoaderCompHashCode, string location, Transform parent_transform = null, bool stay_world_space = false) { var go = YooAssetWrapper.InstantiateSync(location, parent_transform, stay_world_space); self.AutoLoaderGameObjects.TryGetValue(autoResLoaderCompHashCode, out List gameObjList); if (gameObjList == null) { gameObjList = new List(); self.AutoLoaderGameObjects.Add(autoResLoaderCompHashCode, gameObjList); } if (!gameObjList.Contains(go)) { gameObjList.Add(go); } return go; } public static async ETTask LoadAssetAsyncAuto(this YooAssetComponent self, int autoResLoaderCompHashCode, string location) where T : UnityEngine.Object { var obj = await YooAssetWrapper.LoadAssetAsync(location); self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List objList); if (objList == null) { objList = new List(); self.AutoLoaderUnityObjects.Add(autoResLoaderCompHashCode, objList); } if (!objList.Contains(obj)) { objList.Add(obj); } return obj; } public static T LoadAssetSyncAuto(this YooAssetComponent self, int autoResLoaderCompHashCode, string location) where T : UnityEngine.Object { var obj = YooAssetWrapper.LoadAssetSync(location); self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List objList); if (objList == null) { objList = new List(); self.AutoLoaderUnityObjects.Add(autoResLoaderCompHashCode, objList); } if (!objList.Contains(obj)) { objList.Add(obj); } return obj; } public static void ReleaseAuto(this YooAssetComponent self, int autoResLoaderCompHashCode) { if (self.AutoLoaderGameObjects.TryGetValue(autoResLoaderCompHashCode, out List goList)) { foreach (GameObject gameObject in goList) { YooAssetWrapper.ReleaseInstance(gameObject); } } if (self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List objList)) { foreach (UnityEngine.Object o in objList) { YooAssetWrapper.Release(o); } } } } }