1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- /// <summary>
- ///
- /// </summary>
- public class TextAssetManager : MonoSingleton<TextAssetManager>
- {
- /// <summary>
- /// 资源
- /// </summary>
- public Dictionary<string, TextAsset> mIconRes = new Dictionary<string, TextAsset>();
-
- /// <summary>
- /// 初始化
- /// </summary>
- private void Start()
- {
- mIconRes.Clear();
- //LoadRes("GateDialog", () =>
- //{
- //});
- }
-
- /// <summary>
- /// 加载资源
- /// </summary>
- /// <param name="bundleName"> 资源包的名称 </param>
- /// <param name="ac"> 加载完后执行的回调 </param>
- 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();
- });
- }
- /// <summary>
- /// 获取资源
- /// </summary>
- /// <param name="iconContainer">容器bundle名称</param>
- /// <param name="resName"> 查找的名称 </param>
- /// <param name="callBack">赋值成功后回调</param>
- public void GetTextAsset(string iconContainer, string resName, Action<TextAsset> 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);
- }
- });
- }
- }
- /// <summary>
- /// 对话
- /// </summary>
- public const string GateDialogBundleName = "GateDialog";
- }
|