Shifted Hierarchy interface from Transform to GameObject

This commit is contained in:
Diren D Bharwani 2022-11-01 19:00:31 +08:00
parent 40be8a7962
commit 72dc07bbd9
4 changed files with 18 additions and 65 deletions

View File

@ -87,15 +87,6 @@ namespace SHADE
{ {
GetNativeComponent()->SetWorldScale(Convert::ToNative(val)); 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 */ /* Constructors */
@ -103,21 +94,4 @@ namespace SHADE
Transform::Transform(Entity entity) Transform::Transform(Entity entity)
: Component(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);
}
} }

View File

@ -107,30 +107,6 @@ namespace SHADE
Vector3 get(); Vector3 get();
void set(Vector3 val); 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);
}; };
} }

View File

@ -79,11 +79,24 @@ namespace SHADE
} }
GameObject^ GameObject::Parent::get() GameObject^ GameObject::Parent::get()
{ {
return nullptr; 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) 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);
} }
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -97,10 +110,6 @@ namespace SHADE
{ {
GetNativeEntity().SetActive(active); GetNativeEntity().SetActive(active);
} }
System::Collections::ArrayList^ GameObject::GetChildren()
{
return children;
}
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Component Functions */ /* Component Functions */

View File

@ -93,6 +93,9 @@ namespace SHADE
{ {
Entity get(); Entity get();
} }
/// <summary>
/// The parent entity for this GameObject.
/// </summary>
property GameObject^ Parent property GameObject^ Parent
{ {
GameObject^ get(); GameObject^ get();
@ -118,15 +121,6 @@ namespace SHADE
/// </param> /// </param>
void SetActive(bool active); void SetActive(bool active);
/// <summary>
/// Gets the list of GameObjects that are the children of this GameObject.
/// </summary>
/// <returns>
/// The list of GameObjects that are the children of this GameObject. List is empty is
/// there is none.
/// </returns>
System::Collections::ArrayList^ GetChildren();
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Component Access Functions */ /* Component Access Functions */