Awake(), Start() and Update(), OnDestroy() for scripts now all run as intended
This commit is contained in:
parent
3a908b717b
commit
1bede86ff6
|
@ -38,18 +38,19 @@ namespace Sandbox
|
|||
auto matInst = graphicsSystem->AddMaterialInstance();
|
||||
|
||||
// Create entity and add mesh
|
||||
auto entity = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable>();
|
||||
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(entity);
|
||||
testObj = SHADE::SHEntityManager::CreateEntity<SHADE::SHRenderable>();
|
||||
auto& renderable = *SHADE::SHComponentManager::GetComponent_s<SHADE::SHRenderable>(testObj);
|
||||
renderable.Mesh = CUBE_MESH;
|
||||
renderable.SetMaterial(matInst);
|
||||
renderable.TransformMatrix.Translate(0.0f, 0.0f, 2.0f);
|
||||
SHADE::SHScriptEngine* scriptEngine = static_cast<SHADE::SHScriptEngine*>(SHADE::SHSystemManager::GetSystem<SHADE::SHScriptEngine>());
|
||||
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(entity), "TestScript");
|
||||
scriptEngine->AddScript(*SHADE::SHEntityManager::GetEntityByID(testObj), "TestScript");
|
||||
}
|
||||
void SBTestScene::Update(float dt)
|
||||
{
|
||||
(void)dt;
|
||||
|
||||
if (GetKeyState(VK_SPACE) & 0x8000)
|
||||
SHADE::SHEntityManager::DestroyEntity(testObj);
|
||||
}
|
||||
|
||||
void SBTestScene::Render()
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Sandbox
|
|||
{
|
||||
private:
|
||||
EntityID camera;
|
||||
EntityID testObj;
|
||||
|
||||
|
||||
public:
|
||||
|
|
|
@ -288,13 +288,6 @@ namespace SHADE
|
|||
void ScriptStore::RemoveAllScripts(Entity entity)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
// Check if entity exists
|
||||
if (!EntityUtils::IsValid(entity))
|
||||
{
|
||||
Debug::LogError("[ScriptStore] Attempted to remove Scripts from an invalid Entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
return;
|
||||
|
@ -311,13 +304,6 @@ namespace SHADE
|
|||
void ScriptStore::RemoveAllScriptsImmediately(Entity entity, bool callOnDestroy)
|
||||
{
|
||||
SAFE_NATIVE_CALL_BEGIN
|
||||
// Check if entity exists
|
||||
if (!EntityUtils::IsValid(entity))
|
||||
{
|
||||
Debug::LogError("[ScriptStore] Attempted to remove Scripts from an invalid Entity!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
return;
|
||||
|
@ -386,10 +372,7 @@ namespace SHADE
|
|||
while (disposalQueue.Count > 0)
|
||||
{
|
||||
Script^ script = disposalQueue.Dequeue();
|
||||
/*if (Application::IsPlaying)
|
||||
{
|
||||
script->OnDestroy();
|
||||
}*/
|
||||
auto entity = script->Owner.GetEntity();
|
||||
auto scriptList = scripts[script->Owner.GetEntity()];
|
||||
scriptList->Remove(script);
|
||||
|
@ -497,7 +480,6 @@ namespace SHADE
|
|||
if (!EntityUtils::IsValid(entity))
|
||||
return true;
|
||||
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
return true;
|
||||
|
@ -667,7 +649,7 @@ namespace SHADE
|
|||
|
||||
// Entity Validity Check
|
||||
if (nativeEntity == nullptr)
|
||||
throw gcnew System::InvalidOperationException("Attempted to get native Component to an invalid Entity.");
|
||||
return false;
|
||||
|
||||
// Check active state
|
||||
return nativeEntity->GetActive();
|
||||
|
|
Loading…
Reference in New Issue