#include "RUBehaviacTreeFactory.h" NS_RU_BEGIN static RUBehaviacTreeFactory *_instance = nullptr; RUBehaviacTreeFactory* RUBehaviacTreeFactory::getInstance() { if (_instance == nullptr) { _instance = new (std::nothrow) RUBehaviacTreeFactory; } return _instance; } void RUBehaviacTreeFactory::registerBehaviacTreeCreator(const std::string& treeName, std::function behaviacTreeCreator) { CCASSERT(_behaviacTreeCreators.find(treeName) == _behaviacTreeCreators.end(), "wtf"); _behaviacTreeCreators.emplace(treeName,behaviacTreeCreator); } RUBehaviacTree* RUBehaviacTreeFactory::createBehaviacTree(const std::string& treeName) { RUBehaviacTree* behaviacTree = nullptr; //如果注册器的key未注册,返回默认注册器 if (treeName.empty() || _behaviacTreeCreators.find(treeName) == _behaviacTreeCreators.end()) { CCASSERT(false,"有问题"); }else{ auto behaviacTreeCreator = _behaviacTreeCreators.find(treeName)->second; behaviacTree = behaviacTreeCreator(); } return behaviacTree; } NS_RU_END