void PrefabUtility::recordInstanceData(const HSceneObject& so, SceneObjectProxy& output, UnorderedMap<UINT32, GameObjectInstanceDataPtr>& linkedInstanceData) { struct StackData { HSceneObject so; SceneObjectProxy* proxy; }; Stack<StackData> todo; todo.push({so, &output}); output.instanceData = so->_getInstanceData(); output.linkId = (UINT32)-1; while (!todo.empty()) { StackData curData = todo.top(); todo.pop(); const Vector<HComponent>& components = curData.so->getComponents(); for (auto& component : components) { curData.proxy->components.push_back(ComponentProxy()); ComponentProxy& componentProxy = curData.proxy->components.back(); componentProxy.instanceData = component->_getInstanceData(); componentProxy.linkId = component->getLinkId(); linkedInstanceData[componentProxy.linkId] = componentProxy.instanceData; } UINT32 numChildren = curData.so->getNumChildren(); curData.proxy->children.resize(numChildren); for (UINT32 i = 0; i < numChildren; i++) { HSceneObject child = curData.so->getChild(i); SceneObjectProxy& childProxy = curData.proxy->children[i]; childProxy.instanceData = child->_getInstanceData(); childProxy.linkId = child->getLinkId(); linkedInstanceData[childProxy.linkId] = childProxy.instanceData; if (child->mPrefabLinkUUID.empty()) { todo.push({ child, &curData.proxy->children[i] }); } } } }
void Entity::AttachComponent(U32 componentIndex, Component* pComponent) { pComponent->AttachToEntity(m_id); components.push_back(ComponentProxy(pComponent->GetType(), componentIndex)); }