feat(app): WASDMove script (WASD camera-relative movement)
ScriptBehavior gains App() host access (Application injected via ScriptRuntime), TryGet<T> and EntityBits for physics facade addressing. WASDMove maps WASD to the editor camera's horizontal heading (UE gameplay convention): dynamic bodies go through the physics velocity facade preserving the vertical component (zeroing Y would cancel gravity mid-fall), bodiless entities translate their transform directly. Editor-mode key conflict is naturally avoided: RMB-held flight consumes WASD, release hands keys to the script.
This commit is contained in:
@@ -103,8 +103,9 @@ namespace Engine {
|
||||
// 物理调试图元 → 渲染侧(PhysicsDebugPass 每帧上传绘制)
|
||||
m_Renderer->SetPhysicsDebugSource(&m_Physics->GetDebugFrame());
|
||||
|
||||
// 脚本生命周期(对账式,组件增删/改名即时生效)
|
||||
m_Scripts = CreateScope<Scripting::ScriptRuntime>(*m_Scene);
|
||||
// 脚本生命周期(对账式,组件增删/改名即时生效);this 注入脚本
|
||||
// 上下文(Window/Renderer/Physics 门面)
|
||||
m_Scripts = CreateScope<Scripting::ScriptRuntime>(*m_Scene, this);
|
||||
|
||||
while (m_Running) {
|
||||
const auto frameStart = std::chrono::steady_clock::now();
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
namespace Engine {
|
||||
namespace Scripting {
|
||||
|
||||
// 宿主门面访问器:Application 完整类型只在脚本 cpp 里需要,
|
||||
// 这里仅回引成员(避免引擎头循环依赖)
|
||||
Application& ScriptBehavior::App() const {
|
||||
return *m_App;
|
||||
}
|
||||
|
||||
void ScriptRuntime::Update(f32 dt) {
|
||||
Sync();
|
||||
|
||||
@@ -61,7 +67,7 @@ namespace Engine {
|
||||
sc.scriptName, bits);
|
||||
continue;
|
||||
}
|
||||
behavior->Bind(m_Scene, e);
|
||||
behavior->Bind(m_Scene, e, m_App);
|
||||
|
||||
ScriptInstance inst;
|
||||
inst.behavior = std::move(behavior);
|
||||
|
||||
Reference in New Issue
Block a user