using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;public class AddressableManager : MonoBehaviour
{public static AddressableManager instance;List
资源加载
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;public class AssetManager : MonoBehaviour
{public AssetReference assetReference;[AssetReferenceUILabelRestriction("HD")]public AssetReference assetReferenceHD;public AssetReferenceGameObject assetReferenceGameObject;public AssetReferenceT textureAsset;//private void Awake()//{// Debug.Log("");//}void Start(){//AsyncOperationHandle res = assetReferenceGameObject.LoadAssetAsync();//res.Completed += Res_Completed;DontDestroyOnLoad(this.gameObject);// LoadByName("Prefab1");AddressableManager.instance.onCheckFinish += Instance_onCheckFinish;StartCoroutine(AddressableManager.instance.CheckUpadate());}private void Instance_onCheckFinish(AsyncOperationStatus status){Debug.Log("finish status is " + status);Debug.Log("Path is " + Application.persistentDataPath);if (status == AsyncOperationStatus.Succeeded) {LoadByName("Prefab3");LoadByName("SD");//prefab2InstantitateByName("Prefab4");}}private void Res_Completed(AsyncOperationHandle obj){if (obj.Status == AsyncOperationStatus.Succeeded){GameObject gob = Instantiate(obj.Result);Transform parent = GameObject.Find("Canvas").GetComponent();gob.transform.SetParent(parent);}}private void LoadByName(string name){Addressables.LoadAssetAsync(name).Completed += (handle) => {if (handle.Status == AsyncOperationStatus.Succeeded){GameObject gob = Instantiate(handle.Result, GameObject.Find("Canvas").GetComponent());Debug.Log($"加载资源完毕:{gob.name}");}else Debug.Log($"加载资源失败:{name}");};}private void InstantitateByName(string name){Addressables.InstantiateAsync(name).Completed += (handle) => {if (handle.Status == AsyncOperationStatus.Succeeded){GameObject gob = handle.Result;gob.transform.SetParent(GameObject.Find("Canvas").GetComponent());gob.GetComponent().anchoredPosition = Vector2.zero;Debug.Log("实例化对象创建完毕" + gob.name);}else Debug.Log($"加载资源失败:{name}");};}}
配置文件
using System.Collections;
using System.Collections.Generic;
using UnityEngine;public class ConfigManager
{public static string CdnUrl = "http://192.168.133.144/Files/dev";//public static string RemoteCachePath { get { return Application.persistentDataPath + "/android"; } }public static string RemoteCachePath { get {
#if UNITY_EDITORreturn "AddresableAsset/android";
#elsereturn Application.persistentDataPath+"/AddresableAsset";
#endif}}
}