如何从key中获取属性名称?

发布于 2025-01-14 15:40:06 字数 356 浏览 1 评论 0原文

我正在尝试获取从动画播放器节点更改的所有属性和值的列表,
但是如何获取动画键正在更改的节点的属性名称?

也许是这样的:

var ani=aniplayer.get_animation('running');
    
for i in range(0,ani.get_track_count()):
        var key_idx=ani.track_find_key(i,0,0);
        print("property=>",ani.get_key_property(i,key_idx)," new value=>",ani.track_get_key_value(i,key_idx));

I'm trying to get a list of all the properties and the values that are being changed from an animation player node,
but how do I get the property name of node that the animation key is changing?

maybe something like this:

var ani=aniplayer.get_animation('running');
    
for i in range(0,ani.get_track_count()):
        var key_idx=ani.track_find_key(i,0,0);
        print("property=>",ani.get_key_property(i,key_idx)," new value=>",ani.track_get_key_value(i,key_idx));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜点 2025-01-21 15:40:06

假设您有一个动画播放器:

var aniplayer := $AnimationPlayer as AnimationPlayer

您可以通过名称获得动画:

var ani := aniplayer.get_animation("running")

如您所知,您可以获取动画的轨道数:

var track_count := ani.get_track_count()

当然我们可以循环:

for track_id in range(0,track_count):
    pass

让我们看看,您想知道属性是什么正在设置。要获取属性,我们需要获取路径,并从那里提取属性:

for track_id in range(0,track_count):
    var track_path := (ani.track_get_path(track_id) as String).split(":")
    var node_path := track_path[0]
    var property_path := track_path[1]

附录

还有另一种方法可以从NodePath获取属性路径:get_concatenated_subnames

或者我们可以用 get_subname

这就是属性名称:

var property_path = ani.track_get_path(track_id).get_subname(0)

我想现在正是让大家注意 AnimationPlayer 可以为子属性设置动画这一事实的好时机。使用 get_subname(0) 您可以获取属性,但不能获取子属性。

例如,您不必为 position 设置动画,您可以为 position.y 设置动画,并且可以通过在动画面板中轨道名称的末尾。 我在其他地方更详细地描述了如何做到这一点。在本例中 get_subname( 0) 将为您提供 position,但 get_concatenated_subnames() 将为您提供 position:y

Let us say you have an animation player:

var aniplayer := $AnimationPlayer as AnimationPlayer

And you get an animation by name:

var ani := aniplayer.get_animation("running")

As you know you can get the number of tracks the animations has:

var track_count := ani.get_track_count()

And, of course we can loop:

for track_id in range(0,track_count):
    pass

Let us see, you want to know what property is being set. To get the property, we need to get the path, and extract the property from there:

for track_id in range(0,track_count):
    var track_path := (ani.track_get_path(track_id) as String).split(":")
    var node_path := track_path[0]
    var property_path := track_path[1]

Addendum:

There is another way to get the property path from a NodePath: get_concatenated_subnames.

Or we can get the elements separated with get_subname.

So this is the property name:

var property_path = ani.track_get_path(track_id).get_subname(0)

I guess this is good time as any to bring attention to the fact that AnimationPlayer can animate sub-properties. With get_subname(0) you get the property, but not the sub-property.

For example, you don't have to animate position, you can animate position.y and you would do that by adding :y at the end of the track name in the Animation panel. I describe how to do it with more detail elsewhere. In this case get_subname(0) will give you position, but get_concatenated_subnames() will give you position:y.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文