2023-07-21 09:50:06 +00:00
|
|
|
#*
|
|
|
|
#* play_animation.gd
|
|
|
|
#* =============================================================================
|
|
|
|
#* Copyright 2021-2023 Serhii Snitsaruk
|
|
|
|
#*
|
|
|
|
#* Use of this source code is governed by an MIT-style
|
|
|
|
#* license that can be found in the LICENSE file or at
|
|
|
|
#* https://opensource.org/licenses/MIT.
|
|
|
|
#* =============================================================================
|
|
|
|
#*
|
|
|
|
|
2022-12-15 13:49:38 +00:00
|
|
|
@tool
|
|
|
|
extends BTAction
|
|
|
|
|
|
|
|
@export var animation_name: String
|
2022-12-16 03:16:19 +00:00
|
|
|
@export var animation_player: NodePath
|
2022-12-15 13:49:38 +00:00
|
|
|
|
|
|
|
var _player: AnimationPlayer
|
|
|
|
var _finished: bool
|
|
|
|
|
|
|
|
|
|
|
|
func _generate_name() -> String:
|
2023-04-14 08:28:33 +00:00
|
|
|
return "PlayAnimation \"%s\"" % animation_name
|
2022-12-15 13:49:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _setup() -> void:
|
2022-12-16 03:16:19 +00:00
|
|
|
_player = agent.get_node(animation_player)
|
2022-12-15 13:49:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _enter() -> void:
|
|
|
|
if _player.has_animation(animation_name):
|
|
|
|
_finished = false
|
|
|
|
_player.play(animation_name)
|
|
|
|
_player.animation_finished.connect(_on_animation_finished, CONNECT_ONE_SHOT)
|
|
|
|
else:
|
|
|
|
_finished = true
|
|
|
|
|
|
|
|
|
|
|
|
func _tick(_delta: float) -> int:
|
|
|
|
if _finished:
|
|
|
|
return SUCCESS
|
|
|
|
return RUNNING
|
|
|
|
|
|
|
|
|
|
|
|
func _on_animation_finished(_anim):
|
|
|
|
_finished = true
|