Skip to content

Commit 3c76237

Browse files
committed
docs(Editor): Add documentation about UnityEditor
1 parent 504d4b6 commit 3c76237

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

README.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,107 @@ const result = await UnityHub.execUnityHubCommand(["editors", "-r"]);
8888
console.log(result.stdout);
8989
```
9090

91+
## UnityEditor API Reference
92+
93+
UnityEditor provides an interface for automating tasks directly in the Unity Editor:
94+
95+
### Installation and Availability
96+
```typescript
97+
import UnityEditor from "@notask/unity-cli-tools";
98+
99+
// Get the executable path and verify installation
100+
const unityPath = UnityEditor.getUnityExecutablePath("2022.3.15f1");
101+
const isInstalled = await UnityEditor.isUnityVersionInstalled("2022.3.15f1");
102+
console.log(`Installed: ${isInstalled}`, unityPath);
103+
```
104+
105+
### Executing Raw Editor Commands
106+
```typescript
107+
import { CommandResult } from "@notask/unity-cli-tools";
108+
109+
const editorInfo = { version: "2022.3.15f1", path: unityPath };
110+
const result: CommandResult = await UnityEditor.execUnityEditorCommand(
111+
editorInfo,
112+
["-batchmode", "-quit", "-projectPath", "/path/to/project"]
113+
);
114+
console.log(result.stdout);
115+
```
116+
117+
### Creating and Opening Projects
118+
```typescript
119+
import { ProjectInfo } from "@notask/unity-cli-tools";
120+
121+
const projectInfo: ProjectInfo = {
122+
projectPath: "/path/to/new/project",
123+
editorVersion: "2022.3.15f1"
124+
};
125+
126+
await UnityEditor.createProject(projectInfo);
127+
await UnityEditor.openProject(projectInfo, true, true);
128+
```
129+
130+
### Running Tests
131+
```typescript
132+
import { ProjectInfo, TestMode } from "@notask/unity-cli-tools";
133+
134+
const projectInfo: ProjectInfo = {
135+
projectPath: "/path/to/project",
136+
editorVersion: "2022.3.15f1"
137+
};
138+
139+
const { success, output } = await UnityEditor.runTests(projectInfo, TestMode.EditMode);
140+
console.log(success ? "Tests passed" : "Tests failed", output);
141+
```
142+
143+
### License Management
144+
```typescript
145+
import { ProjectInfo } from "@notask/unity-cli-tools";
146+
147+
const projectInfo: ProjectInfo = {
148+
projectPath: "/path/to/project",
149+
editorVersion: "2022.3.15f1"
150+
};
151+
152+
await UnityEditor.activateLicense(projectInfo, "XXXX-XXXX-XXXX-XXXX-XXXX", "user@example.com", "password");
153+
await UnityEditor.returnLicense(projectInfo);
154+
```
155+
156+
### Importing and Exporting Packages
157+
```typescript
158+
import { ProjectInfo } from "@notask/unity-cli-tools";
159+
160+
const projectInfo: ProjectInfo = {
161+
projectPath: "/path/to/project",
162+
editorVersion: "2022.3.15f1"
163+
};
164+
165+
await UnityEditor.exportPackage(
166+
projectInfo,
167+
["Assets/UI", "Assets/Scripts"],
168+
"/path/to/output/MyPackage.unitypackage"
169+
);
170+
await UnityEditor.importPackage(
171+
projectInfo,
172+
"/path/to/downloads/OtherPackage.unitypackage"
173+
);
174+
```
175+
176+
### Executing Custom Editor Methods
177+
```typescript
178+
import { ProjectInfo } from "@notask/unity-cli-tools";
179+
180+
const projectInfo: ProjectInfo = {
181+
projectPath: "/path/to/project",
182+
editorVersion: "2022.3.15f1"
183+
};
184+
185+
const executionResult = await UnityEditor.executeMethod(
186+
projectInfo,
187+
"MyCompany.BuildTools.PerformBuild"
188+
);
189+
console.log(executionResult);
190+
```
191+
91192
## Available Constants
92193

93194
### UnityModules

0 commit comments

Comments
 (0)