当前位置: 首页>>代码示例>>C++>>正文


C++ CGameObject::addComponent方法代码示例

本文整理汇总了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++;
	}
}
开发者ID:codeman001,项目名称:gsleveleditor,代码行数:60,代码来源:CWeaponComponent.cpp

示例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();
	}
}
开发者ID:UFNHGGI,项目名称:CBGE,代码行数:62,代码来源:editor.cpp


注:本文中的CGameObject::addComponent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。