You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
4.7 KiB

using System.Collections.Generic;
using UnityEditor.UI;
using UnityEngine;
using YooAsset;
namespace ET
{
public class YooAssetComponentAwakeSystem: AwakeSystem<YooAssetComponent>
{
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<GameObject> 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<GameObject> gameObjList);
if (gameObjList == null)
{
gameObjList = new List<GameObject>();
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<GameObject> gameObjList);
if (gameObjList == null)
{
gameObjList = new List<GameObject>();
self.AutoLoaderGameObjects.Add(autoResLoaderCompHashCode, gameObjList);
}
if (!gameObjList.Contains(go))
{
gameObjList.Add(go);
}
return go;
}
public static async ETTask<T> LoadAssetAsyncAuto<T>(this YooAssetComponent self, int autoResLoaderCompHashCode, string location) where T : UnityEngine.Object
{
var obj = await YooAssetWrapper.LoadAssetAsync<T>(location);
self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List<UnityEngine.Object> objList);
if (objList == null)
{
objList = new List<UnityEngine.Object>();
self.AutoLoaderUnityObjects.Add(autoResLoaderCompHashCode, objList);
}
if (!objList.Contains(obj))
{
objList.Add(obj);
}
return obj;
}
public static T LoadAssetSyncAuto<T>(this YooAssetComponent self, int autoResLoaderCompHashCode, string location) where T : UnityEngine.Object
{
var obj = YooAssetWrapper.LoadAssetSync<T>(location);
self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List<UnityEngine.Object> objList);
if (objList == null)
{
objList = new List<UnityEngine.Object>();
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<GameObject> goList))
{
foreach (GameObject gameObject in goList)
{
YooAssetWrapper.ReleaseInstance(gameObject);
}
}
if (self.AutoLoaderUnityObjects.TryGetValue(autoResLoaderCompHashCode, out List<UnityEngine.Object> objList))
{
foreach (UnityEngine.Object o in objList)
{
YooAssetWrapper.Release(o);
}
}
}
}
}