Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Create a single component.
- ///
- /// Built-in components are handled separately, custom components are first searched and
- /// then created (if component was registered).
- /// </summary>
- /// <param name="component">Component type ID</param>
- /// <returns>Pointer to newly created component (null in case of failure)</returns>
- static Component* CreateComponent(ComponentId component)
- {
- if (component == ComponentTypeId::Get<SkinnedAnimatorComponent>())
- {
- return new SkinnedAnimatorComponent(nullptr);
- }
- else if (component == ComponentTypeId::Get<CameraComponent>())
- {
- return new CameraComponent(new PerspectiveCamera(float4(0.0f, 0.0f, 0.0f, 1.0f), float4(0.0f, 0.0f, 1.0f, 1.0f), float4(0.0f, 1.0f, 0.0f, 0.0f), Math::DegToRad(45.0f), 1.0f, 1.0f, 1000.0f, 1.0f));
- }
- else if (component == ComponentTypeId::Get<CollisionComponent>())
- {
- return new CollisionComponent(new Box(float4(1.0f, 1.0f, 1.0f, 0.0f)));
- }
- else if (component == ComponentTypeId::Get<LightComponent>())
- {
- return new LightComponent(new PointLight(float4(0.0f, 0.0f, 0.0f, 1.0f), 0.0f, 0.00001f));
- }
- else if (component == ComponentTypeId::Get<MaterialComponent>())
- {
- return new MaterialComponent(nullptr, nullptr, nullptr, nullptr, nullptr, mTextureManager);
- }
- else if (component == ComponentTypeId::Get<MeshComponent>())
- {
- return new MeshComponent(nullptr, mMeshManager);
- }
- else if (component == ComponentTypeId::Get<SkinnedMeshComponent>())
- {
- return new SkinnedMeshComponent(nullptr, mMeshManager);
- }
- else if (component == ComponentTypeId::Get<RigidBodyComponent>())
- {
- return new RigidBodyComponent(new RigidBody(0.0f));
- }
- else if (component == ComponentTypeId::Get<CharacterComponent>())
- {
- return new CharacterComponent(new Character(), 1.0f, 1.0f, 1.0f);
- }
- else if (component == ComponentTypeId::Get<AudioListenerComponent>())
- {
- return new AudioListenerComponent(new AudioListener());
- }
- else if (component == ComponentTypeId::Get<AudioSourceComponent>())
- {
- return new AudioSourceComponent(nullptr, mSoundManager);
- }
- else
- {
- std::map<ComponentId, ComponentInterface*>::iterator it = mScriptComponents.find(component);
- if (it == mScriptComponents.end())
- {
- return nullptr;
- }
- else
- {
- return it->second->CreateComponent();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement