本文整理汇总了C++中CGameObject::addComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ CGameObject::addComponent方法的具体用法?C++ CGameObject::addComponent怎么用?C++ CGameObject::addComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CGameObject
的用法示例。
在下文中一共展示了CGameObject::addComponent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addWeaponToInventory
// addWeaponToInventory
// add to component
void CWeaponComponent::addWeaponToInventory( const char* weaponName )
{
SWeapon* weapon = getWeapon(weaponName);
if ( weapon == NULL )
{
CGameConfig::SWeaponInfo* wpInfo = CGameConfig::getInstance()->getWeaponByName(weaponName);
if ( wpInfo )
{
CGameObject *wpObj = new CGameObject(NULL);
// load model
if ( wpInfo->model.empty() == false )
{
CColladaMeshComponent *collada = new CColladaMeshComponent(wpObj);
collada->loadScene(wpInfo->model.c_str());
wpObj->addComponent(collada);
wpObj->initComponent();
}
wpObj->setVisible(false);
wpObj->setParent(m_gameObject);
m_weapons.push_back( SWeapon() );
SWeapon& w = m_weapons.back();
w.m_obj = wpObj;
w.m_num = 1;
w.m_info = wpInfo;
// find type of weapon
for (int i = (int)Unknown; i < (int)NumWPType; i++)
{
if ( wpInfo->type == k_weaponTypeString[i] )
{
w.m_type = (EWeaponType)i;
break;
}
}
switch (w.m_type)
{
case Gun:
{
CGunComponent *gun = new CGunComponent(wpObj, wpInfo);
wpObj->addComponent(gun);
}
break;
}
wpObj->initComponent();
}
}
else
{
weapon->m_num++;
}
}
示例2: slot_ObjectList_MenuRequest
void Editor::slot_ObjectList_MenuRequest( const QPoint& p )
{
if(ui.widgetListObj->itemAt(p) == nullptr)
return;
static QMenu mainMenu;
static bool firstExex = true;
static QAction* actionDelObj = nullptr;
if(firstExex)
{
firstExex = false;
actionDelObj = mainMenu.addAction("Delete");
static QMenu* menuAddComp = mainMenu.addMenu("Add Component");
static QVector<QMenu*> listMenuCompPack;
auto ci = CGame::GetComponentClassHead();
while(ci)
{
for(auto iter = listMenuCompPack.begin(); iter != listMenuCompPack.end(); iter++)
{
if(ci->packName() == (*iter)->title())
{
if(ci->showInEd())
(*iter)->addAction(ci->className());
goto SEC1;
}
}
if(ci->showInEd())
{
QMenu* newMenu = menuAddComp->addMenu(ci->packName());
newMenu->addAction(ci->className());
listMenuCompPack.push_back(newMenu);
}
SEC1:
ci = ci->next();
}
}
QAction* actionRet = mainMenu.exec(ui.widgetListObj->mapToGlobal(p));
if(actionRet)
{
if(actionRet == actionDelObj)
{
CGameObject* obj = CGame::GetObjByIndex(ui.widgetListObj->currentRow());
obj->destroy();
delete ui.widgetListObj->takeItem(ui.widgetListObj->currentRow());
Editor::SelectObj(nullptr);
}
else
{
CGameObject* obj = CGame::GetObjByIndex(ui.widgetListObj->currentRow());
obj->addComponent(actionRet->text().toAscii().data());
Editor::SelectObj(obj);
}
CGame::EDTick();
}
}