Last active
August 29, 2015 14:03
-
-
Save gin0606/90788db9872b4d4378d7 to your computer and use it in GitHub Desktop.
CocoStudioで深い階層にあるButtonとかを楽に取得するUtil
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by gin0606 on 2014/07/07. | |
// | |
#include "UIWidget.h" | |
#ifndef __widget_util_H_ | |
#define __widget_util_H_ | |
class WidgetUtil { | |
public: | |
static cocos2d::ui::Widget *getChildByNameRecursively(cocos2d::ui::Widget *rootWidget, const std::string &name) { | |
if (!rootWidget) {return nullptr;} | |
if (rootWidget->getName() == name) {return rootWidget;} | |
for (auto child : rootWidget->getChildren()) { | |
auto _child = getChildByNameRecursively(dynamic_cast<cocos2d::ui::Widget *>(child), name); | |
if (_child) {return _child;} | |
} | |
return nullptr; | |
} | |
template<class T> | |
static T getChildByNameRecursivelyAs(cocos2d::ui::Widget *rootWidget, std::string name) { | |
return static_cast<T>(getChildByNameRecursively(rootWidget, name)); | |
} | |
}; | |
#endif //_widget_util_H_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment