/// <summary>
    /// 异步加载
    /// </summary>
    /// <param name="assetName"></param>
    /// <param name="assetType"></param>
    /// <param name="listener"></param>
    private void LoadAsync(string assetName, Type assetType, IResourceListener listener)
    {
        //正在被加载 还没加载完成
        foreach (LoadAsset item in loadingList)
        {
            if (item.AssetName == assetName)
            {
                item.AddListener(listener);
                return;
            }
        }
        //等待的队列里面有
        foreach (LoadAsset item in waitingQue)
        {
            if (item.AssetName == assetName)
            {
                item.AddListener(listener);
                return;
            }
        }
        //都没有 先创建
        LoadAsset asset = new LoadAsset();

        asset.AssetName = assetName;
        asset.AssetType = assetType;
        asset.AddListener(listener);
        //添加到等待队列
        waitingQue.Enqueue(asset);
    }
示例#2
0
    /// <summary>
    /// 异步加载
    /// </summary>
    /// <param name="assetPath">资源路径</param>
    /// <param name="assetType">资源类型</param>
    /// <param name="listener">回调</param>
    private void LoadAsync(string assetPath, Type assetType, IResourceListener listener)
    {
        //正在被加载,还没加载完成
        foreach (LoadAssets item in loadingList)
        {
            if (item.AssetPath == assetPath)
            {
                item.AddListener(listener);
                return;
            }
        }
        //等待的队列里面有
        foreach (LoadAssets item in waitingQueue)
        {
            if (item.AssetPath == assetPath)
            {
                item.AddListener(listener);
                return;
            }
        }
        //都没有 先创建
        LoadAssets loadAssets = new LoadAssets();

        loadAssets.AssetPath = assetPath;
        loadAssets.AssetType = assetType;
        loadAssets.AddListener(listener);
        //添加到等待队列
        waitingQueue.Enqueue(loadAssets);
    }
示例#3
0
    /// <summary>
    /// 异步加载
    /// </summary>
    /// <param name="assetName">资源名</param>
    /// <param name="type">资源类型</param>
    /// <param name="listener">回掉</param>
    private void LoadAsync(string assetName, Type type, IResourceListener listener)
    {
        // 如果正在加载中 添加回掉
        foreach (LoadAsset item in m_LoadingList)
        {
            if (item.AssetName == assetName)
            {
                item.AddListener(listener);
                return;
            }
        }

        // 如果在等待的队列中 添加回掉
        foreach (LoadAsset item in m_WaitingQueue)
        {
            if (item.AssetName == assetName)
            {
                item.AddListener(listener);
                return;
            }
        }

        // 都没有 则创建资源
        LoadAsset asset = new LoadAsset();

        asset.AssetName = assetName;
        asset.Type      = type;
        asset.AddListener(listener);

        // 添加到等待队列
        m_WaitingQueue.Enqueue(asset);
    }
示例#4
0
 /// <summary>
 /// 添加回调
 /// </summary>
 /// <param name="listener"></param>
 public void AddListener(IResourceListener listener)
 {
     if (Listeners == null)
     {
         Listeners = new List <IResourceListener>();
     }
     if (Listeners.Contains(listener))
     {
         return;
     }
     Listeners.Add(listener);
 }
示例#5
0
 /// <summary>
 /// 加载资源
 /// </summary>
 /// <param name="assetPath">资源路径</param>
 /// <param name="assetType">资源类型</param>
 /// <param name="listener">回调</param>
 public void Load(string assetPath, Type assetType, IResourceListener listener)
 {
     //如果已经加载则返回
     if (loadedAssets.ContainsKey(assetPath))
     {
         listener.OnLoaded(assetPath, loadedAssets[assetPath]);
     }
     else
     {
         //没有就开始异步加载
         LoadAsync(assetPath, assetType, listener);
     }
 }
 /// <summary>
 /// 加载资源
 /// </summary>
 /// <param name="assetName">资源名</param>
 /// <param name="assetType">资源类型</param>
 /// <param name="listener">回调</param>
 public void Load(string assetName, Type assetType, IResourceListener listener)
 {
     //如果已经加载 就直接返回
     if (nameAssetDict.ContainsKey(assetName))
     {
         listener.OnLoaded(assetName, nameAssetDict[assetName]);
         return;
     }
     else //没有 开始异步加载
     {
         LoadAsync(assetName, assetType, listener);
     }
 }
示例#7
0
 /// <summary>
 /// 加载资源
 /// </summary>
 /// <param name="assetName">资源名</param>
 /// <param name="type">资源类型</param>
 /// <param name="listener">回掉</param>
 /// <param name="assetType">自定义的资源类型</param>
 public void Load(string assetName, Type type, IResourceListener listener = null)
 {
     // 资源已存在 直接完成回掉
     if (m_AssetDict.ContainsKey(assetName))
     {
         if (listener != null)
         {
             listener.OnLoaded(assetName, m_AssetDict[assetName]);
         }
     }
     // 进行异步加载
     else
     {
         LoadAsync(assetName, type, listener);
     }
 }