You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.0 KiB
GDScript

@tool
extends AnimationSelectCfg
class_name SkillCfg
@export var name : String
@export var skill_animation : Animation
var _has_animation : bool
@export var has_animation : bool :
get:
return _has_animation
set(value):
if Engine.is_editor_hint():
if value != _has_animation:
check_animation(value)
else:
_has_animation = value
func check_animation(value):
if value:
var res_name = Util.get_resource_name(self)
var skill_animation_path = "res://resource/skill_animation/%s.tres" %res_name
if !ResourceLoader.exists(skill_animation_path):
if !create_animation(res_name,skill_animation_path):
return
skill_animation = load(skill_animation_path)
_has_animation = value
else:
skill_animation = null
_has_animation = value
func create_animation(res_name,path) -> bool:
if sprite_frams == null:
print("未设置技能动画资源")
return false
if animation_name == "":
print("未设置技能动画名")
return false
print(animation_name)
if !sprite_frams.has_animation(animation_name):
print("技能动画名不存在")
return false
var animation = Animation.new()
animation.resource_name = res_name
var track_sprite_frames = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(track_sprite_frames,"View:sprite_frames")
animation.track_insert_key(track_sprite_frames,0,sprite_frams)
var track_animation = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(track_animation,"View:animation")
animation.track_insert_key(track_animation,0,animation_name)
var track_frame = animation.add_track(Animation.TYPE_VALUE)
animation.track_set_path(track_frame,"View:frame")
var animation_speed = 0.1
var animation_frame_count = sprite_frams.get_frame_count(animation_name)
animation.length = animation_speed*animation_frame_count
for i in range(0,animation_frame_count):
var time = i * animation_speed
animation.track_insert_key(track_frame,time,i)
ResourceSaver.save(animation,path)
Util.refresh_animation_lib()
return true