Skip to content

Commit 8995a1c

Browse files
authored
Merge pull request #8 from NoTaskStudios/feature/unity-editor-commands
Feature/unity editor commands
2 parents c765e34 + 3c76237 commit 8995a1c

File tree

7 files changed

+777
-38
lines changed

7 files changed

+777
-38
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ eslint.config.js
2929
# Build Packing
3030
dist-tar/
3131
*.zip
32+
*.tar

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"url": "https://github.com/NoTaskStudios/unity-cli-tools.git"
2222
},
2323
"scripts": {
24-
"clean": "rimraf dist dist-cjs",
24+
"clean": "rimraf dist",
2525
"build": "npm run clean && npm run build:esm && npm run build:cjs",
2626
"build:esm": "tsc --project tsconfig.json",
2727
"build:cjs": "tsc --project tsconfig.cjs.json && node scripts/write-cjs-package.cjs",
@@ -66,4 +66,4 @@
6666
"typescript": "^5.8.3",
6767
"typescript-eslint": "8.30.1"
6868
}
69-
}
69+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export { default as UnityHub } from "./unityHub.ts";
2+
export { default as UnityEditor } from "./unityEditor.ts";
23

34
export * from "./types/unity.ts";

src/types/unity.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export enum UnityModules {
4040
UWPBuildSupportDotNet = "uwp-.net",
4141
}
4242

43-
export enum UnityLanguages {
43+
export enum UnityEditorLanguages {
4444
Japanese = "language-ja",
4545
Korean = "language-ko",
4646
ChineseSimplified = "language-zh-hans",
@@ -53,23 +53,17 @@ export enum EditorArchitecture {
5353
arm64 = "arm64",
5454
}
5555

56-
export type ModuleId = UnityModules | UnityLanguages;
56+
export type ModuleId = UnityModules | UnityEditorLanguages;
5757
export type UnityInstallations = Record<string, string>;
5858

5959
//EDITOR
6060
export interface ProjectInfo {
61-
path: string;
62-
editorVersion: string;
6361
projectName: string;
62+
projectPath: string;
63+
editorVersion: string;
6464
scenes?: string[];
6565
}
6666

67-
export interface ProjectSettings {
68-
companyName?: string;
69-
productName?: string;
70-
bundleVersion?: string;
71-
}
72-
7367
// Ref https://docs.unity3d.com/Packages/com.unity.test-framework@1.4/manual/reference-command-line.html#testplatform
7468
export enum TestMode {
7569
EditMode = "editmode",
@@ -94,21 +88,3 @@ export enum UnityBuildTarget {
9488
PS5 = "PS5",
9589
VisionOS = "VisionOS",
9690
}
97-
98-
/**
99-
* Represents a parsed Unity version
100-
*/
101-
export interface ParsedVersion {
102-
/** Major version number (e.g. 2022) */
103-
major: number;
104-
/** Minor version number (e.g. 3) */
105-
minor: number;
106-
/** Patch version number (e.g. 60) */
107-
patch: number;
108-
/** Release type: 'a' (alpha), 'b' (beta), 'f' (final) */
109-
type: string;
110-
/** Revision number (e.g. 1) */
111-
revision: number;
112-
/** Original version string */
113-
original: string;
114-
}

0 commit comments

Comments
 (0)