Ejemplo n.º 1
0
        /// <summary>
        /// AssetBundle加载
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public AsyncAsset AssetBundleLoad(string path)
        {
            // 依赖加载
            string assetBundleName = "data/" + GetAssetBundleName(path);
            var    data            = m_getDependentAsset(assetBundleName);

            AssetsBundle[] dependent = new AssetsBundle[data.Count];
            for (int i = 0; i < data.Count; ++i)
            {
                dependent[i] = (AssetsBundle)AssetBundleLoad(path.Replace(assetBundleName, data[i]));
            }

            AsyncAsset async = null;

            if (m_complete.ContainsKey(path))
            {
                async = m_complete[path];
            }
            else
            {
                if (m_loading.ContainsKey(path))
                {
                    async = m_loading[path];
                }
                else
                {
                    async = new AssetsBundle(path);
                    async.AsyncLoad();
                }
                while (!async.isDone)
                {
                }
                async.Complete();
                m_complete.Add(async.url, async);

                // 计算依赖关系
                if (dependent != null)
                {
                    for (int i = 0; i < dependent.Length; ++i)
                    {
                        dependent[i].AddDependentSelf((AssetsBundle)async);
                        ((AssetsBundle)async).AddSelfDependent(dependent[i]);
                    }
                }
            }

            return(async);
        }