diff --git a/.gitignore b/.gitignore index 6ec3df2..a69d699 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /node_modules/ -/Gen/ +/Gen diff --git a/rspack.config.ts b/rspack.config.ts index a9829b3..d065315 100644 --- a/rspack.config.ts +++ b/rspack.config.ts @@ -12,6 +12,7 @@ export default defineConfig({ unityengine: "CS.UnityEngine", "unityengine/ui": "CS.UnityEngine.UI", "system": "CS.System", + "tmpro": "CS.TMPro", }, output: { path: resolve(__dirname, "Gen/Resources"), diff --git a/src/index.ts b/src/index.ts index 43eddc3..5b2b72a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,9 @@ -console.log("bler"); +import { Debug, Transform } from "unityengine"; +import { getPrefabChild, getPrefabComponent, loadPrefab } from "./loader"; +async function main() { + const control = await loadPrefab("Control"); + const child = getPrefabChild(control, ""); + const tr = getPrefabComponent(control, "a", Transform); + Debug.Log(tr.localScale); +} +main(); diff --git a/src/loader.ts b/src/loader.ts new file mode 100644 index 0000000..d36f3ca --- /dev/null +++ b/src/loader.ts @@ -0,0 +1,53 @@ +import { $typeof } from "puerts"; +import { Awaitable, GameObject, Resources } from "unityengine"; +export async function loadPrefab
(path: P) {
+ return await loadResource(path) as GameObject & { PREFAB_KEY: P };
+}
+export async function loadResource(path: string) {
+ const req = Resources.LoadAsync(path);
+ await asPromise(req);
+ return req.asset;
+}
+export function asPromise(awaiter: { GetAwaiter(): Awaitable.Awaiter }) {
+ return new Promise ,
+>(p: GameObject & { PREFAB_KEY: P }, c: C) {
+ return c === "" ? p : p.transform.Find(c).gameObject as GameObject & {
+ PREFAB_KEY: P;
+ CHILD_KEY: C;
+ };
+}
+export function getPrefabComponent<
+ P extends PrefabKeys,
+ C extends PrefabChildKeys ,
+ B extends PrefabComponent >,
+>(
+ p: GameObject & { PREFAB_KEY: P },
+ c: C,
+ b: Constructor,
+) {
+ const go = c === "" ? p : p.transform.Find(c).gameObject;
+ return go.GetComponent($typeof(b)) as B;
+}
diff --git a/src/types/modules.d.ts b/src/types/modules.d.ts
index ae2b12d..237487e 100644
--- a/src/types/modules.d.ts
+++ b/src/types/modules.d.ts
@@ -7,3 +7,6 @@ declare module "unityengine/ui" {
declare module "system" {
export = CS.System;
}
+declare module "tmpro" {
+ export = CS.TMPro;
+}
diff --git a/src/types/puer.d.ts b/src/types/puer.d.ts
new file mode 100644
index 0000000..6c3c09c
--- /dev/null
+++ b/src/types/puer.d.ts
@@ -0,0 +1,47 @@
+declare enum __Puerts_CSharpEnum { }
+
+declare namespace puer {
+ function $ref