Added proper implementation of IsActiveInHierarchy()

This commit is contained in:
Kah Wei 2022-10-31 16:29:29 +08:00
parent f91b1f00ad
commit 2ffba202f7
3 changed files with 22 additions and 8 deletions

View File

@ -21,6 +21,7 @@ of DigiPen Institute of Technology is prohibited.
#include "ECS.hxx" #include "ECS.hxx"
#include "Utility/Convert.hxx" #include "Utility/Convert.hxx"
#include "Scripts/ScriptStore.hxx" #include "Scripts/ScriptStore.hxx"
#include "Utility/Debug.hxx"
namespace SHADE namespace SHADE
{ {
@ -63,7 +64,13 @@ namespace SHADE
} }
bool GameObject::IsActiveInHierarchy::get() bool GameObject::IsActiveInHierarchy::get()
{ {
return true; // TODO: Update once we have an equivalent on the Entity object auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(GetEntity());
if (!node)
{
Debug::LogWarning("Attempting to access a GameObject's ActiveInHierarchy state which does not exist. Assuming inactive.");
return false;
}
return node->IsActive();
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -667,14 +667,10 @@ namespace SHADE
bool ScriptStore::isEntityActive(Entity entity) bool ScriptStore::isEntityActive(Entity entity)
{ {
// Get native Entity // Invalid entity
SHEntity* nativeEntity = SHEntityManager::GetEntityByID(entity); if (!EntityUtils::IsValid(entity))
// Entity Validity Check
if (nativeEntity == nullptr)
return false; return false;
// Check active state return GameObject(entity).IsActiveInHierarchy;
return nativeEntity->GetActive();
} }
} }

View File

@ -0,0 +1,11 @@
using SHADE;
public class PrintWhenActive : Script
{
public PrintWhenActive(GameObject gameObj) : base(gameObj) { }
protected override void update()
{
Debug.Log("Active!");
}
}