1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include "environment.h" 16 17 #include <3d/ecs/components/environment_component.h> 18 #include <core/ecs/intf_entity_manager.h> 19 20 #include <meta/interface/resource/intf_object_resource.h> 21 SCENE_BEGIN_NAMESPACE()22SCENE_BEGIN_NAMESPACE() 23 24 CORE_NS::Entity Environment::CreateEntity(const IInternalScene::Ptr& scene) 25 { 26 auto& ecs = scene->GetEcsContext(); 27 auto envm = ecs.FindComponent<CORE3D_NS::EnvironmentComponent>(); 28 if (!envm) { 29 return CORE_NS::Entity {}; 30 } 31 auto ent = ecs.GetNativeEcs()->GetEntityManager().Create(); 32 envm->Create(ent); 33 return ent; 34 } 35 SetEcsObject(const IEcsObject::Ptr & obj)36bool Environment::SetEcsObject(const IEcsObject::Ptr& obj) 37 { 38 auto ret = Super::SetEcsObject(obj); 39 if (ret) { 40 Name()->SetValue(GetName()); 41 Name()->OnChanged()->AddHandler(META_NS::MakeCallback<META_NS::IOnChanged>([&] { 42 if (this->object_) { 43 this->object_->SetName(Name()->GetValue()); 44 } 45 })); 46 } 47 return ret; 48 } 49 GetName() const50BASE_NS::string Environment::GetName() const 51 { 52 return this->object_ ? this->object_->GetName() : ""; 53 } 54 55 SCENE_END_NAMESPACE() 56