public override void OnInspectorGUI() { BytesAsset text = (BytesAsset)target; scrololPos = GUILayout.BeginScrollView(scrololPos); GUILayout.TextArea(Encoding.UTF8.GetString(text.bytes)); GUILayout.EndScrollView(); }
public override void OnImportAsset(AssetImportContext ctx) { var fileName = System.IO.Path.GetFileNameWithoutExtension(ctx.assetPath); BytesAsset ba = ScriptableObject.CreateInstance <BytesAsset>(); ba.bytes = File.ReadAllBytes(ctx.assetPath); ctx.AddObjectToAsset(fileName, ba); ctx.SetMainObject(ba); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, bool copyToResFolder = false) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); // Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; uint fileSize = 0; uint fileCrc = 0; if (copyToResFolder) { resOutPath = tmpPath;//Path.Combine(tmpPath, ResFolderName); //Path.Combine(SplitPackage.UpdateOutPath, ResFolderName); abPath = Path.Combine(resOutPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); //copy first crc list string crc32FirstOutName = CUtils.InsertAssetBundleName(crc32outfilename, "_v" + CodeVersion.CODE_VERSION.ToString()); if (!firstExists) //如果没有首包 copy first package { string destFirst = Path.Combine(UpdateOutPath, crc32FirstOutName); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); } //copy crc list FileInfo finfo = new FileInfo(abPath); var resType = HugulaSetting.instance.backupResType; if (resType == CopyResType.VerResFolder) { string verPath = Path.Combine(UpdateOutVersionPath, ResFolderName);//特定版本资源目录用于资源备份 string newName = Path.Combine(verPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } if (resType == CopyResType.OneResFolder) { string updateOutPath = Path.Combine(UpdateOutPath, ResFolderName);//总的资源目录 string newName = Path.Combine(updateOutPath, InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); FileHelper.CheckCreateFilePathDirectory(newName); if (File.Exists(newName)) { File.Delete(newName); } finfo.CopyTo(newName); } } else { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); } CrcCheck.Clear(); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); return(fileCrc); }
/// <summary> /// Creates the streaming crc list. /// </summary> /// <param name="sb">Sb.</param> public static uint CreateStreamingCrcList(StringBuilder sb, bool firstExists = false, string outPath = null) { var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string tmpPath = BuildScript.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); ExportResources.CheckDirectory(tmpPath); string assetPath = "Assets/" + BuildScript.TmpPath + crc32filename + ".asset"; EditorUtility.DisplayProgressBar("Generate streaming crc file list", "write file to " + assetPath, 0.99f); string outTmpPath = Path.Combine(tmpPath, crc32filename + ".lua"); using (StreamWriter sr = new StreamWriter(outTmpPath, false)) { sr.Write(sb.ToString()); } // //打包到streaming path AssetDatabase.Refresh(); BytesAsset ba = ScriptableObject.CreateInstance(typeof(BytesAsset)) as BytesAsset; ba.bytes = File.ReadAllBytes(outTmpPath); AssetDatabase.CreateAsset(ba, assetPath); string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); Debug.Log("write to path=" + outPath); Debug.Log(sb.ToString()); //读取crc string abPath = string.Empty; string resOutPath = null; if (string.IsNullOrEmpty(outPath)) { abPath = Path.Combine(CUtils.realStreamingAssetsPath, crc32outfilename); } else { resOutPath = Path.Combine(outPath, ResFolderName); ExportResources.CheckDirectory(resOutPath); abPath = Path.Combine(resOutPath, crc32outfilename); } BuildScript.BuildABs(new string[] { assetPath }, resOutPath, crc32outfilename, BuildAssetBundleOptions.DeterministicAssetBundle); CrcCheck.Clear(); uint fileSize = 0; uint fileCrc = CrcCheck.GetLocalFileCrc(abPath, out fileSize); EditorUtility.ClearProgressBar(); Debug.Log("Crc file list assetbunle build complate! " + fileCrc.ToString() + abPath); if (!string.IsNullOrEmpty(outPath)) { string newName = Path.Combine(resOutPath, CUtils.InsertAssetBundleName(crc32outfilename, "_" + fileCrc.ToString())); if (File.Exists(newName)) { File.Delete(newName); } FileInfo finfo = new FileInfo(abPath); if (!firstExists) //如果没有首包 { string destFirst = Path.Combine(outPath, crc32outfilename); Debug.Log("destFirst:" + destFirst); File.Copy(abPath, destFirst, true); // finfo.CopyTo(destFirst); } finfo.MoveTo(newName); Debug.Log(" change name to " + newName); } return(fileCrc); }