public class DefaultPath
{
public static string ProjectRootPath = Environment.CurrentDirectory;
///
/// 可读
///
public static string ReadOnlyStreamingPath = Application.streamingAssetsPath;
///
/// 可读可写全平台通用
///
public static string ReadAndWritePath = Application.persistentDataPath;
///
/// <项目路径>/Assets 仅在编辑器使用 属于unity工程目录下
///
public static string AssetFolderPath = Application.dataPath;
//输出路径
public static string OutputPath = DefaultPath.AssetFolderPath + "/AddressableFiles/TransformDLL";
public static string LoadDllPath = OutputPath + "/HotFix_Project_DLL.bytes";
public static string LoadPDBPath = OutputPath + "/HotFix_Project_PDB.bytes";
static DefaultPath()
{
Debug.Log($"ProjectRootPath_{ProjectRootPath}\n{nameof(ReadOnlyStreamingPath)}_{ReadOnlyStreamingPath}\n{nameof(ReadAndWritePath)}_{ReadAndWritePath}\n{nameof(AssetFolderPath)}_{AssetFolderPath}");
}
}
public class ILRuntimeHelper
{
const string srcKey = "SrcDLLPath";
public static string TargetDll => PathUtility.GetRootPath(srcKey) + "/HotFix_Project.dll";
public static string TargetPDB => PathUtility.GetRootPath(srcKey) + "/HotFix_Project.pdb";
public static string OutputPath => DefaultPath.OutputPath;
public static string LoadDllPath => DefaultPath.LoadDllPath;
public static string LoadPDBPath => DefaultPath.LoadPDBPath;
public const string Symbol = "TestRemoteLoadCode";
[MenuItem("Tools/指定加載DLL的文件夾")]
private static void SetDLLPath()
{
PathUtility.SetRootPath(srcKey);
}
[MenuItem("Tools/DllToByte")]
private static void DLLToBytes()
{
if (!File.Exists(OutputPath))
{
Directory.CreateDirectory(OutputPath);
}
void CheckFileValid(string path, string loadPath)
{
if (!File.Exists(path))
{
throw new Exception($"不存在指定文件{path}");
}
File.WriteAllBytes(loadPath, File.ReadAllBytes(path));
}
CheckFileValid(TargetDll, LoadDllPath);
CheckFileValid(TargetPDB, LoadPDBPath);
AssetDatabase.Refresh();
}
}


call 就是调用的意思,projectDir是内置宏,就是热更项目所在的文件夹
::切换到bat文件所在的文件夹
cd /d %~dp0
::%NAME%可以引用变量
::set 可以设置变量
set PROJECTNAME=HotFix_Project
set OUTDLLNAME=%PROJECTNAME%_DLL.bytes
set OUTPDBNAME=%PROJECTNAME%_PDB.bytes
set FROMDLLNAME=%PROJECTNAME%.pdb
set FROMPDBNAME=%PROJECTNAME%.dll
set curdir=%cd%
set EXENAME=%curdir%\TransformHotfixDLL.exe
set DLLPATH=%curdir%\bin\%FROMDLLNAME%
set PDBPATH=%curdir%\bin\%FROMPDBNAME%
cd ..
set curdir=%cd%
set OUTDLLPATH=%curdir%\Assets\AddressableFiles\TransformDLL\%OUTDLLNAME%
set OUTPDBPATH=%curdir%\Assets\AddressableFiles\TransformDLL\%OUTPDBNAME%
set OUTPUTPATH=%curdir%\Assets\AddressableFiles\TransformDLL
::start是启动程序 后面的字符串是输入程序的参数
start %EXENAME% "%DLLPATH%|%PDBPATH%|%OUTPUTPATH%|%OUTDLLPATH%|%OUTPDBPATH%"
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace TransformHotfixDLL
{
internal class Program
{
static void Main(string[] args)
{
var paths = args[0].Split('|');
var fromDLLPath = paths[0];
var fromPDBPath = paths[1];
var targetPath = paths[2];
var LoadPDBPath = paths[3];
var LoadDllPath = paths[4];
if (!File.Exists(targetPath))
{
Directory.CreateDirectory(targetPath);
}
void CheckFileValid(string path, string loadPath)
{
if (!File.Exists(path))
{
throw new Exception($"不存在指定文件{path}");
}
File.WriteAllBytes(loadPath, File.ReadAllBytes(path));
}
CheckFileValid(fromDLLPath, LoadDllPath);
CheckFileValid(fromPDBPath, LoadPDBPath);
}
}
}
asdemf程序集定义文件