diff --git a/src/editor/engine/GameRuntime.js b/src/editor/engine/GameRuntime.js index 71d8985..9a24221 100644 --- a/src/editor/engine/GameRuntime.js +++ b/src/editor/engine/GameRuntime.js @@ -1606,6 +1606,17 @@ export class GameRuntime { routeEvent(target, eventType, extra = {}) { if (!target || !eventType) return; for (const sb of this.sandboxes) { + // LuaSharedSandbox = один sandbox на все Lua-скрипты, target=null. + // Шлём ему ВСЕ события — shim сам найдёт соответствующий Part + // через partById и сфейерит Touched на нужной части. + if (sb.constructor?.name === 'LuaSharedSandbox' || sb._luaShared) { + const kind = eventType === 'touch' ? 'touched' + : eventType === 'untouch' ? 'untouched' + : eventType; + const primId = target.id ?? target.ref ?? null; + sb.sendEvent({ kind, primId, target, ...extra }); + continue; + } if (!sb.target) continue; if (!this._targetMatches(sb.target, target)) continue; sb.sendEvent({ type: eventType, ...extra }); diff --git a/src/editor/engine/lua/LuaSharedSandbox.js b/src/editor/engine/lua/LuaSharedSandbox.js index c06a72d..466a257 100644 --- a/src/editor/engine/lua/LuaSharedSandbox.js +++ b/src/editor/engine/lua/LuaSharedSandbox.js @@ -36,6 +36,9 @@ export class LuaSharedSandbox { this._guiTree = null; this._loopHandle = null; this._lastTickAt = 0; + // Маркер для GameRuntime.routeEvent — этот sandbox принимает все + // события и сам маршрутизирует через shim.fireTargetEvent. + this._luaShared = true; } setOnCommand(cb) { this._onCommand = cb; }