我想在脚本中做一个下拉列表容器
我想创建一个下拉容器来组织我的导出变量。是否可以在脚本中创建自定义下拉列表容器?
这样:
I want to create a dropdown container to organize my export variable. Is it possible to create a custom dropdown container in the script?
Like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是执行此操作的另一种方法。它还要求脚本是
工具
< /a>.我们需要这种方法作为要分组的变量的公共前缀。优点是我们不需要
_get
和_set
:如您所见,我们定义了一个带有
name
的类别,该类别将出现在检查器面板,hint_string
是我们将使用的前缀。将类别放在数组中的属性之前很重要。请参阅:添加脚本类别
附录:使用
PROPERTY_USAGE_CATEGORY
将生成一个命名标头,类似于图片上显示“Node2D”的标头关于这个问题。使用PROPERTY_USAGE_GROUP
创建可折叠组。This is another approach to do this. It also requires the script to be
tool
.What we need for this approach as a common prefix for the variables you want to group. The advantage is that we don't need
_get
and_set
:As you can see we define a category with a
name
that will appear in the Inspector panel, and thehint_string
is the prefix we will use. It is important to put the category before the properties in the array.See: Adding script categories
Addendum: Using
PROPERTY_USAGE_CATEGORY
will produce a named header, similar to the one that says "Node2D" on the picture on the question. UsePROPERTY_USAGE_GROUP
to make a collapsible group.是的,您可以做到这一点,但是(我认为)这有点丑陋,并缩短了您的脚本。您需要将脚本标记为
工具
脚本,并覆盖_get
,_SET
_SET 和_get_property_list
函数。一个基于您的屏幕截图的示例(不是100%确定这完全可以正常工作;我还基于一个最近的项目,此后我将其删除并在某种程度上重组了项目/代码/节点,因为略带UI' t值得脚本中的其他混乱):
请注意,此答案基于Godot 3.4。我不确定Godot 4中是否可以(或将)使用更简单的方法。
Yes, you can do this, but (in my opinion) it is a bit ugly and clutters up your script. You need to mark your script as a
tool
script and override the_get
,_set
, and_get_property_list
functions.An example based on your screenshot (not 100% sure this works exactly as-is; I'm also basing it on a recent project where I have since removed it and somewhat reorganized the project/code/node because the slightly nicer UI wasn't worth the additional clutter in the script):
Note that this answer is based on Godot 3.4. I'm not sure if a simpler approach is (or will be) available in Godot 4.