本文整理汇总了C++中IEntitySystem::InitEntity方法的典型用法代码示例。如果您正苦于以下问题:C++ IEntitySystem::InitEntity方法的具体用法?C++ IEntitySystem::InitEntity怎么用?C++ IEntitySystem::InitEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntitySystem
的用法示例。
在下文中一共展示了IEntitySystem::InitEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnClientConnect
bool CGameRules::OnClientConnect(int channelId, bool isReset)
{
const float fTerrainSize = static_cast<float>(gEnv->p3DEngine->GetTerrainSize());
const float fTerrainElevation = gEnv->p3DEngine->GetTerrainElevation(fTerrainSize * 0.5f, fTerrainSize * 0.5f);
const Vec3 vSpawnLocation(fTerrainSize * 0.5f, fTerrainSize * 0.5f, fTerrainElevation + 15.0f);
IEntitySystem* pEntitySystem = gEnv->pEntitySystem;
IEntityClass* pPlayerClass = pEntitySystem->GetClassRegistry()->FindClass("Player");
if (!pPlayerClass)
return false;
SEntitySpawnParams params;
params.sName = "Player";
params.vPosition = vSpawnLocation;
params.pClass = pPlayerClass;
if (channelId)
{
params.nFlags |= ENTITY_FLAG_NEVER_NETWORK_STATIC;
if (INetChannel* pNetChannel = gEnv->pGame->GetIGameFramework()->GetNetChannel(channelId))
{
if (pNetChannel->IsLocal())
{
params.id = LOCAL_PLAYER_ENTITY_ID;
}
}
}
IEntity* pPlayerEntity = pEntitySystem->SpawnEntity(params, false);
CGameObject* pGameObject = static_cast<CGameObject*>(pPlayerEntity->GetProxy(ENTITY_PROXY_USER));
// always set the channel id before initializing the entity
pGameObject->SetChannelId(channelId);
return pEntitySystem->InitEntity(pPlayerEntity, params);
}