赞
踩
首先写一个类包含ab和ab对应的引用以及对应的卸载方法,在写一个ab的管理类,包括全局ab的加载,卸载,以及相关根据引用数来判断是重内存中是否删除对应的依赖资源,是新建资源还是重内存中获取资源重而达到在ab适度颗粒话下的内存优化!
脚本:
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class AssetBundleInfos
- {
- public AssetBundle assetBundle;
- public int referencedCount;//引用数
- internal event Action unload;
-
- internal void OnUnload()
- {
- assetBundle.Unload(false);
- if (unload != null)
- unload();
- }
- }
- public class Resource_LoadManager
- {
- AssetBundleManifest assetBundleManifest = null;
- Dictionary<string, string[]> dependencies = new Dictionary<string, string[]>();
- Dictionary<string, AssetBundleInfos> loadeAssetBundle = new Dictionary<string, AssetBundleInfos>();
-
- // Use this for initialization
- public Resource_LoadManager()
- {
- //Initalize();
-
- }
-
- //初始化加载所有的依赖项目
- public void Initalize()
- {
- AssetBundle bundle;
- switch (Application.platform)
- {
- case RuntimePlatform.Android:
- bundle = AssetBundle.LoadFromFile(System.IO.Path.Combine(DataPath, "Android"));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。