111
This commit is contained in:
88
Assets/GameFramework/Editor/BuildTool.cs
Normal file
88
Assets/GameFramework/Editor/BuildTool.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using YooAsset.Editor;
|
||||
using YooAsset;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
|
||||
public class BuildTool
|
||||
{
|
||||
[MenuItem("Tools/打包Preload")]
|
||||
public static void BuildPreload()
|
||||
{
|
||||
CopyHotDll.CopyPreloadDll2Byte();
|
||||
ExecuteBuild("Preload",EBuildPipeline.ScriptableBuildPipeline, EditorUserBuildSettings.activeBuildTarget,EFileNameStyle.BundleName,EBuildinFileCopyOption.ClearAndCopyAll);
|
||||
Debug.Log($"打包Preload结束");
|
||||
}
|
||||
[MenuItem("Tools/打包Main %G")]
|
||||
public static void BuildMain()
|
||||
{
|
||||
CopyHotDll.CopyMainDll2Byte();
|
||||
ExecuteBuild("Main", EBuildPipeline.ScriptableBuildPipeline, EditorUserBuildSettings.activeBuildTarget, EFileNameStyle.BundleName, EBuildinFileCopyOption.None);
|
||||
Debug.Log($"打包Main结束");
|
||||
}
|
||||
[MenuItem("Tools/全部打包")]
|
||||
public static void BuildAll()
|
||||
{
|
||||
BuildPreload();
|
||||
BuildMain();
|
||||
}
|
||||
|
||||
public static void ExecuteBuild(string PackageName, EBuildPipeline BuildPipeline, BuildTarget BuildTarget, EFileNameStyle fileNameStyle, EBuildinFileCopyOption buildinFileCopyOption)
|
||||
{
|
||||
var buildinFileCopyParams = AssetBundleBuilderSetting.GetPackageBuildinFileCopyParams(PackageName, BuildPipeline.ToString());
|
||||
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, BuildPipeline.ToString());
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, BuildPipeline.ToString());
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, BuildPipeline.ToString());
|
||||
var builtinShaderBundleName = GetBuiltinShaderBundleName(PackageName);
|
||||
|
||||
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = BuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = GetPackageVersion();
|
||||
buildParameters.EnableSharePackRule = true;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BuildinFileCopyOption = buildinFileCopyOption;
|
||||
buildParameters.BuildinFileCopyParams = buildinFileCopyParams;
|
||||
buildParameters.CompressOption = compressOption;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
|
||||
buildParameters.EncryptionServices = CreateEncryptionInstance(PackageName, BuildPipeline);
|
||||
|
||||
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
public static string GetPackageVersion()
|
||||
{
|
||||
int totalMinutes = DateTime.Now.Hour * 60 + DateTime.Now.Minute;
|
||||
return DateTime.Now.ToString("yyyy-MM-dd") + "-" + totalMinutes;
|
||||
}
|
||||
|
||||
private static string GetBuiltinShaderBundleName(string PackageName)
|
||||
{
|
||||
var uniqueBundleName = AssetBundleCollectorSettingData.Setting.UniqueBundleName;
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
return packRuleResult.GetBundleName(PackageName, uniqueBundleName);
|
||||
}
|
||||
public static IEncryptionServices CreateEncryptionInstance(string PackageName, EBuildPipeline BuildPipeline)
|
||||
{
|
||||
var encyptionClassName = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, BuildPipeline.ToString());
|
||||
var encryptionClassTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices));
|
||||
var classType = encryptionClassTypes.Find(x => x.FullName.Equals(encyptionClassName));
|
||||
if (classType != null)
|
||||
return (IEncryptionServices)Activator.CreateInstance(classType);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
Assets/GameFramework/Editor/BuildTool.cs.meta
Normal file
2
Assets/GameFramework/Editor/BuildTool.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ef4dc48fe62a00246bf7a5beb87f7c4a
|
||||
63
Assets/GameFramework/Editor/CopyHotDll.cs
Normal file
63
Assets/GameFramework/Editor/CopyHotDll.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
|
||||
public class CopyHotDll
|
||||
{
|
||||
[MenuItem("Tools/更新生成PreloadDll")]
|
||||
public static void CopyPreloadDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/HotUpdateDlls/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/GameScripts.Preload.dll";
|
||||
string destDir = $"{Application.dataPath}/GameRes/Preload/HotUpdateDll/GameScripts.Preload.bytes";
|
||||
if (File.Exists(destDir))
|
||||
{
|
||||
File.Delete(destDir);
|
||||
}
|
||||
File.Copy(sourceDir, destDir);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourceDir} to {destDir}");
|
||||
}
|
||||
[MenuItem("Tools/更新生成MainDll")]
|
||||
public static void CopyMainDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/HotUpdateDlls/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/GameScripts.Main.dll";
|
||||
string destDir = $"{Application.dataPath}/GameRes/Main/HotUpdateDll/GameScripts.Main.bytes";
|
||||
if (File.Exists(destDir))
|
||||
{
|
||||
File.Delete(destDir);
|
||||
}
|
||||
File.Copy(sourceDir, destDir);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourceDir} to {destDir}");
|
||||
}
|
||||
[MenuItem("Tools/更新生成补充数据源")]
|
||||
public static void CopyDepDll2Byte()
|
||||
{
|
||||
HybridCLR.Editor.Commands.CompileDllCommand.CompileDllActiveBuildTarget();
|
||||
string sourceDir = $"{Application.dataPath.Replace("/Assets", "")}/HybridCLRData/AssembliesPostIl2CppStrip/{UnityEditor.EditorUserBuildSettings.activeBuildTarget}/";
|
||||
string destDir = $"{Application.dataPath}/GameRes/Main/HotUpdateDll/";
|
||||
foreach (string dll in Boot.Inst.DepDlls)
|
||||
{
|
||||
string sourcePath = $"{sourceDir}/{dll}";
|
||||
string destPath = $"{destDir}/{dll}.bytes";
|
||||
if (File.Exists(sourcePath))
|
||||
{
|
||||
if (File.Exists(destPath))
|
||||
{
|
||||
File.Delete(destPath);
|
||||
}
|
||||
File.Copy(sourcePath, destPath);
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"copy {sourcePath} to {destPath}");
|
||||
}
|
||||
}
|
||||
Debug.Log("copy over");
|
||||
}
|
||||
}
|
||||
2
Assets/GameFramework/Editor/CopyHotDll.cs.meta
Normal file
2
Assets/GameFramework/Editor/CopyHotDll.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4a15e4a3e4bbd7c4c9c3783ac0028089
|
||||
@@ -1,9 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using YooAsset;
|
||||
|
||||
public class Boot : MonoBehaviour
|
||||
public class Boot : SingletonMono<Boot>
|
||||
{
|
||||
public List<string> DepDlls = new List<string>()
|
||||
{
|
||||
"mscorlib.dll",
|
||||
"System.dll",
|
||||
"System.Core.dll",
|
||||
"Mirror.dll"
|
||||
};
|
||||
public GameObject MainUICanvas;
|
||||
public Camera UICamera;
|
||||
public EPlayMode PlayMode = EPlayMode.EditorSimulateMode;
|
||||
|
||||
19
Assets/GameFramework/Runtime/GameFramework.Runtime.asmdef
Normal file
19
Assets/GameFramework/Runtime/GameFramework.Runtime.asmdef
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "GameFramework.Runtime",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:e34a5702dd353724aa315fb8011f08c3",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:3fe1a3e70da50184f9897101cad7e4f2",
|
||||
"GUID:13ba8ce62aa80c74598530029cb2d649"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63f032f8696ad5b4e99c26f7a9f89060
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
34
Assets/GameFramework/Runtime/PatchLogic/HotDllLoader.cs
Normal file
34
Assets/GameFramework/Runtime/PatchLogic/HotDllLoader.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using HybridCLR;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
public class HotDllLoader : Singleton<HotDllLoader>
|
||||
{
|
||||
public void LoadDll(ResourcePackage package, string dll)
|
||||
{
|
||||
if (package.GetAssetInfo(dll).Error == string.Empty)
|
||||
{
|
||||
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
|
||||
#if UNITY_EDITOR
|
||||
Assembly hotUpdateAss = System.AppDomain.CurrentDomain.GetAssemblies().First(a => a.GetName().Name == dll.Replace(".dll", ""));
|
||||
#else
|
||||
Assembly hotUpdateAss = Assembly.Load((handle.AssetObject as TextAsset).bytes);
|
||||
#endif
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD>{dll}");
|
||||
}
|
||||
}
|
||||
public void LoadDepDll(ResourcePackage package, List<string> dlls)
|
||||
{
|
||||
foreach (string dll in dlls)
|
||||
{
|
||||
if (package.GetAssetInfo(dll).Error == string.Empty)
|
||||
{
|
||||
AssetHandle handle = package.LoadAssetSync<TextAsset>(dll);
|
||||
RuntimeApi.LoadMetadataForAOTAssembly((handle.AssetObject as TextAsset).bytes, HomologousImageMode.SuperSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 913490bf1a0079744825742899c17961
|
||||
@@ -1,4 +1,5 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using YooAsset;
|
||||
|
||||
@@ -6,7 +7,8 @@ public class MainOperation
|
||||
{
|
||||
PatchOperationData data;
|
||||
PatchOperation operation;
|
||||
public MainOperation(EPlayMode playMode)
|
||||
bool autoDownload;
|
||||
public MainOperation(EPlayMode playMode, bool autoDownload = false)
|
||||
{
|
||||
data = new PatchOperationData();
|
||||
data.packageName = "Main";
|
||||
@@ -14,12 +16,18 @@ public class MainOperation
|
||||
data.useBuildinFileSystem = false;
|
||||
data.downloadingMaxNum = 10;
|
||||
data.failedTryAgain = 3;
|
||||
data.downloadUpdate = OnDownloadUpdate;
|
||||
data.downloadFinish = OnDownloadFinish;
|
||||
data.downloadError = OnDownloadError;
|
||||
|
||||
operation = new PatchOperation(data);
|
||||
this.autoDownload = autoDownload;
|
||||
}
|
||||
|
||||
public async UniTask Execute()
|
||||
{
|
||||
|
||||
PatchEvent.UpdateProgress(0f);
|
||||
InitializationOperation initializationOperation = await operation.InitializePackage();
|
||||
//<2F><>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
|
||||
if (initializationOperation.Status != EOperationStatus.Succeed)
|
||||
@@ -30,6 +38,8 @@ public class MainOperation
|
||||
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
|
||||
return;
|
||||
}
|
||||
PatchEvent.UpdateStatus($"<22><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
|
||||
Debug.Log($"<22><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
|
||||
var PackageVersionOperation = await operation.RequestPackageVersion();
|
||||
if (PackageVersionOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
@@ -40,6 +50,8 @@ public class MainOperation
|
||||
return;
|
||||
}
|
||||
operation.packageVersion = PackageVersionOperation.PackageVersion;
|
||||
PatchEvent.UpdateStatus($"<22><>ȡ<EFBFBD>汾<EFBFBD>ɹ<EFBFBD>{operation.data.packageName}");
|
||||
Debug.Log($"<22><>ȡ<EFBFBD>汾<EFBFBD>ɹ<EFBFBD>{operation.data.packageName}<7D><>{operation.packageVersion}");
|
||||
var PackageManifestOperation = await operation.UpdatePackageManifest();
|
||||
if (PackageManifestOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
@@ -53,25 +65,83 @@ public class MainOperation
|
||||
if (DownloaderOperation.TotalDownloadCount == 0)
|
||||
{
|
||||
operation.SaveVersionToCache();
|
||||
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{operation.data.packageName}");
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3>汾<EFBFBD><E6B1BE>{operation.packageVersion}");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (autoDownload)
|
||||
{
|
||||
if (!await Download(DownloaderOperation)) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
var completionSource = new UniTaskCompletionSource<bool>();
|
||||
MessageBox.Show()
|
||||
.SetTitle(operation.data.packageName)
|
||||
.SetContent($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>\n{operation.GetCachedPackageVersion()}=>{operation.packageVersion}: {DownloaderOperation.TotalDownloadBytes / 1024f / 1024f:F1}MB")
|
||||
.AddButton("<22><><EFBFBD><EFBFBD>", async (box) =>
|
||||
{
|
||||
bool success = await Download(DownloaderOperation);
|
||||
completionSource.TrySetResult(success);
|
||||
})
|
||||
.AddButton("<22><><EFBFBD><EFBFBD>", (box) =>
|
||||
{
|
||||
DownloaderOperation.CancelDownload();
|
||||
completionSource.TrySetResult(true);
|
||||
})
|
||||
.AddButton("<22>˳<EFBFBD>", (box) =>
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
Application.Quit();
|
||||
});
|
||||
bool shouldContinue = await completionSource.Task;
|
||||
if (!shouldContinue) return;
|
||||
}
|
||||
var ClearCacheFilesOperation = await operation.ClearCacheBundle();
|
||||
if (ClearCacheFilesOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle(operation.data.packageName)
|
||||
.SetContent($"{ClearCacheFilesOperation.Error}")
|
||||
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
|
||||
return;
|
||||
}
|
||||
operation.SaveVersionToCache();
|
||||
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{operation.data.packageName}");
|
||||
Debug.Log($"<22><><EFBFBD><EFBFBD>{operation.data.packageName}<7D><><EFBFBD>ɣ<EFBFBD><C9A3>汾<EFBFBD><E6B1BE>{operation.packageVersion}");
|
||||
}
|
||||
}
|
||||
public async UniTask<bool> Download(DownloaderOperation downloaderOperation)
|
||||
{
|
||||
if (!await operation.DownloadPackageFiles())
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle(operation.data.packageName)
|
||||
.SetContent($"{DownloaderOperation.Error}")
|
||||
.SetContent($"{downloaderOperation.Error}")
|
||||
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
var ClearCacheFilesOperation = await operation.ClearCacheBundle();
|
||||
if (ClearCacheFilesOperation.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
MessageBox.Show()
|
||||
.SetTitle(operation.data.packageName)
|
||||
.SetContent($"{ClearCacheFilesOperation.Error}")
|
||||
.AddButton("<22>˳<EFBFBD>", (box) => { Application.Quit(); });
|
||||
return;
|
||||
}
|
||||
operation.SaveVersionToCache();
|
||||
return true;
|
||||
}
|
||||
private void OnDownloadUpdate(DownloadUpdateData downloadUpdateData)
|
||||
{
|
||||
float progress = (float)downloadUpdateData.CurrentDownloadBytes / downloadUpdateData.TotalDownloadBytes;
|
||||
string sizeText = $"{(downloadUpdateData.CurrentDownloadBytes / 1024f / 1024f):F1}MB / {(downloadUpdateData.TotalDownloadBytes / 1024f / 1024f):F1}MB";
|
||||
|
||||
PatchEvent.UpdateProgress(progress);
|
||||
PatchEvent.UpdateDownloadSize(sizeText);
|
||||
PatchEvent.UpdateStatus($"{data.packageName} <20><>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
|
||||
}
|
||||
|
||||
private void OnDownloadFinish(DownloaderFinishData downloaderFinishData)
|
||||
{
|
||||
PatchEvent.UpdateStatus("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
}
|
||||
|
||||
private void OnDownloadError(DownloadErrorData downloadErrorData)
|
||||
{
|
||||
PatchEvent.UpdateStatus($"<22><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>:{downloadErrorData.FileName}\n{downloadErrorData.ErrorInfo}");
|
||||
}
|
||||
}
|
||||
|
||||
24
Assets/GameFramework/Runtime/PatchLogic/PatchEvent.cs
Normal file
24
Assets/GameFramework/Runtime/PatchLogic/PatchEvent.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public static class PatchEvent
|
||||
{
|
||||
public static event Action<string> OnStatusUpdate;
|
||||
public static event Action<float> OnProgressUpdate;
|
||||
public static event Action<string> OnDownloadSizeUpdate;
|
||||
|
||||
public static void UpdateStatus(string status)
|
||||
{
|
||||
OnStatusUpdate?.Invoke(status);
|
||||
}
|
||||
|
||||
public static void UpdateProgress(float progress)
|
||||
{
|
||||
OnProgressUpdate?.Invoke(progress);
|
||||
}
|
||||
|
||||
public static void UpdateDownloadSize(string sizeText)
|
||||
{
|
||||
OnDownloadSizeUpdate?.Invoke(sizeText);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e733509362b9e5445b0354a734ec8c10
|
||||
Reference in New Issue
Block a user