コード例 #1
0
    /// <summary>
    /// 加载各个平台的总记录的ab的 manifest信息 这是加载ab的前提
    /// </summary>
    /// <returns></returns>
    IEnumerator WWWLoadMainAssets()
    {
        VersionAssetData vad = mNameMD5Dic["Manifest"];

        string url = StringBuilder(GetPlantFormat(), "/", vad.md5);

        //只提供了测试加载,android不能通过File加载需要通过www方式
#if UNITY_IPHONE || UNITY_STANDALONE_WIN || UNITY_EDITOR
        if (!File.Exists(url))
        {
            Debug.LogError("Manifest file not exist:" + url);
        }
        else
        {
            var fs = File.OpenRead(url);

            int    fsLen  = (int)fs.Length;
            byte[] heByte = new byte[fsLen];
            //int r = fs.Read(heByte, 0, heByte.Length);
            fs.Read(heByte, 0, heByte.Length);
            string text = System.Text.Encoding.UTF8.GetString(heByte);
            mMainManifest = IAssetBundleManifest.DeSerializate(text);

            fs.Dispose();
        }
#endif
        yield return(null);

        LoadAssets("prefab/cube", (o, obj) =>
        {
            Debug.Log(" 加载资源成功!!!");
            GameObject.Instantiate(o);
        });
    }
コード例 #2
0
    /// <summary>
    /// 生成依赖关系的文件
    /// </summary>
    static void MakeIAssetBundleManifest()
    {
        //var path = m_Assets + "/Manifest.xml";
        //if (File.Exists(path)) {
        //    File.Delete(path);
        //}
        mIManifest = new IAssetBundleManifest();
        var dic = new Dictionary <string, string[]>();

        foreach (var abName in tempBuilds.Keys)
        {
            var build  = tempBuilds[abName];
            var dpList = new List <string>();
            foreach (var path in build.assetNames)
            {
                var depends = AssetDatabase.GetDependencies(path);

                foreach (var dpPath in depends)
                {
                    if (dpPath.Contains(".cs") ||
                        dpPath.Contains(".mdb") ||
                        dpPath.Contains(".dll"))
                    {
                        continue;
                    }
                    if (path.Equals(dpPath))
                    {
                        continue;
                    }

                    if (mPath2ABName.ContainsKey(dpPath))
                    {
                        dpList.Add(mPath2ABName[dpPath]);
                    }
                    else
                    {
                        //   Debug.LogError("错误!!! 该依赖资源没有加入打包 " + dpPath);
                    }
                }
            }
            dic[abName] = dpList.ToArray();
        }
        mIManifest.SetAsstDpNames(dic);
        mIManifest.Serializate(m_RootDirectory, "Manifest");
        // mIManifest.Serializate(Application.dataPath + "/AssetData", "Manifest");
        // SetAsset("Manifest", path);
    }
コード例 #3
0
    //反序列化
    public static IAssetBundleManifest DeSerializate(string text)
    {
        IAssetBundleManifest manifest = new IAssetBundleManifest();

        XmlDocument xml = new XmlDocument();

        xml.LoadXml(text);
        var nodes = xml.SelectNodes("root/assetbundle");

        Debug.Log("DeSerializate " + nodes.Count);
        foreach (XmlNode abNode in nodes)
        {
            var abName = abNode.Attributes.GetNamedItem("name").Value;
            var dplist = new string[abNode.ChildNodes.Count];
            var count  = 0;
            foreach (XmlNode dpNode in abNode.ChildNodes)
            {
                dplist[count] = dpNode.Attributes.GetNamedItem("name").Value;
                count++;
            }
            manifest.assetDpNames[abName] = dplist;
        }
        return(manifest);
    }