|
8 | 8 | #include "System.h" |
9 | 9 | #include "Engine.h" |
10 | 10 | #include "Scene.h" |
| 11 | +#include "SceneManager.h" |
11 | 12 | #include "component/ScriptComponent.h" |
12 | 13 | #include "ScriptProperty.h" |
13 | 14 | #include "object/EntityHandle.h" |
@@ -569,36 +570,42 @@ void LuaBinding::initializeLuaScripts(Scene* scene) { |
569 | 570 | bool foundScript = false; |
570 | 571 |
|
571 | 572 | if (targetEntity != NULL_ENTITY) { |
572 | | - ScriptComponent* targetScriptComp = scene->findComponent<ScriptComponent>(targetEntity); |
573 | | - if (targetScriptComp) { |
574 | | - if (!prop.ptrTypeName.empty()) { |
575 | | - for (auto& targetScript : targetScriptComp->scripts) { |
576 | | - if (targetScript.type == ScriptType::SCRIPT_LUA && |
577 | | - targetScript.className == prop.ptrTypeName && |
578 | | - targetScript.enabled && targetScript.instance) { |
579 | | - int targetRef = static_cast<int>(reinterpret_cast<intptr_t>(targetScript.instance)); |
580 | | - lua_rawgeti(L, LUA_REGISTRYINDEX, targetRef); |
581 | | - foundScript = true; |
582 | | - break; |
| 573 | + Scene* targetScene = scene; |
| 574 | + if (prop.sceneId != 0) { |
| 575 | + targetScene = SceneManager::getScenePtr(prop.sceneId); |
| 576 | + } |
| 577 | + if (targetScene) { |
| 578 | + ScriptComponent* targetScriptComp = targetScene->findComponent<ScriptComponent>(targetEntity); |
| 579 | + if (targetScriptComp) { |
| 580 | + if (!prop.ptrTypeName.empty()) { |
| 581 | + for (auto& targetScript : targetScriptComp->scripts) { |
| 582 | + if (targetScript.type == ScriptType::SCRIPT_LUA && |
| 583 | + targetScript.className == prop.ptrTypeName && |
| 584 | + targetScript.enabled && targetScript.instance) { |
| 585 | + int targetRef = static_cast<int>(reinterpret_cast<intptr_t>(targetScript.instance)); |
| 586 | + lua_rawgeti(L, LUA_REGISTRYINDEX, targetRef); |
| 587 | + foundScript = true; |
| 588 | + break; |
| 589 | + } |
583 | 590 | } |
584 | | - } |
585 | | - if (!foundScript) |
586 | | - foundScript = pushEntityHandleByType(L, scene, targetEntity, prop.ptrTypeName); |
587 | | - } else { |
588 | | - for (auto& targetScript : targetScriptComp->scripts) { |
589 | | - if (targetScript.type == ScriptType::SCRIPT_LUA && |
590 | | - targetScript.enabled && targetScript.instance) { |
591 | | - int targetRef = static_cast<int>(reinterpret_cast<intptr_t>(targetScript.instance)); |
592 | | - lua_rawgeti(L, LUA_REGISTRYINDEX, targetRef); |
593 | | - foundScript = true; |
594 | | - break; |
| 591 | + if (!foundScript) |
| 592 | + foundScript = pushEntityHandleByType(L, targetScene, targetEntity, prop.ptrTypeName); |
| 593 | + } else { |
| 594 | + for (auto& targetScript : targetScriptComp->scripts) { |
| 595 | + if (targetScript.type == ScriptType::SCRIPT_LUA && |
| 596 | + targetScript.enabled && targetScript.instance) { |
| 597 | + int targetRef = static_cast<int>(reinterpret_cast<intptr_t>(targetScript.instance)); |
| 598 | + lua_rawgeti(L, LUA_REGISTRYINDEX, targetRef); |
| 599 | + foundScript = true; |
| 600 | + break; |
| 601 | + } |
595 | 602 | } |
| 603 | + if (!foundScript) |
| 604 | + foundScript = pushEntityHandleByType(L, targetScene, targetEntity, prop.ptrTypeName); |
596 | 605 | } |
597 | | - if (!foundScript) |
598 | | - foundScript = pushEntityHandleByType(L, scene, targetEntity, prop.ptrTypeName); |
| 606 | + } else { |
| 607 | + foundScript = pushEntityHandleByType(L, targetScene, targetEntity, prop.ptrTypeName); |
599 | 608 | } |
600 | | - } else { |
601 | | - foundScript = pushEntityHandleByType(L, scene, targetEntity, prop.ptrTypeName); |
602 | 609 | } |
603 | 610 | } |
604 | 611 |
|
|
0 commit comments