From a9e87c74bb37b5eb5cde4a7fe1e11f6d1b53f386 Mon Sep 17 00:00:00 2001 From: starmen1265 Date: Wed, 12 Feb 2025 00:13:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0tickactor,=E6=B2=A1=E6=88=90?= =?UTF-8?q?=E5=8A=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Content/JavaScript/entry.js | 35 +++++++++++++++++++ Content/JavaScript/entry.js.map | 2 +- Source/MingSimulator/UI/TSUserWidget.cpp | 14 ++++++++ Source/MingSimulator/UI/TSUserWidget.h | 20 +++++++++++ TypeScript/entry.ts | 44 +++++++++++++++++++++++- ts_file_versions_info.json | 38 ++++++++++---------- 6 files changed, 132 insertions(+), 21 deletions(-) create mode 100644 Source/MingSimulator/UI/TSUserWidget.cpp create mode 100644 Source/MingSimulator/UI/TSUserWidget.h diff --git a/Content/JavaScript/entry.js b/Content/JavaScript/entry.js index 7e74314..bd7fe4c 100644 --- a/Content/JavaScript/entry.js +++ b/Content/JavaScript/entry.js @@ -1,4 +1,39 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +const UE = require("ue"); +const puerts_1 = require("puerts"); +// 创建一个用于Tick的Actor +class TSTickActor extends UE.Actor { + constructor() { + super(...arguments); + this.lastPrintTime = 0; + } + ReceiveTick(DeltaSeconds) { + super.ReceiveTick(DeltaSeconds); + // 每秒打印一次 + this.lastPrintTime += DeltaSeconds; + if (this.lastPrintTime >= 1.0) { + console.log('Tick: ' + this.lastPrintTime.toFixed(2)); + this.lastPrintTime = 0; + } + } + // 确保Actor可以Tick + ReceiveBeginPlay() { + super.ReceiveBeginPlay(); + this.PrimaryActorTick.bCanEverTick = true; + } +} console.log('--------------------------entry.ts started2----------------------'); +// 获取游戏实例和世界 +let gameInstance = puerts_1.argv.getByName("GameInstance"); +let world = gameInstance.GetWorld(); +// 在场景中生成TSTickActor +let spawnLocation = new UE.Vector(0, 0, 100); // 在高度100的位置生成,避免卡在地面 +let spawnRotation = new UE.Rotator(0, 0, 0); +let spawnTransform = new UE.Transform(); +spawnTransform.SetLocation(spawnLocation); +spawnTransform.SetRotation(spawnRotation.Quaternion()); +let tickActor = UE.GameplayStatics.BeginDeferredActorSpawnFromClass(world, TSTickActor.StaticClass(), spawnTransform); +UE.GameplayStatics.FinishSpawningActor(tickActor, spawnTransform); +console.log('--------------------------TSTickActor spawned----------------------'); //# sourceMappingURL=entry.js.map \ No newline at end of file diff --git a/Content/JavaScript/entry.js.map b/Content/JavaScript/entry.js.map index c7a506a..92d8a63 100644 --- a/Content/JavaScript/entry.js.map +++ b/Content/JavaScript/entry.js.map @@ -1 +1 @@ -{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../TypeScript/entry.ts"],"names":[],"mappings":";;AAGA,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAA"} \ No newline at end of file +{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../TypeScript/entry.ts"],"names":[],"mappings":";;AAAA,yBAAwB;AACxB,mCAAuC;AAEvC,mBAAmB;AACnB,MAAM,WAAY,SAAQ,EAAE,CAAC,KAAK;IAAlC;;QACY,kBAAa,GAAW,CAAC,CAAC;IAkBtC,CAAC;IAhBG,WAAW,CAAC,YAAoB;QAC5B,KAAK,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;QAEhC,SAAS;QACT,IAAI,CAAC,aAAa,IAAI,YAAY,CAAC;QACnC,IAAI,IAAI,CAAC,aAAa,IAAI,GAAG,EAAE;YAC3B,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;SAC1B;IACL,CAAC;IAED,gBAAgB;IAChB,gBAAgB;QACZ,KAAK,CAAC,gBAAgB,EAAE,CAAC;QACzB,IAAI,CAAC,gBAAgB,CAAC,YAAY,GAAG,IAAI,CAAC;IAC9C,CAAC;CACJ;AAED,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAA;AAEhF,YAAY;AACZ,IAAI,YAAY,GAAI,aAAI,CAAC,SAAS,CAAC,cAAc,CAAqB,CAAA;AACtE,IAAI,KAAK,GAAG,YAAY,CAAC,QAAQ,EAAE,CAAC;AAEpC,oBAAoB;AACpB,IAAI,aAAa,GAAG,IAAI,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,qBAAqB;AACnE,IAAI,aAAa,GAAG,IAAI,EAAE,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC5C,IAAI,cAAc,GAAG,IAAI,EAAE,CAAC,SAAS,EAAE,CAAC;AACxC,cAAc,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;AAC1C,cAAc,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,EAAE,CAAC,CAAC;AAEvD,IAAI,SAAS,GAAG,EAAE,CAAC,eAAe,CAAC,gCAAgC,CAC/D,KAAK,EACL,WAAW,CAAC,WAAW,EAAE,EACzB,cAAc,CACF,CAAC;AACjB,EAAE,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;AAElE,OAAO,CAAC,GAAG,CAAC,qEAAqE,CAAC,CAAA"} \ No newline at end of file diff --git a/Source/MingSimulator/UI/TSUserWidget.cpp b/Source/MingSimulator/UI/TSUserWidget.cpp new file mode 100644 index 0000000..a0f5052 --- /dev/null +++ b/Source/MingSimulator/UI/TSUserWidget.cpp @@ -0,0 +1,14 @@ +#include "TSUserWidget.h" + +void UTSUserWidget::SetTypeScriptTickFunction(FString FunctionName) +{ + TSTickFunctionName = FunctionName; +} + +void UTSUserWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) +{ + Super::NativeTick(MyGeometry, InDeltaTime); + + // 这里可以调用TypeScript中注册的Tick函数 + // 具体实现方式需要根据您的Puerts配置来调用 +} \ No newline at end of file diff --git a/Source/MingSimulator/UI/TSUserWidget.h b/Source/MingSimulator/UI/TSUserWidget.h new file mode 100644 index 0000000..5448e23 --- /dev/null +++ b/Source/MingSimulator/UI/TSUserWidget.h @@ -0,0 +1,20 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include "TSUserWidget.generated.h" + +UCLASS() +class MINGSIMULATOR_API UTSUserWidget : public UUserWidget +{ + GENERATED_BODY() + +public: + UFUNCTION(BlueprintCallable, Category = "TypeScript") + void SetTypeScriptTickFunction(FString FunctionName); + + virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; + +private: + FString TSTickFunctionName; +}; \ No newline at end of file diff --git a/TypeScript/entry.ts b/TypeScript/entry.ts index 19c9d76..54c143d 100644 --- a/TypeScript/entry.ts +++ b/TypeScript/entry.ts @@ -1,4 +1,46 @@ import * as UE from 'ue' import {argv, blueprint} from 'puerts'; -console.log('--------------------------entry.ts started2----------------------') \ No newline at end of file +// 创建一个用于Tick的Actor +class TSTickActor extends UE.Actor { + private lastPrintTime: number = 0; + + ReceiveTick(DeltaSeconds: number): void { + super.ReceiveTick(DeltaSeconds); + + // 每秒打印一次 + this.lastPrintTime += DeltaSeconds; + if (this.lastPrintTime >= 1.0) { + console.log('Tick: ' + this.lastPrintTime.toFixed(2)); + this.lastPrintTime = 0; + } + } + + // 确保Actor可以Tick + ReceiveBeginPlay(): void { + super.ReceiveBeginPlay(); + this.PrimaryActorTick.bCanEverTick = true; + } +} + +console.log('--------------------------entry.ts started2----------------------') + +// 获取游戏实例和世界 +let gameInstance = (argv.getByName("GameInstance") as UE.GameInstance) +let world = gameInstance.GetWorld(); + +// 在场景中生成TSTickActor +let spawnLocation = new UE.Vector(0, 0, 100); // 在高度100的位置生成,避免卡在地面 +let spawnRotation = new UE.Rotator(0, 0, 0); +let spawnTransform = new UE.Transform(); +spawnTransform.SetLocation(spawnLocation); +spawnTransform.SetRotation(spawnRotation.Quaternion()); + +let tickActor = UE.GameplayStatics.BeginDeferredActorSpawnFromClass( + world, + TSTickActor.StaticClass(), + spawnTransform +) as TSTickActor; +UE.GameplayStatics.FinishSpawningActor(tickActor, spawnTransform); + +console.log('--------------------------TSTickActor spawned----------------------') \ No newline at end of file diff --git a/ts_file_versions_info.json b/ts_file_versions_info.json index 67a01d8..d0c5ae4 100644 --- a/ts_file_versions_info.json +++ b/ts_file_versions_info.json @@ -1,9 +1,13 @@ { "D:/MiceCola/Projects/AncientCivil/TypeScript/entry.ts": { - "version": "fdcb7aa1d16b12d6171a4020b7624560", + "version": "b1cd767eea65f4ecc585ee93cd754dda", "processed": true, "isBP": false }, + "D:/MiceCola/Projects/AncientCivil/Typing/cpp/index.d.ts": { + "version": "dd956b7a3c07de56359cbfa4bee0cf05", + "processed": false + }, "D:/MiceCola/Projects/AncientCivil/Typing/ffi/index.d.ts": { "version": "a371a5609d4ee418c7557ae5aa47afae", "processed": false @@ -12,6 +16,14 @@ "version": "d50bfedc76d792b10b1643a43a4ffd6b", "processed": false }, + "D:/MiceCola/Projects/AncientCivil/Typing/react-umg/index.d.ts": { + "version": "646f0cb810568f8eab5ba1f09cc88037", + "processed": false + }, + "D:/MiceCola/Projects/AncientCivil/node_modules/@types/react/index.d.ts": { + "version": "a6386c71ac7ef6d48c8d05574cce1c20", + "processed": false + }, "D:/MiceCola/Projects/AncientCivil/Typing/ue/index.d.ts": { "version": "b982801b3faba925e1d56c2d2cebd82a", "processed": false @@ -20,12 +32,16 @@ "version": "b35c41fa7a5a7a2cde1b14a2577628f7", "processed": false }, + "D:/MiceCola/Projects/AncientCivil/Typing/ue/ue.d.ts": { + "version": "ec461a2d572a9672fb5da0a67b629ca9", + "processed": false + }, "D:/MiceCola/Projects/AncientCivil/Typing/ue/puerts_decorators.d.ts": { "version": "11c14fe8093e3773ebdc2c6b8a509977", "processed": false }, - "D:/MiceCola/Projects/AncientCivil/node_modules/@types/react/index.d.ts": { - "version": "a6386c71ac7ef6d48c8d05574cce1c20", + "D:/MiceCola/Projects/AncientCivil/Typing/ue/ue_bp.d.ts": { + "version": "8a4adfd291c2689f547a023a91753059", "processed": false }, "D:/MiceCola/Projects/AncientCivil/node_modules/@types/react-reconciler/index.d.ts": { @@ -259,21 +275,5 @@ "D:/MiceCola/Projects/AncientCivil/Content/JavaScript/PuertsEditor/node_modules/typescript/lib/lib.dom.iterable.d.ts": { "version": "977f6792324dbfc2fcc8eadc6f1b0452", "processed": false - }, - "D:/MiceCola/Projects/AncientCivil/Typing/cpp/index.d.ts": { - "version": "dd956b7a3c07de56359cbfa4bee0cf05", - "processed": false - }, - "D:/MiceCola/Projects/AncientCivil/Typing/react-umg/index.d.ts": { - "version": "646f0cb810568f8eab5ba1f09cc88037", - "processed": false - }, - "D:/MiceCola/Projects/AncientCivil/Typing/ue/ue.d.ts": { - "version": "ec461a2d572a9672fb5da0a67b629ca9", - "processed": false - }, - "D:/MiceCola/Projects/AncientCivil/Typing/ue/ue_bp.d.ts": { - "version": "8a4adfd291c2689f547a023a91753059", - "processed": false } } \ No newline at end of file