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.

67 lines
1.7 KiB
GDScript

2 years ago
@tool
extends AnimationSelectCfg
class_name SkillCfg
@export var name : String
@export var skill_animation : Animation
var animation_library = load("res://resource/skill_animation_library/animation_library.tres")
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
ResourceSaver.save(animation,path)
refresh_animation_lib()
return true
func refresh_animation_lib():
var dir_path = "res://resource/skill_animation"
var dir = DirAccess.open(dir_path)
for file in dir.get_files():
var path = dir_path + "/" + file
var res = load(path)
if res is Animation:
var animation = res as Animation
var animation_name = Util.get_resource_name(animation)
animation_library.add_animation(animation_name,animation)
animation_library.animation_added.emit(animation_name)