Esempio n. 1
0
    static bool RemoveUnusedAssetBundles(BundleInfoAsset rsd)
    {
        HashSet <string> unusedbundles = new HashSet <string>();
        var a = BundleInfoManager.GetAsset();

        if (a)
        {
            foreach (var v in a.BundleInfos)
            {
                unusedbundles.Add(v.name);
            }
        }
        foreach (var v in rsd.BundleInfos)
        {
            unusedbundles.Remove(v.name);
        }
        int i = 0;

        foreach (var name in unusedbundles)
        {
            i++;
            if (EditorUtility.DisplayCancelableProgressBar(string.Format("remove unused {0}/{1}", i, unusedbundles.Count), name, (float)i / (float)unusedbundles.Count))
            {
                return(false);
            }
            AssetDatabase.RemoveAssetBundleName(name, true);
        }

        return(true);
    }
Esempio n. 2
0
    public static void InitEditor()
    {
        EmptyBundleNames = new List <string>();
        for (int i = 0; i < 10; ++i)
        {
            for (int k = 0; k < 10; ++k)
            {
                for (int j = 0; j < 10; ++j)
                {
                    for (int a = 0; a < 10; ++a)
                    {
                        string str = "";
                        str += i.ToString();
                        str += k.ToString();
                        str += j.ToString();
                        str += a.ToString();
                        EmptyBundleNames.Add(str);
                    }
                }
            }
        }
        try
        {
            mBundleAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <BundleInfoAsset>(AssetManager.RootPath + "/" + AssetBundleName + "/" + AssetName);
        }
        catch (System.Exception)
        {
            Debug.Log("BundleInfoManager can not found asset");
        }

        if (mBundleAsset == null)
        {
            mBundles     = null;
            mBundleAsset = null;
            return;
        }

        BundleInfo d = null;

        mBundles = new Dictionary <string, BundleInfo>();

        for (int i = 0; i < mBundleAsset.BundleInfos.Count; ++i)
        {
            d = mBundleAsset.BundleInfos[i];
            EmptyBundleNames.Remove(Path.GetFileName(d.name));

            for (int k = 0; k < d.files.Count; ++k)
            {
                if (mBundles.ContainsKey(d.files[k]))
                {
                    Debug.Log(d.files[k] + "   " + d.name + "  " + mBundles[d.files[k]].name);
                }
                mBundles.Add(d.files[k], d);
            }
        }
    }
Esempio n. 3
0
    public static void NamedAssetBundleName()
    {
        int             count = 0;
        long            csize = 0;
        BundleInfoAsset rsd   = ScriptableObject.CreateInstance <BundleInfoAsset>();

        rsd.BundleInfos = new List <BundleInfo>();
        {
            BundleInfo bi = new BundleInfo(BundleInfoManager.AssetBundleName);
            bi.files.Add("Assets/" + RootDir + "/" + BundleInfoManager.AssetBundleName + "/" + BundleInfoManager.AssetName);
            rsd.BundleInfos.Add(bi);
        }

        BundleInfoManager.InitEditor();
        AssetDatabase.StartAssetEditing();
        bool completed = false;

        do
        {
            if (null == DependedCount(Application.dataPath + "/" + RootDir, ref rsd.BundleInfos, ref count, ref csize))
            {
                break;
            }

            Debug.LogFormat("bundle count {0}, file count {1}, files size {2} MB", rsd.BundleInfos.Count, count, csize / 1024 / 1024);


            completed = true;
        } while (false);



        if (completed)
        {
            RemoveAssetFromBundle(rsd);
            RemoveUnusedAssetBundles(rsd);

            CreateBundleInfoAsset(rsd);
            RemoveUnusedBundles(rsd);

            AssetDatabase.RemoveUnusedAssetBundleNames();
        }

        Debug.Log(completed ? "completed" : "use canceled");

        AssetDatabase.StopAssetEditing();
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
        EditorUtility.ClearProgressBar();
    }
Esempio n. 4
0
    static void CreateBundleInfoAsset(BundleInfoAsset rsd)
    {
        string assetpath = "Assets/" + RootDir + "/" + BundleInfoManager.AssetBundleName + "/" + BundleInfoManager.AssetName;

        SortFileList(rsd);

        UnityEngine.Object o = AssetDatabase.LoadAssetAtPath <BundleInfoAsset>(assetpath);
        if (o == null)
        {
            Directory.CreateDirectory(Application.dataPath + "/" + RootDir + "/" + BundleInfoManager.AssetBundleName);
            AssetDatabase.CreateAsset(rsd, assetpath);
            // AssetDatabase.SaveAssets();
            var importer = AssetImporter.GetAtPath(assetpath);
            importer.assetBundleName = BundleInfoManager.AssetBundleName;
        }
        else
        {
            EditorUtility.CopySerialized(rsd, o);
        }
    }
Esempio n. 5
0
    static void RemoveAssetFromBundle(BundleInfoAsset rsd)
    {
        BundleInfoAsset o = BundleInfoManager.GetAsset();

        if (o == null)
        {
            return;
        }

        HashSet <string> oas = new HashSet <string>();

        foreach (var b in o.BundleInfos)
        {
            foreach (var a in b.files)
            {
                oas.Add(a);
            }
        }

        int c  = 0;
        int cc = oas.Count;

        foreach (var b in rsd.BundleInfos)
        {
            foreach (var a in b.files)
            {
                oas.Remove(a);
                c++;
            }
        }

        Debug.Log("remove asset count : " + oas.Count + ", n count : " + c + ", o count : " + cc);
        int i = 0;

        foreach (var a in oas)
        {
            ++i;
            EditorUtility.DisplayProgressBar(string.Format("remove unused asset {0}/{1}", i, oas.Count), a, (float)i / (float)oas.Count);
            SetAssetBundleName(a, "");
        }
    }
Esempio n. 6
0
    public static void Init()
    {
#if UNITY_EDITOR
        if (AssetManager.SimulateMode)
        {
            return;
        }
#endif
        try
        {
            mBundleAsset = AssetManager.LoadAssetWithBundle <BundleInfoAsset>(AssetBundleName, AssetManager.RootPath + "/" + AssetBundleName + "/" + AssetName);
        }
        catch (System.Exception)
        {
            Debug.Log("BundleInfoManager can not found asset");
        }

        if (mBundleAsset == null)
        {
            mBundles     = null;
            mBundleAsset = null;
            return;
        }

        BundleInfo d = null;
        mBundles = new Dictionary <string, BundleInfo>();

        for (int i = 0; i < mBundleAsset.BundleInfos.Count; ++i)
        {
            d = mBundleAsset.BundleInfos[i];

            for (int k = 0; k < d.files.Count; ++k)
            {
                if (mBundles.ContainsKey(d.files[k]))
                {
                    Debug.Log(d.files[k] + "   " + d.name + "  " + mBundles[d.files[k]].name);
                }
                mBundles.Add(d.files[k], d);
            }
        }
    }
Esempio n. 7
0
    static void SortFileList(BundleInfoAsset infos)
    {
        try
        {
            infos.BundleInfos.Sort((x, y) =>
            {
                return(x.name.CompareTo(y.name));
            });

            foreach (var b in infos.BundleInfos)
            {
                b.files.Sort((x, y) =>
                {
                    return(x.CompareTo(y));
                });
            }
        }
        catch (System.Exception ex)
        {
            Debug.Log(ex);
        }
    }
Esempio n. 8
0
    static void RemoveUnusedBundles(BundleInfoAsset rsd)
    {
        string[] bs = AssetDatabase.GetAllAssetBundleNames();
        int      i  = 0;

        foreach (var name in bs)
        {
            i++;
            if (null == rsd.BundleInfos.Find((info) =>
            {
                return(info.name == name);
            }))
            {
                if (EditorUtility.DisplayCancelableProgressBar(string.Format("remove unused {0}", name), name, 1))
                {
                    EditorUtility.ClearProgressBar();
                    return;
                }
                AssetDatabase.RemoveAssetBundleName(name, true);
            }
        }
        EditorUtility.ClearProgressBar();
    }