void LoadAssetManifest() { string path = assetPath + ASSET_MANIFEST_FILE; if (File.Exists(path)) { string json = File.ReadAllText(assetPath + ASSET_MANIFEST_FILE); mAssetManifest = JsonUtility.FromJson <AssetManifest>(json); if (mAssetManifest != null && mAssetManifest.assetHeaders != null && mAssetManifest.assetHeaders.Count > 0) { foreach (var header in mAssetManifest.assetHeaders) { header.Init(); if (mLocalAssets.ContainsKey(header.url)) { mLocalAssets[header.url] = header; } else { mLocalAssets.Add(header.url, header); } } } } else { mAssetManifest = new AssetManifest(); Debug.LogWarning("Manifest file doesn't exist!"); } }
private IEnumerator StartGame() { yield return(AssetManifest.Init()); ABsManager.m_AssetBundleManifest = AssetManifest.manifest; ResManager.Instance.m_pattern = ResManager.Pattern.AssetBundle; ResManager.LoadLevel("Launch"); }
private void SearchAnimations(AssetManifest pManifest, AssetSearchResultItem pBaseResultItem, List <AssetSearchResultItem> pFound) { if (_tagsRegex != null) { return; } const string PuppetAnimationToken = "PuppetAnimation"; if ((_assetSubTypesRegex == null) || _assetSubTypesRegex.IsMatch(PuppetAnimationToken)) { if ((pManifest.BodyModels != null) && (pManifest.BodyModels.Count > 0)) { foreach (BodyModelItem puppet in pManifest.BodyModels) { if ((puppet.Animations != null) && (puppet.Animations.Count > 0)) { SearchAnimationsCommon(PuppetAnimationToken, puppet.PuppetName, puppet.Animations, pBaseResultItem, pFound); } } } } const string PropAnimationToken = "PropAnimation"; if ((_assetSubTypesRegex == null) || _assetSubTypesRegex.IsMatch(PropAnimationToken)) { if ((pManifest.PropModels != null) && (pManifest.PropModels.Count > 0)) { foreach (PropModelItem prop in pManifest.PropModels) { if ((prop.Animations != null) && (prop.Animations.Count > 0)) { SearchAnimationsCommon(PropAnimationToken, prop.Name, prop.Animations, pBaseResultItem, pFound); } } } } }
public void LoadManifestFile(byte[] inData) { AssetManifest manifestfile = Serializer.Deserialize <AssetManifest>(inData); if (manifestfile != null) { AssetVersion = manifestfile.version; foreach (AssetManifest.BundleInfo data in manifestfile.bundles) { for (int i = 0; i < data.guids.Length; i++) { if (!_assetMapping.ContainsKey(data.guids[i])) { _assetMapping.Add(data.guids[i], data); } } BundleMapping.Add(data.name, data); } } }
static void Main(string[] args) { _MetaStateSettings.Init(); bool isCdnOnlyMode = false; List <string> allArgs = args == null ? new List <string>() : args.ToList(); PlayFab.PlayFabSettings.staticSettings.DeveloperSecretKey = PlayFabSettings.DeveloperSecretKey; PlayFab.PlayFabSettings.staticSettings.TitleId = PlayFabSettings.TitleId; BackOfficeStatusUrl = AzureSettings.StatusUrl; if (allArgs.Contains("-cdnonly")) { isCdnOnlyMode = true; Console.WriteLine("Found -cdnonly switch, will only sync files..."); } if (allArgs.ElementAtOrDefault(0) != null && allArgs.ElementAtOrDefault(0) == "-appversion") { string version = allArgs.ElementAtOrDefault(1); string path = allArgs.ElementAtOrDefault(2); if (!string.IsNullOrEmpty(version) && !string.IsNullOrEmpty(path)) { File.WriteAllText(path, version); } return; } if (allArgs.ElementAtOrDefault(0) != null && allArgs.ElementAtOrDefault(0) == "-status") { bool online = allArgs.ElementAtOrDefault(1) == "online" ? true : false; string seconds = allArgs.ElementAtOrDefault(2); string version = allArgs.ElementAtOrDefault(3); ChangeServerStatus(online, seconds, version); return; } var pathArg = allArgs.Where(y => y.StartsWith("-BaseUnityFolder:")).SingleOrDefault(); if (pathArg != null) { MetaStateSettings._BaseUnityFolder = pathArg.Replace("-BaseUnityFolder:", string.Empty); } var currentManifestResult = PlayFab.PlayFabServerAPI.GetTitleDataAsync(new PlayFab.ServerModels.GetTitleDataRequest() { Keys = new List <string>() { MetaStateSettings._TitleDataKey_CdnManifest } }).GetAwaiter().GetResult(); Console.WriteLine("Fetching CDN content..."); AssetManifest currentManifest = null; if (currentManifestResult.Result.Data.ContainsKey(MetaStateSettings._TitleDataKey_CdnManifest) && !string.IsNullOrEmpty(currentManifestResult.Result.Data[MetaStateSettings._TitleDataKey_CdnManifest])) { currentManifest = JsonConvert.DeserializeObject <AssetManifest>(currentManifestResult.Result.Data[MetaStateSettings._TitleDataKey_CdnManifest]); } else { currentManifest = new AssetManifest(); } Console.WriteLine("Loading local files on " + MetaStateSettings._BaseUnityFolder + MetaStateSettings._DownloadableFolderPath); List <AssetFileInfo> allFiles = LocalFileHandler.GetLocalDownloadableFiles(); var allCdnContent = PlayFabAdminAPI.GetContentListAsync(new PlayFab.AdminModels.GetContentListRequest()).GetAwaiter().GetResult(); int currentDataVersion; AssetFileInfo previousDbFileInfo = null; if (!isCdnOnlyMode) { //string databasePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\" + MetaStateSettings._DatabaseName; string databasePath = MetaStateSettings._BaseUnityFolder + MetaStateSettings._DatabaseFileName; DataLayer.Instance.Init(databasePath); currentDataVersion = DataLayer.Instance.GetTable <DataVersion>().First().Version; DataLayer.Instance.Connection.Close(); var databaseFileInfo = new AssetFileInfo(databasePath, MetaStateSettings._AssetManagerStartupFolder + Path.GetFileName(databasePath) + MetaStateSettings._AssetManagerVersionString + currentDataVersion.ToString(), true); if (currentManifest.DataVersion != currentDataVersion) { databaseFileInfo.ForceSync = true; } allFiles.Add(databaseFileInfo); } else { currentDataVersion = currentManifest.DataVersion; string dbFilename = MetaStateSettings._AssetManagerStartupFolder + MetaStateSettings._DatabaseName + MetaStateSettings._AssetManagerVersionString + currentDataVersion.ToString(); previousDbFileInfo = currentManifest.Files.Where(y => y.RelativeName == dbFilename).SingleOrDefault(); if (previousDbFileInfo != null) { Console.WriteLine("Will re-import " + previousDbFileInfo.RelativeName + " to manifest..."); } } List <AssetFileInfo> allFilesToBeSynced = new List <AssetFileInfo>(); foreach (var file in allFiles) { var cdnFile = allCdnContent.Result.Contents.Where(y => y.Key == file.RelativeName).SingleOrDefault(); var playFabEntry = currentManifest.GetFile(file.RelativeName); if (playFabEntry == null || cdnFile == null || playFabEntry.Size != file.Size || file.ForceSync) { allFilesToBeSynced.Add(file); Console.WriteLine(file.RelativeName + " must be synced."); } } if (allFilesToBeSynced.Count > 0) { Console.WriteLine(string.Format("{0} file(s) must be synced. Press 1 to sync, 0 to cancel:", allFilesToBeSynced.Count.ToString())); switch (Console.ReadKey().Key) { case ConsoleKey.D1: Console.WriteLine(Environment.NewLine); Console.WriteLine("Starting CDN Sync..."); bool hasError = false; int i = 1; foreach (var file in allFilesToBeSynced) { Console.WriteLine(string.Format("Uploading file {0} of {1}. ({2})", i.ToString(), allFilesToBeSynced.Count.ToString(), file.RelativeName)); if (!UploadFileToCDN(file.RelativeName, file.ToArray())) { hasError = true; Console.WriteLine(string.Format("ERROR UPLOADING {0} of {1}. ({2})", i.ToString(), allFilesToBeSynced.Count.ToString(), file.RelativeName)); break; } i++; } if (!hasError) { Console.WriteLine("All files uploaded..."); Console.WriteLine("Creating and uploading manifest..."); currentManifest.ManifestVersion++; currentManifest.DataVersion = currentDataVersion; currentManifest.Files = new List <AssetFileInfo>(); currentManifest.Files.AddRange(allFiles); if (previousDbFileInfo != null) { currentManifest.Files.Add(previousDbFileInfo); } var updateData = PlayFabServerAPI.SetTitleDataAsync(new PlayFab.ServerModels.SetTitleDataRequest() { Key = MetaStateSettings._TitleDataKey_CdnManifest, Value = currentManifest.ToJson() }).GetAwaiter().GetResult(); if (updateData.Error == null) { Console.WriteLine("Mafinest uploaded."); Console.WriteLine("CDN Sync is COMPLETED."); } else { Console.WriteLine("Mafinest uploaded failed."); } } break; } } else { Console.WriteLine("No files to be synced!"); } //Console.WriteLine("Bruh, press any key to exit program."); //Console.ReadKey(); }
static void WriteData(Dictionary <string, string> resPathDic) { AssetManifest manifest = new AssetManifest(); manifest.AssetLst = new List <AssetElement>(); foreach (string path in resPathDic.Keys) { AssetElement element = new AssetElement(); element.Path = path; //element.Crc = Crc32.GetCrc32(path); element.ABName = resPathDic[path]; element.AssetName = path.Remove(0, path.LastIndexOf("/") + 1); element.DependAB = new List <string>(); string[] resDependce = AssetDatabase.GetDependencies(path); for (int i = 0; i < resDependce.Length; i++) { string tempPath = resDependce[i]; string abName = ""; if (mAllFileABNameDic.TryGetValue(tempPath, out abName)) { if (abName == resPathDic[path])//依赖资源就在本包内 忽略 (其实就包含了过滤自己) { continue; } if (!element.DependAB.Contains(abName)) { element.DependAB.Add(abName); } } } manifest.AssetLst.Add(element); } //写入xml string xmlPath = Application.dataPath + "/assetmanifest.xml"; if (File.Exists(xmlPath)) { File.Delete(xmlPath); } FileStream fileStream = new FileStream(xmlPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); StreamWriter sw = new StreamWriter(fileStream, System.Text.Encoding.UTF8); XmlSerializer xs = new XmlSerializer(manifest.GetType()); xs.Serialize(sw, manifest); sw.Close(); fileStream.Close(); //写入二进制 //foreach (AssetElement abBase in manifest.AssetLst) //{ // abBase.Path = ""; //} FileStream fs = new FileStream(mABBinaryPath, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite); fs.Seek(0, SeekOrigin.Begin); fs.SetLength(0); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, manifest); fs.Close(); AssetDatabase.Refresh(); setABName("assetmanifest", mABBinaryPath); }
public static void BuildAssetBundles(string inOutputDir, BuildTarget inBuildTarget) { // This will force the AssetDB to pick up any changes AssetDatabase.Refresh(); List <AssetManifest.BundleInfo> bundleInfoList = new List <AssetManifest.BundleInfo>(); List <AssetBundleBuild> bundleList = new List <AssetBundleBuild>(); Dictionary <string, Bundle> dataBundles = new Dictionary <string, Bundle>(); EditorDataUtil.ProcessAcrossAllData(info => { string bundleName = info.Data.Name + info.Data.GetType().Name; List <string> guids = new List <string>(); List <string> assetPaths = new List <string>(); // we always have the base bundle at index 0 dataBundles[bundleName] = new Bundle(bundleName, guids, assetPaths); ExtractBundleReference(bundleName, info.Data, ref dataBundles); }); foreach (KeyValuePair <string, Bundle> b in dataBundles) { Bundle currentBundle = b.Value; if (currentBundle.Guids.Count > 0) { AssetBundleBuild bundle = new AssetBundleBuild { assetBundleName = b.Key, assetNames = currentBundle.AssetPaths.Distinct().ToArray() }; bundleList.Add(bundle); AssetManifest.BundleInfo bundleInfo = new AssetManifest.BundleInfo { assetNames = bundle.assetNames, guids = currentBundle.Guids.Distinct().ToArray(), name = b.Key.ToLower(), dependencies = currentBundle.Dependecies.ToArray() }; // the files are case sensitive on the web under unix systems! Thus we use lowercase bundleInfoList.Add(bundleInfo); } } if (!Directory.Exists(inOutputDir)) { Directory.CreateDirectory(inOutputDir); } // Uncompress bundles on android are a must due to the slow IO :( // outside that we should always used the chunk based compression. BuildAssetBundleOptions options = BuildAssetBundleOptions.UncompressedAssetBundle; if (inBuildTarget != BuildTarget.Android) { options = BuildAssetBundleOptions.ChunkBasedCompression; } AssetBundleManifest unityManifestFile = BuildPipeline.BuildAssetBundles(inOutputDir, bundleList.ToArray(), options, inBuildTarget); // no new bundles were generated during this build. if (unityManifestFile == null) { return; } string[] files = Directory.GetFiles(inOutputDir, "*.manifest"); AssetManifest manifest = new AssetManifest { bundles = bundleInfoList.ToArray() }; foreach (AssetManifest.BundleInfo bundleInfo in manifest.bundles) { string hash = string.Empty; string bundlePath = files.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x) == bundleInfo.name); if (!string.IsNullOrEmpty(bundlePath)) { hash = GetFileCRC(bundlePath); } // we use the hash included in the bundle manifest so we can then use it for versioning // when passing into LoadFromCacheOrDownload ? bundleInfo.hash = hash; string[] dependencies = unityManifestFile.GetAllDependencies(bundleInfo.name); // messy but oh well :P bundleInfo.dependencies = bundleInfo.dependencies.Concat(dependencies).Distinct().ToArray(); } // Set some version number! int version = 0; manifest.version = version; Serializer.Serialize(manifest, inOutputDir + Path.DirectorySeparatorChar + "AssetManifest.xml"); }
public void OnPreprocessBuild(BuildReport report) { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); byte[] bytes = AssetManifest.Export(); File.WriteAllBytes($"{report.summary.outputPath}/AssetManifest", bytes); }