예제 #1
0
    /// <summary>
    /// 异步加载AB
    /// </summary>
    /// <param name="abPath"></param>
    public void LoadAssetBundleAsyn(string abPath)
    {
        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)
        {
            //已经在加载了
            return;
        }

        string[] dependenciesPath = GetABAllDependencies(cmAB.ABPath);

        if (null != dependenciesPath)
        {
            for (int i = 0, max = dependenciesPath.Length; i < max; i++)
            {
                if (!waitingABPath.Contains(dependenciesPath[i]))
                {
                    waitingABPath.Enqueue(dependenciesPath[i]);
                }
            }
        }

        waitingABPath.Enqueue(abPath);
        cmAB.OnWaitingStart();
        //DoNextABLoad();
        ProcessABLoadAsyn();
    }
예제 #2
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));
    }