Editor: UI panels and GameObject updates
This commit is contained in:
@@ -10,6 +10,10 @@ GameObject::ID GameObject::s_nextID = 1;
|
||||
GameObject::GameObject()
|
||||
: m_name("GameObject") {
|
||||
m_id = s_nextID++;
|
||||
static std::random_device rd;
|
||||
static std::mt19937_64 gen(rd());
|
||||
static std::uniform_int_distribution<uint64_t> dis(1, UINT64_MAX);
|
||||
m_uuid = dis(gen);
|
||||
m_transform = new TransformComponent();
|
||||
m_transform->m_gameObject = this;
|
||||
}
|
||||
@@ -17,6 +21,10 @@ GameObject::GameObject()
|
||||
GameObject::GameObject(const std::string& name)
|
||||
: m_name(name) {
|
||||
m_id = s_nextID++;
|
||||
static std::random_device rd;
|
||||
static std::mt19937_64 gen(rd());
|
||||
static std::uniform_int_distribution<uint64_t> dis(1, UINT64_MAX);
|
||||
m_uuid = dis(gen);
|
||||
m_transform = new TransformComponent();
|
||||
m_transform->m_gameObject = this;
|
||||
}
|
||||
@@ -88,6 +96,27 @@ void GameObject::DetachChildren() {
|
||||
m_children.clear();
|
||||
}
|
||||
|
||||
void GameObject::DetachFromParent() {
|
||||
if (m_parent) {
|
||||
Math::Vector3 worldPos = GetTransform()->GetPosition();
|
||||
Math::Quaternion worldRot = GetTransform()->GetRotation();
|
||||
Math::Vector3 worldScale = GetTransform()->GetScale();
|
||||
|
||||
auto& siblings = m_parent->m_children;
|
||||
siblings.erase(std::remove(siblings.begin(), siblings.end(), this), siblings.end());
|
||||
m_parent = nullptr;
|
||||
|
||||
if (m_scene) {
|
||||
m_scene->m_rootGameObjects.push_back(m_id);
|
||||
}
|
||||
|
||||
GetTransform()->SetPosition(worldPos);
|
||||
GetTransform()->SetRotation(worldRot);
|
||||
GetTransform()->SetScale(worldScale);
|
||||
GetTransform()->SetDirty();
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::SetActive(bool active) {
|
||||
if (m_activeSelf != active) {
|
||||
m_activeSelf = active;
|
||||
|
||||
Reference in New Issue
Block a user