Exemplo n.º 1
0
        private static void BuildVersions(AssetBundleManifest manifest, BuildRules rules)
        {
            var allBundles = manifest.GetAllAssetBundles();
            var bundle2Ids = GetBundle2Ids(allBundles);
            var bundles    = GetBundles(manifest, allBundles, bundle2Ids);
            var ver        = rules.AddVersion();

            var dirs          = new List <string>();
            var assets        = new List <AssetRef>();
            var patches       = new List <Patch>();
            var asset2Bundles = new Dictionary <string, BundleRef>();

            foreach (var item in rules.assets)
            {
                var path = item.name;
                var dir  = Path.GetDirectoryName(path);
                if (!string.IsNullOrEmpty(dir))
                {
                    dir = dir.Replace("\\", "/");
                }
                var index = dirs.FindIndex(o => o.Equals(dir));
                if (index == -1)
                {
                    index = dirs.Count;
                    dirs.Add(dir);
                }
                var asset = new AssetRef();
                if (item.groupBy == GroupBy.None)
                {
                    var id = AddBundle(path, asset, ref bundles);
                    asset.bundle = id;
                }
                else
                {
                    bundle2Ids.TryGetValue(item.bundle, out asset.bundle);
                }
                asset2Bundles[path] = bundles[asset.bundle];
                asset.dir           = index;
                asset.name          = Path.GetFileName(path);
                assets.Add(asset);
            }

            Func <List <string>, List <int> > getFiles = delegate(List <string> list)
            {
                var ret = new List <int>();
                foreach (var file in list)
                {
                    BundleRef bundle;
                    asset2Bundles.TryGetValue(file, out bundle);
                    if (bundle != null)
                    {
                        if (!ret.Contains(bundle.id))
                        {
                            ret.Add(bundle.id);
                        }
                        foreach (var child in bundle.children)
                        {
                            if (!ret.Contains(child))
                            {
                                ret.Add(child);
                            }
                        }
                    }
                    else
                    {
                        Debug.LogWarning("bundle == nil, file:" + file);
                    }
                }
                return(ret);
            };

            for (var i = 0; i < rules.patches.Count; i++)
            {
                var item = rules.patches[i];
                patches.Add(new Patch
                {
                    name  = item.name,
                    files = getFiles(item.assets),
                });
            }

            var versions = new Versions();

            versions.activeVariants = manifest.GetAllAssetBundlesWithVariant();
            versions.dirs           = dirs.ToArray();
            versions.assets         = assets;
            versions.bundles        = bundles;
            versions.patches        = patches;
            versions.ver            = ver;

            if (rules.allAssetsToBuild)
            {
                bundles.ForEach(obj => obj.location = 1);
            }
            else
            {
                foreach (var patchName in rules.patchesInBuild)
                {
                    var patch = versions.patches.Find((Patch item) => { return(item.name.Equals(patchName)); });
                    if (patch != null)
                    {
                        foreach (var file in patch.files)
                        {
                            if (file >= 0 && file < bundles.Count)
                            {
                                bundles[file].location = 1;
                            }
                        }
                    }
                }
            }

            versions.Save(outputPath + "/" + Assets.Versions);
        }
Exemplo n.º 2
0
        private void Complete()
        {
            updateScreen.progressBar.gameObject.SetActive(false);

            Versions.Save();

            if (_downloads.Count > 0)
            {
                for (int i = 0; i < _downloads.Count; i++)
                {
                    var item = _downloads[i];
                    if (!item.isDone)
                    {
                        break;
                    }
                    else
                    {
                        if (_serverVersions.ContainsKey(item.path))
                        {
                            _versions[item.path] = _serverVersions[item.path];
                        }
                    }
                }

                StringBuilder sb = new StringBuilder();
                foreach (var item in _versions)
                {
                    sb.AppendLine(string.Format("{0}:{1}", item.Key, item.Value));
                }

                var path = Assets.GetRelativeUpdatePath(versionsTxt);
                if (File.Exists(path))
                {
                    File.Delete(path);
                }

                File.WriteAllText(path, sb.ToString());
                var request = Assets.Initialize();
                request.completed = delegate(AssetRequest req)
                {
                    if (!string.IsNullOrEmpty(req.error))
                    {
                        OnError(req.error);
                    }
                    else
                    {
                        if (completed != null)
                        {
                            completed();
                        }
                    }
                };
                state = State.Completed;

                message = string.Format("{0} files has update.", _downloads.Count);
                return;
            }

            if (completed != null)
            {
                completed();
            }

            message = "nothing to update.";
            state   = State.Completed;
        }