public static IEnumerator InitCreate <T>(string assetLabel, List <T> assets) where T : Object { yield return(Addressables.LoadAssetsAsync <T>(assetLabel, op => { assets.Add(Object.Instantiate(op)); })); }
void LoadTexture(string key, string label) { Addressables.LoadAssetsAsync <Texture2D>(new List <object> { key, label }, null, Addressables.MergeMode.Intersection).Completed += TextureLoaded; }
public void LoadDeck(DeckData deckToLoad) { targetDeck = deckToLoad; // 加载指定标签的资源(标签类似于AB的Label Variant) // 可以用Label加载比如说:只发给AI的牌,只发给玩家的牌,等等 Addressables.LoadAssetsAsync <CardData>(targetDeck.labelsToInclude[0].labelString, null).Completed += OnResourcesRetrieved; }
public async void Start() { loadHandle = Addressables.LoadAssetsAsync <GameObject>( keys, // Either a single key or a List of keys addressable => { // Called for every loaded asset Debug.Log(addressable.name); }, Addressables.MergeMode.Union, // How to combine multiple labels false); // Whether to fail if any asset fails to load // Wait for the operation to finish in the background await loadHandle.Task; // Instantiate the results float x = 0, z = 0; foreach (var addressable in loadHandle.Result) { if (addressable != null) { Instantiate <GameObject>(addressable, new Vector3(x++ *2.0f, 0, z * 2.0f), Quaternion.identity, transform); // make child of this object if (x > 9) { x = 0; z++; } } } }
public static IEnumerator Initialize <T>(string assetLabel, List <T> assets) { yield return(Addressables.LoadAssetsAsync <T>(assetLabel, op => { assets.Add(op); })); }
public ETTask <T> LoadAssetAsync <T>(string addressPath) where T : UnityEngine.Object { ETTask <T> tTask = ETTask <T> .Create(); var label = GetAssetSkinLabel(addressPath); processingAddressablesAsyncLoaderCount += 1; if (!string.IsNullOrEmpty(label)) { var res = Addressables.LoadAssetsAsync <T>(new List <string> { addressPath, label }, null, Addressables.MergeMode.Intersection); res.Completed += (loader) => { var obj = OnAddressablesAsyncLoaderDone(loader); tTask.SetResult(obj); }; } else { var res = Addressables.LoadAssetAsync <T>(addressPath); res.Completed += (loader) => { var obj = OnAddressablesAsyncLoaderDone(loader); tTask.SetResult(obj); }; } return(tTask); }
public ResourceComplete(AssetLabelReference assetLabel) { var tmpHandle = Addressables.LoadAssetsAsync <Object> (assetLabel, null); tmpHandle.Completed += OnLoadCompleted; handle = tmpHandle; }
private static void ExportPresets() { Addressables.LoadAssetsAsync <BlockDescriptor>("blocks", d => { using var writer = File.CreateText( Path.Combine(Environment.CurrentDirectory, "Definitions/Blocks/", d.name) + ".json"); writer.Write(JsonUtility.ToJson(d)); }); Addressables.LoadAssetsAsync <PieceDescriptor>("pieces", d => { using var writer = File.CreateText( Path.Combine(Environment.CurrentDirectory, "Definitions/Pieces/", d.name) + ".json"); writer.Write(JsonUtility.ToJson(d)); }); Addressables.LoadAssetsAsync <RotationSystemDescriptor>("rotation_systems", d => { var dir = Path.Combine(Environment.CurrentDirectory, "Definitions/RotationSystems/", d.name); Directory.CreateDirectory(dir); foreach (var module in d.modules) { using var writer = File.CreateText(dir + "/" + module.name + ".json"); writer.Write(JsonUtility.ToJson(module)); } }); Addressables.LoadAssetsAsync <SpinDetectorDescriptor>("spin_detectors", d => { using var writer = File.CreateText( Path.Combine(Environment.CurrentDirectory, "Definitions/SpinDetectors/", d.name) + ".json"); writer.Write(JsonUtility.ToJson(d)); }); }
public static IEnumerator AsyncLoadLabel() { if (LabelLoadOver) { yield break; } Addressables.LoadAssetsAsync <ObjT>(Label, (result) => { Set(result.name, result); if (result is GameObject) { var qid = (result as GameObject).GetComponentInChildren <QId>(); if (qid != null) { Set(qid.PrefabId, result); } } }).Completed += (results) => { Debug.Log("[" + Label + "]加载完成总数" + objDic.Count); LabelLoadOver = true; OnLabelLoadOver?.Invoke(); OnLabelLoadOver = null; }; while (!LabelLoadOver) { yield return(null); } }
/// <summary> /// Tile资源加载初始化 /// </summary> private void TileAssetLoadInit() { this.IsAssetLoadCompleted = false; this.TileAssetDict = new Dictionary <string, TileBase>(); Addressables.LoadAssetsAsync <TileBase>(this.TileAssetLabel, this.TileAseetLoadCompleted). Completed += this.TileAssetAllLoadCompleted; }
public static async Task Load() { await Addressables.LoadAssetsAsync <MonsterSet>(typeof(MonsterSet).Name, op => { moduleSets.Add(op.monsterID, op); }).Task; }
private void Start() { var operation = Addressables.LoadAssetsAsync <CharacterProfile>(_labelReference, null); operation.Completed += op => { var stats = from c in op.Result select c.Stats; var maxStats = new Character(); maxStats.JumpSquad = (from s in stats select s.JumpSquad).Max(); maxStats.SoftLanding = (from s in stats select s.SoftLanding).Max(); maxStats.HardLanding = (from s in stats select s.HardLanding).Max(); maxStats.InitialDash = (from s in stats select s.InitialDash).Max(); maxStats.SingleDash = (from s in stats select s.SingleDash).Max(); maxStats.Weight = (from s in stats select s.Weight).Max(); maxStats.WalkSpeed = (from s in stats select s.WalkSpeed).Max(); maxStats.RunSpeed = (from s in stats select s.RunSpeed).Max(); maxStats.AirSpeed = (from s in stats select s.AirSpeed).Max(); maxStats.FallSpeed = (from s in stats select s.FallSpeed).Max(); maxStats.FastFallSpeed = (from s in stats select s.FastFallSpeed).Max(); maxStats.FullHopTime = (from s in stats select s.FullHopTime).Max(); maxStats.ShortHopTime = (from s in stats select s.ShortHopTime).Max(); maxStats.FullHopFastFallTime = (from s in stats select s.FullHopFastFallTime).Max(); maxStats.ShortHopFastFallTime = (from s in stats select s.ShortHopFastFallTime).Max(); maxStats.FullHopFastFallTime = (from s in stats select s.FullHopFastFallTime).Max(); DataNormalizer.MaxStats = maxStats; _scrollView.UpdateData((from c in op.Result select c.Stats).ToList()); }; }
public ResourceHandle LoadAsync <T>(string key, Action <IList <UnityEngine.Object> > callback) { var handle = new ResourceHandle(GenerateHandleId(), key, typeof(T)); Assert.IsTrue(!handle.IsSceneObject); m_HandleList.Add(handle); // キーが存在するかチェックした上でロード var locationHandle = Addressables.LoadResourceLocationsAsync(key); m_ResourceLocationHandleDict.Add(key, locationHandle); locationHandle.Completed += op => { // キーが存在するか var isExists = op.Status == AsyncOperationStatus.Succeeded && op.Result != null && 1 <= op.Result.Count; if (isExists) { // ロード handle.HandleAsssets = Addressables.LoadAssetsAsync <UnityEngine.Object>(key, null); handle.HandleAsssets.Completed += op2 => { if (op2.Status == AsyncOperationStatus.Succeeded) { #if UNITY_EDITOR Fwk.DebugSystem.Log.DebugUseResourceLog.Instance.Append("key:" + key); foreach (var obj in op2.Result) { Fwk.DebugSystem.Log.DebugUseResourceLog.Instance.Append("- " + obj.name); } #endif callback(op2.Result); } else { m_HandleList.Remove(handle); Debug.LogFormat("Status[{0}]: key => {1}", op2.Status, handle.Key); } if (op2.OperationException != null) { Debug.LogWarningFormat("Load is null => {0}", op2.OperationException.ToString()); } }; } else { m_HandleList.Remove(handle); Debug.LogFormat("[key => {0}] 指定キーのリソースがない可能性があります", handle.Key); Debug.Log("実機でのみここに入ってくる場合、Addressable Group のスキーマ設定を見直して下さい"); } // ResourceLocationHandle の後片付け AsyncOperationHandle <IList <IResourceLocation> > resultHandle; m_ResourceLocationHandleDict.TryGetValue(key, out resultHandle); m_ResourceLocationHandleDict.Remove(key); Addressables.Release(resultHandle); }; return(handle); }
private void FillSelectionSlots() //Fills the selection menu with icons based on the current type { string slotLabel = currentSelectionType.ToString(); RectTransform lastTile = unequipTile; Addressables.LoadAssetsAsync <ItemStats>(slotLabel, null).Completed += objects => { foreach (ItemStats item in objects.Result) { if (playerData.GetIsItemUnlocked(item.itemAdress)) { //Spawns a new slot if the item is of the current category and moves it to the next open position either to the right or below the current row ItemSlotBehavior addedSlot = Instantiate(itemSlotPrefab, slotParentTransform).GetComponent <ItemSlotBehavior>(); RectTransform addedSlotTransform = addedSlot.GetComponent <RectTransform>(); float xOffset = lastTile.GetComponent <RectTransform>().anchoredPosition.x + addedSlotTransform.rect.width + spawnSpacing.x; float yOffset = lastTile.GetComponent <RectTransform>().anchoredPosition.y; if (xOffset > slotParentTransform.rect.width / 2f) { xOffset = unequipTile.anchoredPosition.x; yOffset = addedSlotTransform.sizeDelta.y + (spawnSpacing.y + addedSlotTransform.rect.height) * -1f; } addedSlotTransform.anchoredPosition = new Vector2(xOffset, yOffset); addedSlot.SetData(item); addedSlot.customsMenu = this; lastTile = addedSlotTransform; spawnedTiles.Add(addedSlot.gameObject); } } }; }
void LoadTables(AsyncOperationHandle <IList <IResourceLocation> > loadResourcesOperation) { if (loadResourcesOperation.Status != AsyncOperationStatus.Succeeded) { Complete(m_Database, false, "Failed to locate preload tables."); return; } // Do we need to preload any tables? if (loadResourcesOperation.Result.Count == 0) { m_Progress = 1; Complete(m_Database, true, null); return; } // Load the tables m_LoadTablesOperation = Addressables.LoadAssetsAsync <TTable>(loadResourcesOperation.Result, TableLoaded); if (!m_LoadTablesOperation.IsDone) { m_LoadTablesOperation.Completed += LoadTableContents; } else { LoadTableContents(m_LoadTablesOperation); } }
public IEnumerator AddressablesLabelLoad() { if (_objectComplex != null) { DestroyComplex(); } string key = "People.prefab"; string label = "HD"; AsyncOperationHandle <IList <GameObject> > loadAssetHandle = Addressables.LoadAssetsAsync <GameObject>(new List <object> { key, label }, null, Addressables.MergeMode.Intersection); loadAssetHandle.Completed += SwitchToHighDef; //加载到内存中 yield return(loadAssetHandle); if (loadAssetHandle.Status == AsyncOperationStatus.Succeeded && loadAssetHandle.IsValid()) { //_instantiateHandle = Addressables.InstantiateAsync(loadAssetHandle.Result[0]); //Addressables.UnloadSceneAsync //_objectComplex = _instantiateHandle.Result; //Addressables.Release(loadAssetHandle); } }
private void Awake() { // Loading addresable assets by Items label Addressables.LoadAssetsAsync <Item>("Items", null).Completed += obj => { if (obj.Result?.Count > 0) { OnLoaded?.Invoke(obj.Result as List <Item>); } }; /* * // loading configu * var req = Addressables.LoadAssetAsync<TextAsset>("Assets/BlackBoard/Data/" + Name + "/Default.bytes"); * req.Completed += op => * { * if (req.Result != null) * { * var s = new MemoryStream(req.Result.bytes); * entries = (BlackBoardEntry[]) binaryFormatter.Deserialize(s); * Addressables.Release(req); * * for (var i = 0; i < entries.Length && i < m_Entries.Capacity; i++) * { * m_Entries.TryAdd(i, entries[i]); * } * * OnEntriesLoaded?.Invoke(); * } * }; */ }
void LoadPrefab(string key, string label) { Addressables.LoadAssetsAsync <GameObject>(new List <object> { key, label }, null, Addressables.MergeMode.Intersection).Completed += PrefabLoaded; }
void InstantiateAsync() { //AsyncOperationHandle<GameObject> goHandle = Addressables.LoadAssetAsync<GameObject>("gameObjectKey"); Addressables.LoadAssetsAsync <MapData>(mapDataName, (asset) => { foreach (MapObject a in asset.mapObjects) { var map = new GameObject(asset.name); map.transform.parent = enviorment.transform; if (AddressResourceExist(a.objectName)) { //Addressables.InstantiateAsync(a.objectName,map.transform, (prefab) => Addressables.LoadAssetsAsync <GameObject>(a.objectName, (prefab) => { var o = GameObject.Instantiate(prefab, map.transform, false); o.name = a.name; o.transform.position = a.pos; o.transform.rotation = a.rot; o.transform.localScale = a.scale; loadedGameObjects.Add(o); }); } else { Debug.LogWarning("Address 不存在:" + a.objectName); } } }); }
public static void LoadAssets() { Addressables.LoadAssetsAsync <TextAsset>("LineDescriptors", null).Completed += OnLineDescritorsLoaded; Addressables.LoadAssetAsync <GameObject>(DIALOG_ANSWER_ASSET_NAME).Completed += OnAnswerHandlerAssetLoaded; SceneManager.sceneLoaded += OnSceneLoaded; DialoguesSettingsManager.OnAudioLocalisationKeyChanged += OnAudioLocalisationKeyChanged; }
/// <summary> /// 异步加载资源集合 /// </summary> /// <param name="label"></param> /// <param name="callback"></param> /// <param name="completed"></param> /// <typeparam name="T"></typeparam> /// <returns></returns> public static AsyncOperationHandle <IList <T> > LoadAssetsAsync <T>(AssetLabelReference label, Action <T> callback, Action <AsyncOperationHandle <IList <T> > > completed = null) { var operation = Addressables.LoadAssetsAsync <T>(label, callback); operation.Completed += completed; return(operation); }
/// <summary> /// 根据标签和名字异步加载资源 /// </summary> /// <typeparam name="T">资源名字</typeparam> /// <param name="labelOrNames">标签和名字</param> /// <returns>所有的资源</returns> public async UniTask <IList <T> > LoadAllAsyncWithLabelAndNames <T>(IList <string> labelOrNames) where T : Object { keys.Clear(); foreach (var key in labelOrNames) { keys.Add(key); } return(await Addressables.LoadAssetsAsync <T>(keys, null, Addressables.MergeMode.Intersection).Task); }
//================ Variation public static AsyncOperationHandle <IList <T> > LoadAssetsAsync <T>(string pAddress, string pLabel, Action <float> pProgress = null, Action <IList <T> > pOnCompleted = null) { var operation = Addressables.LoadAssetsAsync <T>(new List <object> { pAddress, pLabel }, null, Addressables.MergeMode.Intersection); WaitLoadTask(operation, pProgress, pOnCompleted); return(operation); }
void LoadTexture(string key, string label) { m_Mat = GetComponent <MeshRenderer>().material; Addressables.LoadAssetsAsync <Texture2D>(new List <object> { key, label }, null, Addressables.MergeMode.Intersection).Completed += TextureLoaded; }
public void loadUI() { //需要将ui用到的物体在addressable中添加“ui”标签,方便统一加载 AssetLabelReference assetLabelReference = new AssetLabelReference { labelString = "ui" }; Addressables.LoadAssetsAsync <GameObject>(assetLabelReference, null).Completed += OnResourceloadFinshed; }
// Start is called before the first frame update void Start() { Addressables.LoadAssetsAsync <TextAsset>(new List <string> { "GameStrings", "zhCN" }, null, Addressables.MergeMode.Intersection).Completed += Language_Completed; Addressables.LoadAssetsAsync <TextAsset>(new List <string> { "GameStrings", "enUS" }, null, Addressables.MergeMode.Intersection).Completed += Language_Completed; }
public void ShowStuff() { var asyncOp = Addressables.LoadAssetsAsync <TextureExample>(theLabel, ProcessCallback); //BAD asyncOp.Completed += (handle) => { Debug.Log("Completed"); Addressables.Release(asyncOp); }; }
public static AsyncOperationHandle <IList <T> > LoadAssetsForLabelAsync <T>(AssetLabelReference label, Action <IList <T> > callback) { var handle = Addressables.LoadAssetsAsync <T>(label, null); handle.Completed += (args) => { callback?.Invoke(args.Result); }; return(handle); }
public static void Init() { var operation = Addressables.LoadAssetsAsync <GameObject>(PickupsLabel, _ => { }); operation.Completed += handle => { pickupPrefabs = new List <GameObject>(handle.Result); loaded = true; }; }
private async Task LoadSongsData() { AsyncOperationHandle <IList <SongInfo> > songDataHandle = Addressables.LoadAssetsAsync <SongInfo>(_dataAssetsToLoad.SongsDataLabel, LoadSongsCompleted); await songDataHandle.Task; foreach (var item in SongDictionary) { Debug.Log(item.Key); } }