OpenSesameCompilerForUnity 使用教程

OpenSesameCompilerForUnity 使用教程

OpenSesameCompilerForUnityA Roslyn compiler to access internals/privates for Unity. In other words, you can access to any internals/privates in other assemblies, without reflection. Let's say, "Open sesame!"项目地址:https://gitcode.com/gh_mirrors/op/OpenSesameCompilerForUnity

1、项目介绍

OpenSesameCompilerForUnity 是一个基于 Roslyn 的自定义编译器和编辑器扩展,用于在 Unity 中访问内部和私有成员。通过这个工具,你可以在不使用反射的情况下访问其他程序集的内部和私有成员。简而言之,它允许你像说“芝麻开门”一样轻松访问这些受限的成员。

2、项目快速启动

安装

你可以通过 UPM(Unity Package Manager)或直接从 GitHub 安装 OpenSesameCompilerForUnity。

通过 UPM 安装

Packages/manifest.json 文件中添加以下依赖:

"dependencies": {
    "com.coffee.open-sesame-compiler": "https://github.com/mob-sakai/OpenSesameCompilerForUnity.git#1.0.0"
}
通过 GitHub 安装

克隆仓库到你的项目中:

git clone -b upm https://github.com/mob-sakai/OpenSesameCompilerForUnity.git

使用

  1. 在 Unity 项目视图中选择一个 AssemblyDefinitionFile
  2. 在检查器视图中配置设置:
    • 启用 Open Sesame:使用 OpenSesameCompiler 代替默认的 csc 编译器。
    • 设置修改符号:在编译时添加或移除分号分隔的符号。

示例代码:

// 启用 Open Sesame 后,可以直接访问内部或私有成员
EditorApplication.CallDelayed(() => Debug.Log("delayed"), 1);

3、应用案例和最佳实践

应用案例

假设你有一个包含内部方法的库,通常情况下,这些方法对外部是不可见的。使用 OpenSesameCompilerForUnity,你可以轻松访问这些方法。

// 假设 UnityEditor 中的 EditorApplication.CallDelayed 是内部静态方法
EditorApplication.CallDelayed(() => Debug.Log("delayed"), 1);

最佳实践

  • 谨慎使用:虽然 OpenSesameCompilerForUnity 提供了强大的功能,但应谨慎使用,避免滥用内部和私有访问权限。
  • 版本管理:确保你使用的版本是最新的,以获得最新的功能和修复。

4、典型生态项目

asmdefScriptingDefines

asmdefScriptingDefines 是一个与 OpenSesameCompilerForUnity 配合使用的工具,用于管理 Assembly Definition 文件的脚本定义。

GitHub 链接:asmdefScriptingDefines

Csc-Manager

Csc-Manager 是一个用于管理 C# 编译器的工具,可以与 OpenSesameCompilerForUnity 一起使用,提供更高级的编译器设置。

GitHub 链接:Csc-Manager

通过这些工具的配合使用,可以进一步增强 Unity 项目的开发效率和灵活性。

OpenSesameCompilerForUnityA Roslyn compiler to access internals/privates for Unity. In other words, you can access to any internals/privates in other assemblies, without reflection. Let's say, "Open sesame!"项目地址:https://gitcode.com/gh_mirrors/op/OpenSesameCompilerForUnity

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

邬千旻Herman

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值