Merge pull request #158 from SHADE-DP/SP3-12-SceneGraph
SP3-12 Hierarchy Interface for C# UPDATES Setting & Getting of Parent has been moved from Transform to GameObject
This commit is contained in:
commit
5fe81932e1
|
@ -29,7 +29,7 @@ namespace SHADE
|
|||
{
|
||||
system.second->Init();
|
||||
#ifdef _DEBUG
|
||||
std::cout << system.first << " Init" << std::endl;
|
||||
SHLOG_INFO("Initialising System {}...", system.first)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,15 +87,6 @@ namespace SHADE
|
|||
{
|
||||
GetNativeComponent()->SetWorldScale(Convert::ToNative(val));
|
||||
}
|
||||
Transform^ Transform::Parent::get()
|
||||
{
|
||||
auto node = SHSceneManager::GetCurrentSceneGraph().GetNode(owner.GetEntity());
|
||||
if (!node)
|
||||
throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity.");
|
||||
|
||||
const auto PARENT = node->GetParent();
|
||||
return PARENT ? gcnew Transform(PARENT->GetEntityID()) : nullptr;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Constructors */
|
||||
|
@ -103,21 +94,4 @@ namespace SHADE
|
|||
Transform::Transform(Entity entity)
|
||||
: Component(entity)
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
void Transform::SetParent(Transform^ parent, bool worldPositionStays)
|
||||
{
|
||||
auto& sceneGraph = SHSceneManager::GetCurrentSceneGraph();
|
||||
auto node = sceneGraph.GetNode(owner.GetEntity());
|
||||
if (!node)
|
||||
throw gcnew System::InvalidOperationException("[Transform] Unable to retrieve SceneGraphNode for an Entity.");
|
||||
|
||||
if (parent)
|
||||
node->SetParent(sceneGraph.GetNode(parent->owner.GetEntity()));
|
||||
else
|
||||
sceneGraph.SetParent(parent->owner.GetEntity(), nullptr);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,30 +107,6 @@ namespace SHADE
|
|||
Vector3 get();
|
||||
void set(Vector3 val);
|
||||
}
|
||||
/// <summary>
|
||||
/// Parent Transform that affects this Transform.
|
||||
/// </summary>
|
||||
property Transform^ Parent
|
||||
{
|
||||
Transform^ get();
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Usage Functions */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/// <summary>
|
||||
/// Sets the parent of this Transform component.
|
||||
/// </summary>
|
||||
/// <param name="parent">
|
||||
/// Entity that contains the Transform component that this Transform will be
|
||||
/// parented to. If null, unparenting will occur.
|
||||
/// </param>
|
||||
/// <param name="worldPositionStays">
|
||||
/// If true, the transform values of this Transform component will retain their
|
||||
/// pre-parent-change global transforms. The local transform values will be
|
||||
/// modified to ensure that the global transforms do not change.
|
||||
/// </param>
|
||||
void SetParent(Transform^ parent, bool worldPositionStays);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ of DigiPen Institute of Technology is prohibited.
|
|||
#include "GameObject.hxx"
|
||||
// External Dependencies
|
||||
#include "ECS_Base/Managers/SHEntityManager.h"
|
||||
#include "Scene/SHSceneGraph.h"
|
||||
// Project Headers
|
||||
#include "ECS.hxx"
|
||||
#include "Utility/Convert.hxx"
|
||||
|
@ -76,6 +77,27 @@ namespace SHADE
|
|||
{
|
||||
return entity;
|
||||
}
|
||||
GameObject^ GameObject::Parent::get()
|
||||
{
|
||||
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
|
||||
const auto* ROOT = SCENE_GRAPH.GetRoot();
|
||||
|
||||
const auto* NODE = SCENE_GRAPH.GetNode(entity);
|
||||
if (NODE == nullptr)
|
||||
throw gcnew System::InvalidOperationException("Unable to retrieve SceneGraphNode for Entity " + entity.ToString());
|
||||
|
||||
const auto* PARENT = NODE->GetParent();
|
||||
return PARENT != ROOT ? gcnew GameObject(PARENT->GetEntityID()) : nullptr;
|
||||
}
|
||||
void GameObject::Parent::set(GameObject^ newParent)
|
||||
{
|
||||
const auto& SCENE_GRAPH = SHSceneManager::GetCurrentSceneGraph();
|
||||
|
||||
if (newParent == nullptr)
|
||||
SCENE_GRAPH.SetParent(entity, nullptr);
|
||||
else
|
||||
SCENE_GRAPH.SetParent(entity, newParent->EntityId);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* GameObject Property Functions */
|
||||
|
@ -159,11 +181,13 @@ namespace SHADE
|
|||
/* Constructors */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
GameObject::GameObject(const SHEntity& entity)
|
||||
: entity { entity.GetEID() }
|
||||
: entity { entity.GetEID() }
|
||||
, children{ gcnew System::Collections::ArrayList }
|
||||
{}
|
||||
|
||||
GameObject::GameObject(Entity entity)
|
||||
: entity { entity }
|
||||
: entity { entity }
|
||||
, children{ gcnew System::Collections::ArrayList }
|
||||
{}
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
|
|
@ -93,6 +93,14 @@ namespace SHADE
|
|||
{
|
||||
Entity get();
|
||||
}
|
||||
/// <summary>
|
||||
/// The parent entity for this GameObject.
|
||||
/// </summary>
|
||||
property GameObject^ Parent
|
||||
{
|
||||
GameObject^ get();
|
||||
void set(GameObject^);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* GameObject Property Functions */
|
||||
|
@ -112,6 +120,7 @@ namespace SHADE
|
|||
/// Whether to activate or deactivate this GameObject.
|
||||
/// </param>
|
||||
void SetActive(bool active);
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
/* Component Access Functions */
|
||||
|
@ -242,7 +251,8 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------*/
|
||||
/* Data Members */
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
Entity entity;
|
||||
Entity entity;
|
||||
System::Collections::ArrayList^ children;
|
||||
|
||||
public:
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
|
|
Loading…
Reference in New Issue