////////////////////////////////////////////////////////////////////////// // onAttach void GaStructureComponent::onAttach( ScnEntityWeakRef Parent ) { // Get canvas + font. Canvas_ = Parent->getComponentAnyParentByType< ScnCanvasComponent >(); BcAssert( Canvas_ ); Font_ = Parent->getComponentAnyParentByType< ScnFontComponent >(); BcAssert( Font_ ); Sprite_ = Parent->getComponentAnyParentByType< ScnSpriteComponent >(); BcAssert( Sprite_ ); Physics_ = getParentEntity()->getComponentByType< GaPhysicsComponent >(); BcAssert( Physics_ ); Game_ = getParentEntity()->getComponentAnyParentByType< GaGameComponent >(); BcAssert( Game_ ); // Subscribe to hotspot for pressed. Parent->subscribe( gaEVT_HOTSPOT_PRESSED, this, [ this ]( EvtID, const EvtBaseEvent& InEvent )->eEvtReturn { const auto& Event = InEvent.get< GaHotspotEvent >(); return evtRET_PASS; } ); // Begin build phase event Game_->getParentEntity()->subscribe( gaEVT_GAME_BEGIN_BUILD_PHASE, this, [ this ]( EvtID, const EvtBaseEvent & Event ) { if( StructureType_ == GaStructureType::RESOURCE ) { Game_->spendResources( -CalculatedResourceRate_ ); } return evtRET_PASS; } ); setActive( Active_ ); Level_ = 0; incLevel(); Timer_ = BaseFireRate_; Super::onAttach( Parent ); }