本文整理汇总了C++中ActorPtr::BeginPlay方法的典型用法代码示例。如果您正苦于以下问题:C++ ActorPtr::BeginPlay方法的具体用法?C++ ActorPtr::BeginPlay怎么用?C++ ActorPtr::BeginPlay使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ActorPtr
的用法示例。
在下文中一共展示了ActorPtr::BeginPlay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Load
void LevelLoader::Load(const char* fileName)
{
std::ifstream file(fileName);
if (!file.is_open())
{
SDL_Log("Level file %s not found", fileName);
return;
}
std::stringstream fileStream;
fileStream << file.rdbuf();
std::string contents = fileStream.str();
rapidjson::StringStream jsonStr(contents.c_str());
rapidjson::Document doc;
doc.ParseStream(jsonStr);
if (!doc.IsObject())
{
SDL_Log("Level file %s is not valid JSON", fileName);
DbgAssert(false, "Level file is not valid JSON!");
return;
}
std::string str = doc["metadata"]["type"].GetString();
int ver = doc["metadata"]["version"].GetInt();
// Check the metadata
if (!doc["metadata"].IsObject() ||
str != "itplevel" ||
ver != 1)
{
SDL_Log("Level %s is not a know level file format", fileName);
return;
}
// Step 1: Setup any overall world properties
if(doc["world"].IsObject())
{
Vector3 ambientLight;
GetVectorFromJSON(doc["world"], "ambientLight", ambientLight);
mGame.GetRenderer().SetAmbientLight(ambientLight);
}
// Step 2: Setup the actors (and each of their components)
const rapidjson::Value& actorsRoot = doc["actors"];
for (rapidjson::SizeType i = 0; i < actorsRoot.Size(); i++)
{
std::string type = actorsRoot[i]["type"].GetString();
ActorSpawnFunc & f = mActorSpawnMap.find(type)->second;
ActorPtr actor = f(mGame, actorsRoot[i]["properties"]);
//Iterate updated components
const rapidjson::Value& updatedComponents = actorsRoot[i]["updatedComponents"];
for (rapidjson::SizeType j = 0; j < updatedComponents.Size(); j++)
{
std::string componentType = updatedComponents[j]["type"].GetString();
ComponentInfo & typeinfo = mCompSpawnMap.find(componentType)->second;
ComponentPtr component = actor->GetComponentFromType(typeinfo.mType);
if(component != nullptr)
{
component->SetProperties(updatedComponents[j]["properties"]);
}
}
//Iterate new components
const rapidjson::Value& newComponents = actorsRoot[i]["newComponents"];
for(rapidjson::SizeType j = 0; j < newComponents.Size(); j++)
{
std::string componentType = newComponents[j]["type"].GetString();
ComponentInfo & typeinfo = mCompSpawnMap.find(componentType)->second;
Component::UpdateType updateType = Component::UpdateType::PreTick;
std::string update = newComponents[j]["update"].GetString();
if(update == "PostTick")
{
updateType = Component::UpdateType::PostTick;
}
typeinfo.mFunc(*actor, updateType , newComponents[j]["properties"]);
}
//Begin actor
actor->BeginPlay();
}
}