Added implementation of GetComponentInChildren() for scripts
This commit is contained in:
parent
21a3d6ecd7
commit
4958240806
|
@ -21,6 +21,9 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include <msclr\marshal_cppstd.h>
|
||||
// External Dependencies
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Scene/SHSceneManager.h"
|
||||
#include "Scene/SHSceneGraph.h"
|
||||
#include "Tools/SHLog.h"
|
||||
// Project Headers
|
||||
#include "Utility/Convert.hxx"
|
||||
#include "Utility/Debug.hxx"
|
||||
|
@ -124,27 +127,31 @@ namespace SHADE
|
|||
return T();
|
||||
}
|
||||
|
||||
// Get Transform component and get the children list
|
||||
throw gcnew System::NotImplementedException;
|
||||
//Pls::Transform* tf = Pls::ECS::GetComponent<Pls::Transform>(entity);
|
||||
//if (tf == nullptr)
|
||||
// return T();
|
||||
// Get Entity's SceneGraphNode
|
||||
SHSceneNode* sceneGraphNode = SHSceneManager::GetCurrentSceneGraph().GetNode(entity);
|
||||
if (sceneGraphNode == nullptr)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[ECS_CLI] Failed to retrieve SceneGraphNode of entity #" << entity << ". This should not happen!";
|
||||
SHLog::Warning(oss.str());
|
||||
return T();
|
||||
}
|
||||
|
||||
//// Search direct children first
|
||||
//for (const auto& child : tf->GetChildren())
|
||||
//{
|
||||
// T component = GetComponent<T>(child);
|
||||
// if (component != nullptr)
|
||||
// return component;
|
||||
//}
|
||||
// Search direct children first
|
||||
for (const auto& child : sceneGraphNode->GetChildren())
|
||||
{
|
||||
T component = GetComponent<T>(child->GetEntityID());
|
||||
if (component != nullptr)
|
||||
return component;
|
||||
}
|
||||
|
||||
//// Search their children
|
||||
//for (const auto& child : tf->GetChildren())
|
||||
//{
|
||||
// T script = GetComponentInChildren<T>(child);
|
||||
// if (script != nullptr)
|
||||
// return script;
|
||||
//}
|
||||
// Search their children
|
||||
for (const auto& child : sceneGraphNode->GetChildren())
|
||||
{
|
||||
T component = GetComponentInChildren<T>(child->GetEntityID());
|
||||
if (component != nullptr)
|
||||
return component;
|
||||
}
|
||||
|
||||
// None here
|
||||
return T();
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace SHADE
|
|||
}
|
||||
bool GameObject::IsActiveInHierarchy::get()
|
||||
{
|
||||
throw gcnew System::NotImplementedException();
|
||||
return true; // TODO: Update once we have an equivalent on the Entity object
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include <sstream>
|
||||
// External Dependencies
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Tools/SHLog.h"
|
||||
// Project Headers
|
||||
#include "Utility/Debug.hxx"
|
||||
#include "Utility/Convert.hxx"
|
||||
|
@ -148,34 +149,37 @@ namespace SHADE
|
|||
if (!EntityUtils::IsValid(entity))
|
||||
throw gcnew System::ArgumentException("Invalid Entity provided to get a Script from.");
|
||||
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
{
|
||||
return T();
|
||||
}
|
||||
|
||||
// Get Transform component and get the children list
|
||||
throw gcnew System::NotImplementedException;
|
||||
//Pls::Transform* tf = Pls::ECS::GetComponent<Pls::Transform>(Convert::ToNative(entity));
|
||||
//if (tf == nullptr)
|
||||
// return T();
|
||||
// Get Entity's SceneGraphNode
|
||||
SHSceneNode* sceneGraphNode = SHSceneManager::GetCurrentSceneGraph().GetNode(entity);
|
||||
if (sceneGraphNode == nullptr)
|
||||
{
|
||||
std::ostringstream oss;
|
||||
oss << "[ECS_CLI] Failed to retrieve SceneGraphNode of entity #" << entity << ". This should not happen!";
|
||||
SHLog::Warning(oss.str());
|
||||
return T();
|
||||
}
|
||||
|
||||
//// Search direct children first
|
||||
//for (const auto& child : tf->GetChildren())
|
||||
//{
|
||||
// T script = GetScript<T>(Convert::ToCLI(child));
|
||||
// if (script != nullptr)
|
||||
// return script;
|
||||
//}
|
||||
// Search direct children first
|
||||
for (const auto& child : sceneGraphNode->GetChildren())
|
||||
{
|
||||
T script = GetScript<T>(child->GetEntityID());
|
||||
if (script != nullptr)
|
||||
return script;
|
||||
}
|
||||
|
||||
//// Search their children
|
||||
//for (const auto& child : tf->GetChildren())
|
||||
//{
|
||||
// T script = GetScriptInChildren<T>(Convert::ToCLI(child));
|
||||
// if (script != nullptr)
|
||||
// return script;
|
||||
//}
|
||||
// Search their children
|
||||
for (const auto& child : sceneGraphNode->GetChildren())
|
||||
{
|
||||
T script = GetScript<T>(child->GetEntityID());
|
||||
if (script != nullptr)
|
||||
return script;
|
||||
}
|
||||
|
||||
// None here
|
||||
return T();
|
||||
|
@ -233,7 +237,6 @@ namespace SHADE
|
|||
if (!EntityUtils::IsValid(entity))
|
||||
throw gcnew System::ArgumentException("Invalid Entity provided to remove a Script from.");
|
||||
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
{
|
||||
|
@ -264,7 +267,6 @@ namespace SHADE
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Check if entity exists in the script storage
|
||||
if (!scripts.ContainsKey(entity))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue