Example #1
0
        public static void ProcessAssetBundleRes(AssetDataTable table)
        {
            var abNameArr = AssetDatabase.GetAllAssetBundleNames();

            if (abNameArr != null && abNameArr.Length > 0)
            {
                foreach (var abName in abNameArr)
                {
                    var dependArr = AssetDatabase.GetAssetBundleDependencies(abName, false);
                    AssetDataPackage group;
                    var abIndex = table.AddAssetBundleMsg(abName, dependArr, out group);
                    if (abIndex < 0)
                    {
                        continue;
                    }
                    var assets = AssetDatabase.GetAssetPathsFromAssetBundle(abName);
                    foreach (var cell in assets)
                    {
                        //var type = AssetDatabase.GetMainAssetTypeAtPath(cell);
                        //var code = type.ToCode();

                        group.AddAssetData(cell.EndsWith(".unity")
                            ? new AssetData(AssetPath2Name(cell), ResLoadType.ABScene, abIndex, abName)
                            : new AssetData(AssetPath2Name(cell), ResLoadType.ABAsset, abIndex, abName));
                    }
                }
            }
        }
Example #2
0
        private static void ProcessTableConfig(AssetDataTable table, string folder)
        {
            AssetDataPackage group = null;

            DirectoryInfo direInfo = new DirectoryInfo(folder);

            FileInfo[] fileInfos = direInfo.GetFiles();

            if (fileInfos == null || fileInfos.Length == 0)
            {
                return;
            }

            for (int i = 0; i < fileInfos.Length; ++i)
            {
                FileInfo info = fileInfos[i];

                if (AssetFileFilter.IsConfigTable(info.FullName))
                {
                    string md5       = GetMD5HashFromFile(info.FullName);
                    long   buildTime = DateTime.Now.Ticks;//info.LastWriteTime.Ticks;
                    table.AddAssetBundleName(ProjectPathConfig.tableFolder + info.Name, null, md5, (int)info.Length, buildTime, out group);
                }
            }

            table.Dump();
        }
Example #3
0
        // [MenuItem("Assets/GFrame/Asset/构建AB_IOS")]
        // public static void BuildAllAssetBundlesIOS()
        // {
        //     AssetBundleBuilder.BuildAB(outPath + "/IOS", BuildTarget.iOS);
        // }

        // [MenuItem("Assets/GFrame/Asset/构建AB_Android")]
        // public static void BuildAllAssetBundlesAndroid()
        // {
        //     AssetBundleBuilder.BuildAB(outPath + "/Android", BuildTarget.Android);
        // }

        #region 构建 AssetDataTable
        //[MenuItem("Assets/GFrame/Asset/生成Asset清单")]
        private static void BuildDataTable()
        {
            Log.i("#Start BuildDataTable");
            AssetDataTable table = new AssetDataTable();

            ProcessAssetBundleRes(table, null);
            table.Save();
        }
Example #4
0
        public static void RemoveInvalidAssetBundle()
        {
            AssetDataTable table = new AssetDataTable();

            ProcessAssetBundleRes(table, null);
            Log.i("#Start Remove Invalid AssetBundle");
            RemoveInvalidAssetBundleInner(FilePath.streamingAssetsPath4AB, table);
            Log.i("#Success Remove Invalid AssetBundle.");
        }
Example #5
0
        public static void BuildDataTable()
        {
            Log.i("Start BuildAssetDataTable!");
            AssetDataTable table = new AssetDataTable();

            ProcessAssetBundleRes(table, null);

            table.Save(ProjectPathConfig.absExportRootFolder);
        }
Example #6
0
        public static void BuildDataTable()
        {
            AssetDataTable table = new AssetDataTable();

            ProcessAssetBundleRes(table);

            table.Save(ProjectPathConfig.absExportRootFolder);
            AssetDatabase.Refresh();
        }
Example #7
0
        public static void BuildTableConfigTable()
        {
            Log.i("Start BuildTableConfigTable!");
            AssetDataTable table  = new AssetDataTable();
            string         folder = Application.dataPath + "/" + ProjectPathConfig.DEFAULT_TABLE_EXPORT_PATH;

            ProcessTableConfig(table, folder);

            table.Save(FilePath.streamingAssetsPath);
        }
Example #8
0
        private static void ProcessAssetBundleRes(AssetDataTable table, string[] abNames)
        {
            AssetDataPackage group = null;

            int abIndex = -1;

            AssetDatabase.RemoveUnusedAssetBundleNames();

            if (abNames == null)
            {
                abNames = AssetDatabase.GetAllAssetBundleNames();
            }

            if (abNames != null && abNames.Length > 0)
            {
                for (int i = 0; i < abNames.Length; ++i)
                {
                    string abPath = Application.dataPath + "/" + ProjectPathConfig.exportRootFolder + abNames[i];

                    string[] depends = AssetDatabase.GetAssetBundleDependencies(abNames[i], false);

                    FileInfo info = new FileInfo(abPath);
                    if (!info.Exists)
                    {
                        continue;
                    }
                    string md5       = GetMD5HashFromFile(abPath);
                    long   buildTime = DateTime.Now.Ticks; //info.LastWriteTime.Ticks;

                    abIndex = table.AddAssetBundleName(abNames[i], depends, md5, (int)info.Length, buildTime, out group);
                    if (abIndex < 0)
                    {
                        continue;
                    }
                    //Log.i("MD5:" + GetMD5HashFromFile(abPath));

                    string[] assets = AssetDatabase.GetAssetPathsFromAssetBundle(abNames[i]);
                    foreach (var cell in assets)
                    {
                        if (cell.EndsWith(".unity"))
                        {
                            group.AddAssetData(new AssetData(AssetPath2Name(cell), eResType.kABScene, abIndex));
                        }
                        else
                        {
                            group.AddAssetData(new AssetData(AssetPath2Name(cell), eResType.kABAsset, abIndex));
                        }
                    }
                }
            }

            table.Dump();
        }
Example #9
0
        public static void RemoveInvalidAssetBundle()
        {
            AssetDataTable table = new AssetDataTable();

            ProcessAssetBundleRes(table, null);

            Log.i("#Start Remove Invalid AssetBundle");

            RemoveInvalidAssetBundleInner(ProjectPathConfig.absExportRootFolder, table);

            Log.i("#Success Remove Invalid AssetBundle.");
        }
Example #10
0
        public static void BuildDataTable()
        {
            Log.i("Start BuildAssetDataTable!");
            AssetDataTable table = AssetDataTable.Create();

            ProcessAssetBundleRes(table);

            string filePath =
                IOUtils.CreateDirIfNotExists(FilePath.streamingAssetsPath + FrameworkConfigData.RELATIVE_AB_ROOT_FOLDER) +
                FrameworkConfigData.EXPORT_ASSETBUNDLE_CONFIG_FILENAME;

            table.Save(filePath);
            AssetDatabase.Refresh();
        }
Example #11
0
        private static void ProcessAssetBundleRes(AssetDataTable table, string[] abNames)
        {
            AssetDataPackage package = null;

            //int abIndex = -1;
            AssetDatabase.RemoveUnusedAssetBundleNames();
            if (abNames == null)
            {
                abNames = AssetDatabase.GetAllAssetBundleNames();
            }

            if (abNames != null && abNames.Length > 0)
            {
                for (int i = 0; i < abNames.Length; ++i)
                {
                    //输出路径
                    string abPath = Path.Combine(FilePath.streamingAssetsPath4AB, abNames[i]);

                    string[] depends = AssetDatabase.GetAssetBundleDependencies(abNames[i], false);
                    FileInfo info    = new FileInfo(abPath);
                    if (!info.Exists)
                    {
                        continue;
                    }
                    string md5        = GetMD5HashFromFile(abPath);
                    long   buildTime  = System.DateTime.Now.Ticks;
                    bool   successAdd = table.AddAssetBundle(abNames[i], depends, md5, (int)info.Length, buildTime, out package);
                    if (!successAdd)
                    {
                        continue;
                    }

                    string[] assets = AssetDatabase.GetAssetPathsFromAssetBundle(abNames[i]);
                    foreach (var cell in assets)
                    {
                        // if (cell.EndsWith(".unity"))
                        // {
                        //     package.AddAssetData(new AssetData(AssetPath2Name(cell), eResType.kABScene));//, -1));
                        // }
                        // else
                        {
                            package.AddAssetData(new AssetData(PathHelper.Path2Name(cell), eResType.kABAsset));//, -1));
                        }
                    }
                }
            }
        }
Example #12
0
        private static void RemoveInvalidAssetBundleInner(string absPath, AssetDataTable table)
        {
            string[] dirs = Directory.GetDirectories(absPath);

            if (dirs != null && dirs.Length > 0)
            {
                for (int i = 0; i < dirs.Length; ++i)
                {
                    RemoveInvalidAssetBundleInner(dirs[i], table);
                }
            }

            string[] files = Directory.GetFiles(absPath);
            if (files != null && files.Length > 0)
            {
                for (int i = 0; i < files.Length; ++i)
                {
                    string p = AssetBundlePath2ABName(files[i]);
                    if (!AssetFileFilter.IsAssetBundle(p))
                    {
                        continue;
                    }

                    if (table.GetABUnit(p) == null)
                    {
                        File.Delete(files[i]);
                        File.Delete(files[i] + ".meta");
                        File.Delete(files[i] + ".manifest");
                        File.Delete(files[i] + ".manifest.meta");

                        Log.e("Delete Invalid AB:" + p);
                    }
                }

                files = Directory.GetFiles(absPath);
                if (files == null || files.Length == 0)
                {
                    Directory.Delete(absPath);
                }
            }
            else
            {
                Directory.Delete(absPath);
            }
        }
Example #13
0
        private static void ProcessAssetBundleRes(AssetDataTable table)
        {
            AssetDataGroup group = null;

            int abIndex = table.AddAssetBundleName(FrameworkConfigData.ABMANIFEST_AB_NAME, null, out group);

            if (abIndex > 0)
            {
                group.AddAssetData(new AssetData(FrameworkConfigData.ABMANIFEST_ASSET_NAME, eResType.kABAsset, abIndex, null));
            }

            AssetDatabase.RemoveUnusedAssetBundleNames();

            string[] abNames = AssetDatabase.GetAllAssetBundleNames();
            if (abNames != null && abNames.Length > 0)
            {
                for (int i = 0; i < abNames.Length; ++i)
                {
                    string[] depends = AssetDatabase.GetAssetBundleDependencies(abNames[i], false);
                    abIndex = table.AddAssetBundleName(abNames[i], depends, out group);
                    if (abIndex < 0)
                    {
                        continue;
                    }

                    string[] assets = AssetDatabase.GetAssetPathsFromAssetBundle(abNames[i]);
                    foreach (var cell in assets)
                    {
                        if (cell.EndsWith(".unity"))
                        {
                            group.AddAssetData(new AssetData(AssetPath2Name(cell), eResType.kABScene, abIndex, abNames[i]));
                        }
                        else
                        {
                            group.AddAssetData(new AssetData(AssetPath2Name(cell), eResType.kABAsset, abIndex, abNames[i]));
                        }
                    }
                }
            }

            table.Dump();
        }