Added implementation of GetComponentInChildren() for scripts

This commit is contained in:
Kah Wei 2022-09-22 11:37:24 +08:00
parent 21a3d6ecd7
commit 4958240806
3 changed files with 52 additions and 43 deletions

View File

@ -21,6 +21,9 @@ of DigiPen Institute of Technology is prohibited.
#include <msclr\marshal_cppstd.h> #include <msclr\marshal_cppstd.h>
// External Dependencies // External Dependencies
#include "ECS_Base/Managers/SHEntityManager.h" #include "ECS_Base/Managers/SHEntityManager.h"
#include "Scene/SHSceneManager.h"
#include "Scene/SHSceneGraph.h"
#include "Tools/SHLog.h"
// Project Headers // Project Headers
#include "Utility/Convert.hxx" #include "Utility/Convert.hxx"
#include "Utility/Debug.hxx" #include "Utility/Debug.hxx"
@ -124,27 +127,31 @@ namespace SHADE
return T(); return T();
} }
// Get Transform component and get the children list // Get Entity's SceneGraphNode
throw gcnew System::NotImplementedException; SHSceneNode* sceneGraphNode = SHSceneManager::GetCurrentSceneGraph().GetNode(entity);
//Pls::Transform* tf = Pls::ECS::GetComponent<Pls::Transform>(entity); if (sceneGraphNode == nullptr)
//if (tf == nullptr) {
// return T(); 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 // Search direct children first
//for (const auto& child : tf->GetChildren()) for (const auto& child : sceneGraphNode->GetChildren())
//{ {
// T component = GetComponent<T>(child); T component = GetComponent<T>(child->GetEntityID());
// if (component != nullptr) if (component != nullptr)
// return component; return component;
//} }
//// Search their children // Search their children
//for (const auto& child : tf->GetChildren()) for (const auto& child : sceneGraphNode->GetChildren())
//{ {
// T script = GetComponentInChildren<T>(child); T component = GetComponentInChildren<T>(child->GetEntityID());
// if (script != nullptr) if (component != nullptr)
// return script; return component;
//} }
// None here // None here
return T(); return T();

View File

@ -56,7 +56,7 @@ namespace SHADE
} }
bool GameObject::IsActiveInHierarchy::get() bool GameObject::IsActiveInHierarchy::get()
{ {
throw gcnew System::NotImplementedException(); return true; // TODO: Update once we have an equivalent on the Entity object
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/

View File

@ -20,6 +20,7 @@ of DigiPen Institute of Technology is prohibited.
#include <sstream> #include <sstream>
// External Dependencies // External Dependencies
#include "ECS_Base/Managers/SHEntityManager.h" #include "ECS_Base/Managers/SHEntityManager.h"
#include "Tools/SHLog.h"
// Project Headers // Project Headers
#include "Utility/Debug.hxx" #include "Utility/Debug.hxx"
#include "Utility/Convert.hxx" #include "Utility/Convert.hxx"
@ -148,34 +149,37 @@ namespace SHADE
if (!EntityUtils::IsValid(entity)) if (!EntityUtils::IsValid(entity))
throw gcnew System::ArgumentException("Invalid Entity provided to get a Script from."); throw gcnew System::ArgumentException("Invalid Entity provided to get a Script from.");
// Check if entity exists in the script storage // Check if entity exists in the script storage
if (!scripts.ContainsKey(entity)) if (!scripts.ContainsKey(entity))
{ {
return T(); return T();
} }
// Get Transform component and get the children list // Get Entity's SceneGraphNode
throw gcnew System::NotImplementedException; SHSceneNode* sceneGraphNode = SHSceneManager::GetCurrentSceneGraph().GetNode(entity);
//Pls::Transform* tf = Pls::ECS::GetComponent<Pls::Transform>(Convert::ToNative(entity)); if (sceneGraphNode == nullptr)
//if (tf == nullptr) {
// return T(); 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 // Search direct children first
//for (const auto& child : tf->GetChildren()) for (const auto& child : sceneGraphNode->GetChildren())
//{ {
// T script = GetScript<T>(Convert::ToCLI(child)); T script = GetScript<T>(child->GetEntityID());
// if (script != nullptr) if (script != nullptr)
// return script; return script;
//} }
//// Search their children // Search their children
//for (const auto& child : tf->GetChildren()) for (const auto& child : sceneGraphNode->GetChildren())
//{ {
// T script = GetScriptInChildren<T>(Convert::ToCLI(child)); T script = GetScript<T>(child->GetEntityID());
// if (script != nullptr) if (script != nullptr)
// return script; return script;
//} }
// None here // None here
return T(); return T();
@ -233,7 +237,6 @@ namespace SHADE
if (!EntityUtils::IsValid(entity)) if (!EntityUtils::IsValid(entity))
throw gcnew System::ArgumentException("Invalid Entity provided to remove a Script from."); throw gcnew System::ArgumentException("Invalid Entity provided to remove a Script from.");
// Check if entity exists in the script storage // Check if entity exists in the script storage
if (!scripts.ContainsKey(entity)) if (!scripts.ContainsKey(entity))
{ {
@ -264,7 +267,6 @@ namespace SHADE
return false; return false;
} }
// Check if entity exists in the script storage // Check if entity exists in the script storage
if (!scripts.ContainsKey(entity)) if (!scripts.ContainsKey(entity))
{ {