Changed managed code's GameObject to synce with the node's active state

This commit is contained in:
Diren D Bharwani 2022-12-12 17:58:15 +08:00
parent 9b17c62b1d
commit 7820d332b1
4 changed files with 37 additions and 3 deletions

View File

@ -310,6 +310,27 @@ namespace SHADE
SHEventManager::BroadcastEvent<SHSceneGraphChangeParentEvent>(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT); SHEventManager::BroadcastEvent<SHSceneGraphChangeParentEvent>(EVENT_DATA, SH_SCENEGRAPH_CHANGE_PARENT_EVENT);
} }
void SHSceneGraph::SetActive(EntityID entityID, bool isActive) noexcept
{
////////////////////////////////////////
// Error handling
if (!SHEntityManager::IsValidEID(entityID))
{
SHLOG_ERROR("Entity {} is invalid!", entityID)
return;
}
const auto NODE_ITER = entityNodeMap.find(entityID);
if (NODE_ITER == entityNodeMap.end())
{
SHLOG_ERROR("Entity {} cannot be found in the scene!", entityID)
return;
}
////////////////////////////////////////
NODE_ITER->second->SetActive(isActive);
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Public Function Member Definitions */ /* Public Function Member Definitions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -68,6 +68,8 @@ namespace SHADE
void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept; void SetParent (EntityID entityID, SHSceneNode* newParent) noexcept;
void SetParent (EntityID entityID, EntityID newParent) noexcept; void SetParent (EntityID entityID, EntityID newParent) noexcept;
void SetActive (EntityID entityID, bool isActive) noexcept;
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Function Members */ /* Function Members */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -145,6 +145,10 @@ namespace SHADE
active = newActiveState; active = newActiveState;
isActiveInHierarchy = newActiveState; isActiveInHierarchy = newActiveState;
// Set the entity's active state
// TODO(Daniel / Diren): Sync it based on active in hierarchy or active state.
SHEntityManager::GetEntityByID(entityID)->SetActive(active);
// Recurse down the children to set the active in hierarchy state // Recurse down the children to set the active in hierarchy state
recursiveSetActiveInHierarchy(active, children); recursiveSetActiveInHierarchy(active, children);
} }

View File

@ -76,7 +76,13 @@ namespace SHADE
{ {
if (!valid) if (!valid)
throw gcnew System::NullReferenceException(); throw gcnew System::NullReferenceException();
return GetNativeEntity().GetActive(); auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(GetEntity());
if (!node)
{
Debug::LogWarning("Attempting to access a GameObject's Active state which does not exist. Assuming inactive.");
return false;
}
return node->IsActive();
} }
bool GameObject::IsActiveInHierarchy::get() bool GameObject::IsActiveInHierarchy::get()
{ {
@ -88,7 +94,7 @@ namespace SHADE
Debug::LogWarning("Attempting to access a GameObject's ActiveInHierarchy state which does not exist. Assuming inactive."); Debug::LogWarning("Attempting to access a GameObject's ActiveInHierarchy state which does not exist. Assuming inactive.");
return false; return false;
} }
return node->IsActive(); return node->IsActiveInHierarchy();
} }
Entity GameObject::EntityId::get() Entity GameObject::EntityId::get()
{ {
@ -148,7 +154,8 @@ namespace SHADE
{ {
if (!valid) if (!valid)
throw gcnew System::NullReferenceException(); throw gcnew System::NullReferenceException();
GetNativeEntity().SetActive(active);
SHSceneManager::GetCurrentSceneGraph().SetActive(GetEntity(), active);
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/