示例#1
0
        public static void BuildAssetBundles()
        {
            var assetManifest = GetManifest();

            BuildScript.RemoveUnusedAssetBundleNames();

            var assets           = assetManifest.assets;
            var assetBundleNames = assetManifest.bundles;
            var dirs             = assetManifest.dirs;

            var map = new Dictionary <string, List <string> >();

            foreach (var item in assetManifest.bundles)
            {
                map[item] = new List <string>();
            }

            foreach (var item in assets)
            {
                var assetPath = dirs[item.dir] + "/" + item.name;
                map[assetBundleNames[item.bundle]].Add(assetPath);
            }

            List <AssetBundleBuild> builds = new List <AssetBundleBuild>();

            foreach (var item in map)
            {
                builds.Add(new AssetBundleBuild()
                {
                    assetBundleName = item.Key,
                    assetNames      = item.Value.ToArray()
                });
            }

            // Choose the output path according to the build target.
            var outputPath = CreateAssetBundleDirectory();

            const BuildAssetBundleOptions options = BuildAssetBundleOptions.ChunkBasedCompression;

            var manifest =
                BuildPipeline.BuildAssetBundles(outputPath, builds.ToArray(), options,
                                                EditorUserBuildSettings.activeBuildTarget);
            var versionsTxt = outputPath + "/versions.txt";
            var versions    = new Dictionary <string, string>();

            LoadVersions(versionsTxt, versions);

            var buildVersions = GetVersions(manifest);

            var updates = new List <string>();

            foreach (var item in buildVersions)
            {
                string hash;
                var    isNew = true;
                if (versions.TryGetValue(item.Key, out hash))
                {
                    if (hash.Equals(item.Value))
                    {
                        isNew = false;
                    }
                }
                if (isNew)
                {
                    updates.Add(item.Key);
                }
            }

            if (updates.Count > 0)
            {
                using (var s = new StreamWriter(File.Open(outputPath + "/updates.txt", FileMode.Append)))
                {
                    s.WriteLine(DateTime.Now.ToFileTime() + ":");
                    foreach (var item in updates)
                    {
                        s.WriteLine(item);
                    }
                    s.Flush();
                    s.Close();
                }

                SaveVersions(versionsTxt, buildVersions);
            }
            else
            {
                Debug.Log("nothing to update.");
            }

            string[] ignoredFiles = { GetPlatformName(), "versions.txt", "updates.txt", "manifest" };

            var files = Directory.GetFiles(outputPath, "*", SearchOption.AllDirectories);

            var deletes = (from t in files
                           let file = t.Replace('\\', '/').Replace(outputPath.Replace('\\', '/') + '/', "")
                                      where !file.EndsWith(".manifest", StringComparison.Ordinal) && !Array.Exists(ignoredFiles, s => s.Equals(file))
                                      where !buildVersions.ContainsKey(file)
                                      select t).ToList();

            foreach (var delete in deletes)
            {
                if (!File.Exists(delete))
                {
                    continue;
                }
                File.Delete(delete);
                File.Delete(delete + ".manifest");
            }

            deletes.Clear();
        }
示例#2
0
 private static void CopyAssetBundles()
 {
     BuildScript.CopyAssetBundlesTo(Path.Combine(Application.streamingAssetsPath, Utility.AssetBundles));
     AssetDatabase.Refresh();
 }
示例#3
0
 private static void BuildStandalonePlayer()
 {
     BuildScript.BuildStandalonePlayer();
 }
示例#4
0
 private static void BuildAssetBundles()
 {
     BuildScript.BuildManifest();
     BuildScript.BuildAssetBundles();
 }
示例#5
0
 private static void BuildManifest()
 {
     BuildScript.BuildManifest();
 }
示例#6
0
 private static void ClearAllABName()
 {
     BuildScript.ClearAllAssetBundleName();
 }