| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //------------------------------------------------------------
- // Game Framework
- // Copyright © 2013-2021 Jiang Yin. All rights reserved.
- // Homepage: https://gameframework.cn/
- // Feedback: mailto:ellan@gameframework.cn
- //------------------------------------------------------------
- using GameFramework;
- using System.Collections.Generic;
- using System.IO;
- using UnityEditor;
- using UnityEngine;
- using UnityGameFramework.Editor.ResourceTools;
- //using HybridCLR.Editor;
- namespace GFMain.Editor
- {
- /// <summary>
- /// 在线资源更新版生成资源处理
- /// 通过生成信息,生成版本信息VersionInfo文档,生成于full文件夹下
- /// </summary>
- public sealed class UpdatableBuildEventHandler : IBuildEventHandler
- {
- private const string UpdateURL = "http://192.168.1.23:8008/_res/Full";//服务器更新路径
- private static string OutPutDirectory { get; set; }
- public bool ContinueOnFailure { get { return false; } }
- private static VersionInfo m_VersionInfo = new VersionInfo();
- public void OnPreprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
- Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
- string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
- {
- //...
- //赋值Version需要参数
- m_VersionInfo.LatestGameVersion = applicableGameVersion;
- m_VersionInfo.InternalResourceVersion = internalResourceVersion;
- m_VersionInfo.InternalGameVersion = 1;
- OutPutDirectory = outputDirectory;
- }
- public void OnPostprocessAllPlatforms(string productName, string companyName, string gameIdentifier, string gameFrameworkVersion, string unityVersion, string applicableGameVersion, int internalResourceVersion,
- Platform platforms, AssetBundleCompressionType assetBundleCompression, string compressionHelperTypeName, bool additionalCompressionSelected, bool forceRebuildAssetBundleSelected, string buildEventHandlerTypeName, string outputDirectory, BuildAssetBundleOptions buildAssetBundleOptions,
- string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, string buildReportPath)
- {
- }
- public void OnPreprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath)
- {
- //生成元数据补充清单
- //var jw = new LitJson.JsonWriter() { PrettyPrint = true };
- //var metadataArr = (AOTGenericReferences.PatchedAOTAssemblyList as List<string>).ToArray();
- //for (int i = 0; i < metadataArr.Length; i++)
- //{
- // metadataArr[i] = EditorUserBuildSettings.activeBuildTarget.ToString() + "/" + metadataArr[i];
- //}
- //LitJson.JsonMapper.ToJson(metadataArr, jw);
- //var metadataArrJson = jw.TextWriter.ToString();
- //var savePath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "HybridCLRGenerate", platform + "MetadataList.txt"));
- //File.WriteAllText(savePath, metadataArrJson);
- //Debug.Log("XXXMetadataList.txt save success!!!");
- ////拷贝补充元数据dll到对应目录
- //for (int i = 0; i < metadataArr.Length; i++)
- //{
- // var strOrigPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/HybridCLRData/AssembliesPostIl2CppStrip/" + metadataArr[i];
- // var strDestPath = Application.dataPath + "/HybridCLRGenerate/" + metadataArr[i] + ".bytes";
- // string strPath = Path.GetDirectoryName(strDestPath);
- // if (!Directory.Exists(strPath)) Directory.CreateDirectory(strPath);
- // File.Copy(strOrigPath, strDestPath, true);
- //}
- ////拷贝热更dll到对应目录
- //string[] hotDllNames = new string[HybridCLRSettings.Instance.hotUpdateAssemblyDefinitions.Length];
- //for (int i = 0; i < HybridCLRSettings.Instance.hotUpdateAssemblyDefinitions.Length; ++i)
- //{
- // var path = AssetDatabase.GetAssetPath(HybridCLRSettings.Instance.hotUpdateAssemblyDefinitions[i]);
- // var dllName = hotDllNames[i] = HybridCLRSettings.Instance.hotUpdateAssemblyDefinitions[i].name;
- // var strOrigPath = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf("/")) + "/HybridCLRData/HotUpdateDlls/" + EditorUserBuildSettings.activeBuildTarget.ToString() + "/" + dllName + ".dll";
- // var strDestPath = Path.Combine(Application.dataPath + path.Substring(6).Replace("asmdef", "dll.bytes"));// "/APPContainer/Res/DLL/" + dllName + ".dll.bytes");// ;
- // Debug.Log(strDestPath);
- // string strPath = Path.GetDirectoryName(strDestPath);
- // if (!Directory.Exists(strPath)) Directory.CreateDirectory(strPath);
- // File.Copy(strOrigPath, strDestPath, true);
- //}
- }
- public void OnBuildAssetBundlesComplete(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, AssetBundleManifest assetBundleManifest)
- {
- }
- public void OnOutputUpdatableVersionListData(Platform platform, string versionListPath, int versionListLength, int versionListHashCode, int versionListCompressedLength, int versionListCompressedHashCode)
- {
- //赋值Version版本相关参数
- m_VersionInfo.ForceUpdateGame = false;
- m_VersionInfo.VersionListLength = versionListLength;
- m_VersionInfo.VersionListHashCode = versionListHashCode;
- m_VersionInfo.VersionListCompressedLength = versionListCompressedLength;
- m_VersionInfo.VersionListCompressedHashCode = versionListCompressedHashCode;
- }
- public void OnPostprocessPlatform(Platform platform, string workingPath, bool outputPackageSelected, string outputPackagePath, bool outputFullSelected, string outputFullPath, bool outputPackedSelected, string outputPackedPath, bool isSuccess)
- {
- if (outputFullSelected)
- {
- //保存XXXVersion.txt到Full目录
- var versionName = m_VersionInfo.LatestGameVersion.Replace(".", "_") + "_" + m_VersionInfo.InternalResourceVersion;
- m_VersionInfo.UpdatePrefixUri = Utility.Path.GetRegularPath(Path.Combine(UpdateURL, versionName, platform.ToString()));
- var jw = new LitJson.JsonWriter() { PrettyPrint = true };
- LitJson.JsonMapper.ToJson(m_VersionInfo, jw);
- var versionJson = jw.TextWriter.ToString();
- var savePath = Utility.Path.GetRegularPath(Path.Combine(OutPutDirectory, "Full", platform + "Version.txt"));
- File.WriteAllText(savePath, versionJson);
- Debug.Log("Version.txt save success!!!");
- }
- if (outputPackageSelected)
- {//单机,移动打包文件到StreamingAssets文件夹
- if (platform == Platform.Windows || platform == Platform.Windows64)
- {
- string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
- string[] fileNames = Directory.GetFiles(outputPackagePath, "*", SearchOption.AllDirectories);
- foreach (string fileName in fileNames)
- {
- string destFileName = Utility.Path.GetRegularPath(Path.Combine(streamingAssetsPath, fileName.Substring(outputPackagePath.Length)));
- FileInfo destFileInfo = new FileInfo(destFileName);
- if (!destFileInfo.Directory.Exists)
- {
- destFileInfo.Directory.Create();
- }
- File.Copy(fileName, destFileName, true);
- }
- }
- }
- if (outputPackedSelected)
- {//拷贝Packed文件到StreamingAssets
- string streamingAssetsPath = Utility.Path.GetRegularPath(Path.Combine(Application.dataPath, "StreamingAssets"));
- string[] fileNames = Directory.GetFiles(outputPackedPath, "*", SearchOption.AllDirectories);
- foreach (string fileName in fileNames)
- {
- string destFileName = Utility.Path.GetRegularPath(Path.Combine(streamingAssetsPath, fileName.Substring(outputPackedPath.Length)));
- FileInfo destFileInfo = new FileInfo(destFileName);
- if (!destFileInfo.Directory.Exists)
- {
- destFileInfo.Directory.Create();
- }
- File.Copy(fileName, destFileName, true);
- }
- }
- }
- }
- }
|