OpenSesameCompilerForUnity 使用教程
1. 项目的目录结构及介绍
OpenSesameCompilerForUnity 项目的目录结构如下:
OpenSesameCompilerForUnity/
├── Assets/
│ ├── Editor/
│ │ ├── OpenSesameCompiler/
│ │ │ ├── Editor/
│ │ │ │ ├── OpenSesameCompilerSettings.cs
│ │ │ │ └── ...
│ │ │ ├── OpenSesameCompiler.asmdef
│ │ │ └── ...
│ │ └── ...
│ ├── Tests/
│ │ ├── CoffeeOpenSesameTest/
│ │ │ ├── CoffeeOpenSesameTest.asmdef
│ │ │ └── ...
│ │ └── ...
│ └── ...
├── CHANGELOG.md
├── LICENSE
├── README.md
└── ...
目录介绍
- Assets/: Unity 项目的主要目录,包含所有资源和代码。
- Editor/: 包含编辑器扩展代码,用于在 Unity 编辑器中配置和使用 OpenSesameCompiler。
- OpenSesameCompiler/: OpenSesameCompiler 的核心代码目录。
- Editor/: 包含编辑器扩展的具体实现。
- OpenSesameCompilerSettings.cs: 配置 OpenSesameCompiler 的主要文件。
- OpenSesameCompiler.asmdef: 定义 OpenSesameCompiler 的程序集。
- Editor/: 包含编辑器扩展的具体实现。
- OpenSesameCompiler/: OpenSesameCompiler 的核心代码目录。
- Tests/: 包含测试代码。
- CoffeeOpenSesameTest/: 示例测试项目。
- CoffeeOpenSesameTest.asmdef: 定义测试程序集。
- CoffeeOpenSesameTest/: 示例测试项目。
- Editor/: 包含编辑器扩展代码,用于在 Unity 编辑器中配置和使用 OpenSesameCompiler。
- CHANGELOG.md: 项目更新日志。
- LICENSE: 项目许可证(MIT)。
- README.md: 项目介绍和使用说明。
2. 项目的启动文件介绍
项目的启动文件主要是 OpenSesameCompilerSettings.cs
,它位于 Assets/Editor/OpenSesameCompiler/Editor/
目录下。这个文件负责配置 OpenSesameCompiler 的设置,包括是否启用 OpenSesameCompiler、添加或移除编译符号等。
启动文件介绍
// OpenSesameCompilerSettings.cs
using UnityEditor;
using UnityEngine;
public class OpenSesameCompilerSettings : EditorWindow
{
// 配置项
private bool useOpenSesameCompiler = true;
private string modifySymbols = "";
private bool portableMode = false;
// 显示设置窗口
[MenuItem("Window/OpenSesame Compiler Settings")]
public static void ShowWindow()
{
GetWindow<OpenSesameCompilerSettings>("OpenSesame Compiler Settings");
}
private void OnGUI()
{
// 配置项的具体设置
useOpenSesameCompiler = EditorGUILayout.Toggle("Use OpenSesame Compiler", useOpenSesameCompiler);
modifySymbols = EditorGUILayout.TextField("Modify Symbols", modifySymbols);
portableMode = EditorGUILayout.Toggle("Portable Mode", portableMode);
}
}
3. 项目的配置文件介绍
项目的配置文件主要是 OpenSesameCompiler.asmdef
,它位于 Assets/Editor/OpenSesameCompiler/
目录下。这个文件定义了 OpenSesameCompiler 的程序集,包括程序集名称、依赖项等。
配置文件介绍
// OpenSesameCompiler.asmdef
{
"name": "OpenSesameCompiler",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
配置项介绍
- name: 程序集名称。
- references: 依赖的程序集。
- includePlatforms: 包含的平台(这里是 Editor)。
- excludePlatforms: 排除的平台。
- allowUnsafeCode: 是否允许不安全的代码。