コード例 #1
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();
        }
コード例 #2
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));
                        }
                    }
                }
            }
        }