Exemplo n.º 1
0
    /// <summary>
    /// 资源引用次数减一
    /// </summary>
    /// <param name="abPath"></param>
    /// <param name="assetName"></param>
    public void Release(string abPath, string assetName)
    {
        CMAssetBundle cmAB = null;

        if (m_dicAssetBundleDatas.TryGetValue(abPath, out cmAB) && cmAB.IsDone())
        {
            cmAB.ReleaseAsset(assetName);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// 执行assetbundle异步加载检测
    /// </summary>
    private void ProcessABLoadAsyn()
    {
        CMAssetBundle            tempCMAB             = null;
        string                   tempAbPath           = null;
        AssetBundleCreateRequest tempABCreateRequiest = null;

        if (CurAsynLoadingAbNum > 0)
        {
            var enumerator = asynLoadingAbDic.GetEnumerator();
            while (enumerator.MoveNext())
            {
                if (enumerator.Current.Value.isDone)
                {
                    tempStrLst.Add(enumerator.Current.Key);
                }
            }
        }
        if (tempStrLst.Count > 0)
        {
            for (int i = 0, max = tempStrLst.Count; i < max; i++)
            {
                tempAbPath = tempStrLst[i];
                tempCMAB   = GetCMAssetBundle(tempAbPath);
                if (asynLoadingAbDic.TryGetValue(tempAbPath, out tempABCreateRequiest))
                {
                    if (!tempCMAB.IsDone())
                    {
                        //执行完成
                        tempCMAB.Done(tempABCreateRequiest.assetBundle);
                        //给依赖资源添加引用计数
                        AddABDependenceRef(tempStrLst[i]);
                    }

                    if (asynLoadingAbDic.ContainsKey(tempAbPath))
                    {
                        asynLoadingAbDic.Remove(tempAbPath);
                    }
                }
            }
            tempStrLst.Clear();
        }

        while (CanLoadNextABAsyn())
        {
            tempAbPath = waitingABPath.Dequeue();
            tempCMAB   = GetCMAssetBundle(tempAbPath);
            if (tempCMAB.GetTaskState() != CMABTaskState.CMTaskState_None &&
                tempCMAB.GetTaskState() != CMABTaskState.CMTaskState_Waiting)
            {
                continue;
            }
            tempABCreateRequiest = AssetBundle.LoadFromFileAsync(GetFileFullPath("ui/" + tempAbPath));
            tempCMAB.OnProcessing(tempABCreateRequiest.progress);

            asynLoadingAbDic.Add(tempAbPath, tempABCreateRequiest);
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// 是否依赖资源加载完成
    /// </summary>
    /// <param name="abPath"></param>
    /// <returns></returns>
    public bool IsDependenceLoadComplete(string abPath)
    {
        string[] dependences = GetABAllDependencies(abPath);
        bool     complete    = true;

        if (null != dependences)
        {
            CMAssetBundle dpCmAB = null;
            for (int i = 0, max = dependences.Length; i < max; i++)
            {
                if (!TryGetCMAssetBundle(dependences[i], out dpCmAB) || !dpCmAB.IsDone())
                {
                    complete = false;
                    break;
                }
            }
        }
        return(complete);
    }
Exemplo n.º 4
0
    /// <summary>
    /// 获取资源(同步)
    /// </summary>
    /// <param name="abPath"></param>
    /// <param name="assetName"></param>
    /// <returns></returns>
    public UnityEngine.Object CreateAsset(string abPath, string assetName)
    {
        CMAssetBundle cmAB = null;

        if (!m_dicAssetBundleDatas.TryGetValue(abPath, out cmAB))
        {
            cmAB = CMAssetBundle.Create(abPath);
            m_dicAssetBundleDatas.Add(abPath, cmAB);
        }

        if (cmAB.GetTaskState() == CMABTaskState.CMTaskState_None)
        {
            string [] dependences = GetABAllDependencies(abPath);
            if (null != dependences)
            {
                CMAssetBundle dpCmAB = null;
                AssetBundle   dpAB   = null;
                for (int i = 0, max = dependences.Length; i < max; i++)
                {
                    if (!m_dicAssetBundleDatas.TryGetValue(dependences[i], out dpCmAB))
                    {
                        dpCmAB = CMAssetBundle.Create(dependences[i]);
                        m_dicAssetBundleDatas.Add(dependences[i], dpCmAB);
                    }
                    if (dpCmAB.IsDone())
                    {
                        continue;
                    }
                    dpAB = AssetBundle.LoadFromFile(GetFileFullPath("ui/" + dependences[i]));
                    dpCmAB.Done(dpAB);
                }
            }
            cmAB.OnWaitingStart();
            AssetBundle ab = AssetBundle.LoadFromFile(GetFileFullPath("ui/" + abPath));
            cmAB.OnProcessing(1);
            cmAB.Done(ab);
        }

        return(cmAB.CreateAsset(assetName));
    }