unity/nuget/README.md
可用的平台 .net8.0, win-x64, linux-x64, osx (universal binary)
Python 的 osx 版本目前仅支持 osx-arm64
目前不支持AOT
引入Puerts ( Puerts.Core 包),并根据需求引入需要运行的平台的 NativeAssets (.dll, .so ...),
没有 NativeAssets 则无法在对应的平台运行
例如
Puerts.Core.NativeAssets.Win32 对应 WindowsPuerts.Core.NativeAssets.Linux 对应 LinuxPuerts.Core.NativeAssets.macOS 对应 macOS引入需要的扩展,以下是支持的扩展,同样的,也需要引入对应的 NativeAssets
Puerts.LuaPuerts.NodeJSPuerts.PythonPuerts.QuickJSPuerts.V8简单用例,已引入 Puerts.Core、 Puerts.V8 以及对应的 NativeAssets 包
using Puerts;
var jsEnv = new ScriptEnv(new BackendV8());
jsEnv.Eval(@"CS.System.Console.WriteLine('hello world');");
jsEnv.Dispose();
Console.WriteLine("Press any key to exit...");
构建包的版本可以通过设置 Directory.Build.props 中的各个版本号来定义
版本是从各个upm包的 package.json 中读取的
<PuertsCoreVersion></PuertsCoreVersion>
<PuertsLuaVersion></PuertsLuaVersion>
<PuertsNodeJsVersion></PuertsNodeJsVersion>
<PuertsPythonVersion></PuertsPythonVersion>
<PuertsQuickJsVersion></PuertsQuickJsVersion>
<PuertsV8Version></PuertsV8Version>
设置目标的框架
<PuertsCurrentTargetFrameworks>net8.0</PuertsCurrentTargetFrameworks>
<PuertsNativeAssetsLinuxTargetFrameworks>net8.0</PuertsNativeAssetsLinuxTargetFrameworks>
<PuertsNativeAssetsWin32TargetFrameworks>net8.0</PuertsNativeAssetsWin32TargetFrameworks>
<PuertsNativeAssetsmacOSTargetFramework>net8.0</PuertsNativeAssetsmacOSTargetFramework>
在Windows下构建、发布
# 构建
.\build.ps1 --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget"
# 构建并发布
.\build.ps1 --NativeAssetsDirectory "xxx\puerts\unity\downloaded_natives" --ProjectsRoot "xxx\puerts\unity\nuget" --Source "https://api.nuget.org/v3/index.json" --ApiKey "your-nuget-api-key"
在Linux/macOS下构建、发布
# 构建
./build.sh --NativeAssetsDirectory "xxx/puerts/unity/downloaded_natives" --ProjectsRoot "xxx/puerts/unity/nuget"
# 构建并发布
/build.sh --NativeAssetsDirectory "xxx/puerts/unity/downloaded_natives" --ProjectsRoot "xxx/puerts/unity/nuget" --Source "https://api.nuget.org/v3/index.json" --ApiKey "your-nuget-api-key"
NativeAssetsDirectory 原生文件目录,放置构建完成的 native 项目产物ProjectsRoot nuget项目目录Source 打包发布的目标源ApiKey 目标源的密钥 注意密钥安全构建脚本 Program.cs