Ejemplo n.º 1
0
        // ------------------------------------------------------------------------------------------
        // 从AssetBundle里加载资源
        private void LoadBundleAsset(LoaderGroup group, AssetBundleInfo info, string name, Type type,
                                     GroupLoadedCallback onLoaded,
                                     bool async = true, LoadPriority priority = LoadPriority.Normal)
        {
            if (info == null || string.IsNullOrEmpty(name))
            {
                if (onLoaded != null)
                {
                    onLoaded(group, null);
                }

                return;
            }

            if (!async)
            {
                // 同步,直接加载
                //Logger.Log(string.Format("-->LoadBundleAsset: {0}", name));

                Object asset = info.LoadAsset(name, type);
                if (onLoaded != null)
                {
                    onLoaded(group, asset);
                }
            }
            else
            {
                // 异步,创建一个加载器后加载
                BundleAssetLoadParam param = new BundleAssetLoadParam {
                    Bundle = info.Bundle,
                    Type   = type
                };

                m_task.AddLoadTask(group, Loader.LoaderType.BundleAsset, name, param, (group1, data1) => {
                    // 加载回调
                    if (onLoaded != null)
                    {
                        onLoaded(group1, data1);
                    }
                }, true, priority, true);
            }
        }
Ejemplo n.º 2
0
        /*private void InitVersionData(bool start = true)
         * {
         *  Clear();
         *
         *  m_origns.Clear();
         *  for (int i = 0; i < VersionData.Inst.Items.Length; ++i)
         *  {
         *      VersionData.VersionItem item = VersionData.Inst.Items[i];
         *      m_origns.Add(item.Name, item.Md5);
         *  }
         *
         *  if (start)
         *  {
         *      LoadManifest();
         *  }
         * }*/

        /*public void SetPatchData(JSONClass list, bool clear = false)
         * {
         *  if (clear)
         *  {
         *      Clear();
         *  }
         *
         *  m_patchs.Clear();
         *  if (list != null)
         *  {
         *      foreach (KeyValuePair<string, JSONNode> item in list)
         *      {
         *          m_patchs.Add(item.Key, item.Value["md5"]);
         *      }
         *  }
         *
         *  LoadManifest();
         * }*/

        /*private void LoadVersion()
         * {
         *  Logger.Log("LoadVersion");
         *  if (ConstantData.EnableMd5Name)
         *  {
         *      string pathPatch = string.Format("{0}/version_patch", Application.persistentDataPath);
         *      bool hasPatch = false;
         *
         *      if (ConstantData.EnablePatch)
         *      {
         *          hasPatch = File.Exists(pathPatch);
         *      }
         *
         *      InitVersionData(!hasPatch);
         *
         *      if (hasPatch)
         *      {
         *          LoadStream(pathPatch, (data) =>
         *          {
         *              byte[] bytes = data as byte[];
         *              if (bytes == null)
         *              {
         *                  Logger.LogError("Load patch version Failed!");
         *                  return;
         *              }
         *
         *              string text = Encoding.UTF8.GetString(bytes);
         *              JSONClass json = JSONNode.Parse(text) as JSONClass;
         *              if (json == null)
         *              {
         *                  Logger.LogError("Load patch version Failed!");
         *                  return;
         *              }
         *
         *              JSONClass jsonList = null;
         *              if (string.Equals(json["version"], LogicConstantData.Version))
         *              {
         *                  jsonList = json["list"] as JSONClass;
         *              }
         *
         *              m_urlPatch = json["url"];
         *              SetPatchData(jsonList);
         *          }, false, false, true);
         *      }
         *  }
         *  else
         *  {
         *      LoadManifest();
         *  }
         * }*/

        // 加载资源清单
        private void LoadManifest()
        {
            Logger.Log("LoadManifest");

            if (m_manifest != null)
            {
                Object.DestroyImmediate(m_manifest, true);
                m_manifest = null;
            }

            if (m_mapping != null)
            {
                Object.DestroyImmediate(m_mapping, true);
                m_mapping = null;
            }

            // 加载AssetBundle依赖文件
            LoadAssetBundle(null, ConstantData.AssetbundleManifest, (group, data) => {
                AssetBundleInfo ab = data as AssetBundleInfo;
                if (ab != null)
                {
                    m_manifest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest");
                }
            }, false, false, false);

            // 加载资源到AssetBundle映射表
            string name = ConstantData.AssetbundleMapping;

            LoadAssetFromBundle(null, name, name, typeof(AssetBundleMapping), (group, data) => {
                m_mapping = data as AssetBundleMapping;
                if (m_mapping != null)
                {
                    m_mapping.Init();
                }
            }, false);

            Logger.Log("LoadManifest End");
        }