Exemplo n.º 1
0
    private static void CreateAssetBundleDat(AssetBundleManifest manifest, BuildAssetBundleOptions _buildOptions, BuildTarget _buildTarget)
    {
        if (manifest == null)
        {
            return;
        }

        string[] abs = manifest.GetAllAssetBundles();

        AssetBundle[] aaaa = new AssetBundle[abs.Length];

        try
        {
            List <string> assetNames = new List <string>();

            List <string> assetBundleNames = new List <string>();

            Dictionary <string, List <string> > result = new Dictionary <string, List <string> >();

            for (int i = 0; i < abs.Length; i++)
            {
                //AssetBundle ab = LoadAssetBundle("file:///" + Application.streamingAssetsPath + "/" + AssetBundleManager.path + abs[i]);

                AssetBundle ab = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/" + AssetBundleManager.path + abs[i]);

                aaaa[i] = ab;

                string[] strs = ab.GetAllAssetNames();

                for (int m = 0; m < strs.Length; m++)
                {
                    string str = strs[m];

                    if (assetNames.Contains(str))
                    {
                        SuperDebug.LogError("error!");
                    }
                    else
                    {
                        assetNames.Add(str);

                        assetBundleNames.Add(abs[i]);

                        List <string> ll = new List <string>();

                        result.Add(str, ll);
                    }
                }
            }

            for (int i = 0; i < assetNames.Count; i++)
            {
                string        assetName = assetNames[i];
                string        abName    = assetBundleNames[i];
                List <string> list      = result[assetName];

                string[] strs = AssetDatabase.GetDependencies(assetName);

                for (int m = 0; m < strs.Length; m++)
                {
                    string tmpAssetName = strs[m].ToLower();

                    if (tmpAssetName != assetName)
                    {
                        int index = assetNames.IndexOf(tmpAssetName);

                        if (index != -1)
                        {
                            string assetBundleName = assetBundleNames[index];

                            if (assetBundleName != abName && !list.Contains(assetBundleName))
                            {
                                list.Add(assetBundleName);
                            }
                        }
                    }
                }
            }

            FileInfo fi = new FileInfo(Application.streamingAssetsPath + "/" + AssetManager.dataName);

            if (fi.Exists)
            {
                fi.Delete();
            }

            FileStream fs = fi.Create();

            BinaryWriter bw = new BinaryWriter(fs);

            AssetManagerDataFactory.SetData(bw, assetNames, assetBundleNames, result);

            fs.Flush();

            bw.Close();

            fs.Close();

            fs.Dispose();
        }
        catch (Exception e)
        {
            Debug.Log("error:" + e.Message);
        }
        finally
        {
            foreach (AssetBundle aaa in aaaa)
            {
                aaa.Unload(true);
            }
        }
    }
Exemplo n.º 2
0
    private static void CreateAssetBundleDat(AssetBundleManifest manifest, BuildAssetBundleOptions _buildOptions, BuildTarget _buildTarget)
    {
        if (manifest == null)
        {
            return;
        }

        string[] abs = manifest.GetAllAssetBundles();

        AssetBundle[] aaaa = new AssetBundle[abs.Length];

        try{
            List <UnityEngine.Object> assets = new List <UnityEngine.Object> ();

            List <string> assetNames = new List <string> ();

            List <string> assetBundleNames = new List <string> ();

            Dictionary <string, List <string> > result = new Dictionary <string, List <string> > ();

            for (int i = 0; i < abs.Length; i++)
            {
                AssetBundle ab = LoadAssetBundle("file:///" + Application.streamingAssetsPath + "/" + AssetBundleManager.path + abs[i]);

//				AssetBundle ab = AssetBundle.CreateFromFile(Application.streamingAssetsPath + "/" + AssetBundleManager.path + abs[i]);

                aaaa[i] = ab;

                string[] nn = ab.GetAllAssetNames();

                foreach (string str in nn)
                {
                    if (assetNames.Contains(str))
                    {
                        SuperDebug.LogError("error!");
                    }
                    else
                    {
                        assetNames.Add(str);

                        UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(str);

                        assets.Add(obj);

                        assetBundleNames.Add(abs[i]);

                        List <string> ll = new List <string>();

                        result.Add(str, ll);
                    }
                }
            }

            for (int i = 0; i < assetNames.Count; i++)
            {
                string             name = assetNames[i];
                UnityEngine.Object obj  = assets[i];
                List <string>      list = result[name];

                UnityEngine.Object[] sss = EditorUtility.CollectDependencies(new UnityEngine.Object[] { obj });

                foreach (UnityEngine.Object dd in sss)
                {
                    if (dd != obj)
                    {
                        if (assets.Contains(dd))
                        {
                            string assetBundleName = assetBundleNames[assets.IndexOf(dd)];

                            if (!list.Contains(assetBundleName))
                            {
                                list.Add(assetBundleName);
                            }
                        }
                    }
                }
            }

            FileInfo fi = new FileInfo(Application.streamingAssetsPath + "/" + AssetManager.dataName);

            if (fi.Exists)
            {
                fi.Delete();
            }

            FileStream fs = fi.Create();

            BinaryWriter bw = new BinaryWriter(fs);

            AssetManagerDataFactory.SetData(bw, assetNames, assetBundleNames, result);

            fs.Flush();

            bw.Close();

            fs.Close();

            fs.Dispose();
        }catch (Exception e) {
            Debug.Log("error:" + e.Message);
        }finally{
            foreach (AssetBundle aaa in aaaa)
            {
                aaa.Unload(true);
            }
        }
    }