using UnityEngine; using System; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; /// /// /// public class TextAssetManager : MonoSingleton { /// /// 资源 /// public Dictionary mIconRes = new Dictionary(); /// /// 初始化 /// private void Start() { mIconRes.Clear(); //LoadRes("GateDialog", () => //{ //}); } /// /// 加载资源 /// /// 资源包的名称 /// 加载完后执行的回调 private void LoadRes(string bundleName, Action ac) { ResourceHelper.Instance.LoadAssetBundle(bundleName, (AssetBundle bundle) => { if (null != bundle) { GameObject go = (GameObject)bundle.LoadAsset(bundleName); UnityEngine.Object[] sprObj = bundle.LoadAllAssets(typeof(TextAsset)); foreach (UnityEngine.Object obj in sprObj) { mIconRes[obj.name] = (TextAsset)obj; } } ac(); }); } /// /// 获取资源 /// /// 容器bundle名称 /// 查找的名称 /// 赋值成功后回调 public void GetTextAsset(string iconContainer, string resName, Action callBack) { string bundleName = resName; if (mIconRes.ContainsKey(bundleName) && mIconRes[bundleName] != null) { if (callBack != null) { callBack(mIconRes[bundleName]); } } else { LoadRes(IconPrefixConst.getIconContainerName(iconContainer), () => { if (mIconRes.ContainsKey(bundleName)) { if (callBack != null) { callBack(mIconRes[bundleName]); } } else { callBack(null); } }); } } /// /// 对话 /// public const string GateDialogBundleName = "GateDialog"; }