我正在做一些项目,在那里我需要动态创建,按钮与NGUI。我找到了一些答案,但都帮不了我。这很简单,但是根据我在http://www.tasharen.com/forum/index.php?topic=81.0和NGUI (UICreateWidgetWizard.cs)中发现的,比如:
UILabel lbl = NGUITools.AddWidget<UILabel>(go);它还是不起作用..。
我的代码如下:
UIButton button = NGUITools.AddWidget<UIButton>(parent);谢谢你们帮忙!
发布于 2014-09-05 09:49:25
如@pfranza建议的那样,创建UIButtons的预制件,您可以将其作为脚本中的公共对象引用,然后使用
GameObject newButton = NGUITools.AddChild(mParentGameObject, mButtonPrefab);或者,如果您愿意,可以在运行时完全创建它:
UISprite mButtonSprite = NGUITools.AddSprite(mParentGameObject, mAtlas, "Button");
//Button is the name of the sprite in the atlas
mButtonSprite.MakePixelPerfect();
NGUITools.AddWidgetCollider(mButtonSprite.gameObject);
mButtonSprite.gameObject.AddComponent<UIButton>();
//add any further components/set up you like.发布于 2014-09-03 21:10:29
您必须从要用作模板的按钮中创建预制件;将预制件作为GameObject附加到脚本中。然后,在脚本中,您可以克隆该对象并激活它。
https://stackoverflow.com/questions/25649916
复制相似问题