Commit 4461930d authored by Gavin An's avatar Gavin An

코드 정리

parent 474297e4
...@@ -39,78 +39,12 @@ func _setup_monster_from_data() -> void: ...@@ -39,78 +39,12 @@ func _setup_monster_from_data() -> void:
return return
_model_instance = node _model_instance = node
print("BaseMonster: Identified model [", m_name, "] from MonsterData.") # 자식 클래스에서 구체적인 스킨 및 애니메이션 초기 설정 수행
_setup_skin_and_animations()
if m_name == "noble_man":
_apply_noble_man_skin(_model_instance)
elif m_name == "zombie":
_apply_zombie_skin(_model_instance)
_model_anim_player = _find_animation_player(_model_instance)
if _model_anim_player:
print("BaseMonster: Linked model AnimationPlayer: ", m_name)
# 모델명_animations.tres 또는 모델명_anims.tres 라이브러리를 동적으로 로드하여 등록
var anim_lib_path: String = "res://assets/models/monsters/" + m_name + "/" + m_name + "_animations.tres"
var anim_lib_path_alt: String = "res://assets/models/monsters/" + m_name + "/" + m_name + "_anims.tres"
var path_to_load: String = ""
if ResourceLoader.exists(anim_lib_path):
path_to_load = anim_lib_path
elif ResourceLoader.exists(anim_lib_path_alt):
path_to_load = anim_lib_path_alt
if path_to_load != "":
var lib: AnimationLibrary = load(path_to_load) as AnimationLibrary
if lib and not _model_anim_player.has_animation_library(m_name):
var already_registered: bool = false
for existing_lib_name in _model_anim_player.get_animation_library_list():
if _model_anim_player.get_animation_library(existing_lib_name) == lib:
already_registered = true
break
if not already_registered:
_model_anim_player.add_animation_library(m_name, lib)
print("BaseMonster: Loaded and registered ", m_name, " animations library successfully.")
else:
print("BaseMonster: Animation library already registered on model under another name.")
# 초기 Idle 애니메이션 재생 시도
var init_idle: String = _resolve_anim_name(_model_anim_player, m_name, "Idle")
if init_idle != "":
_model_anim_player.play(init_idle)
print("BaseMonster: Playing initial Idle: ", init_idle)
## 몬스터 자식 메쉬에 noble_man_0.png 텍스처를 입히는 재귀 함수
func _apply_noble_man_skin(node: Node) -> void:
if node is MeshInstance3D:
var mesh_inst: MeshInstance3D = node as MeshInstance3D
var texture_path: String = "res://assets/models/monsters/noble_man/noble_man_0.png"
if ResourceLoader.exists(texture_path):
var texture: Texture2D = load(texture_path) as Texture2D
if texture:
var mat: StandardMaterial3D = StandardMaterial3D.new()
mat.albedo_texture = texture
mat.roughness = 0.5
mesh_inst.material_override = mat
for child: Node in node.get_children():
_apply_noble_man_skin(child)
## 몬스터 자식 메쉬에 zombie_0.png 텍스처를 입히는 재귀 함수
func _apply_zombie_skin(node: Node) -> void:
if node is MeshInstance3D:
var mesh_inst: MeshInstance3D = node as MeshInstance3D
var texture_path: String = "res://assets/models/monsters/zombie/zombie_0.png"
if ResourceLoader.exists(texture_path):
var texture: Texture2D = load(texture_path) as Texture2D
if texture:
var mat: StandardMaterial3D = StandardMaterial3D.new()
mat.albedo_texture = texture
mat.roughness = 0.5
mesh_inst.material_override = mat
for child: Node in node.get_children():
_apply_zombie_skin(child)
## 자식 클래스에서 스킨 및 애니메이션을 등록하도록 구현하는 가상 함수
func _setup_skin_and_animations() -> void:
pass
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
if GameManager.is_game_over or is_dead: if GameManager.is_game_over or is_dead:
...@@ -138,7 +72,7 @@ func initialize_monster(data: MonsterData) -> void: ...@@ -138,7 +72,7 @@ func initialize_monster(data: MonsterData) -> void:
if not _model_instance: if not _model_instance:
_setup_monster_from_data() _setup_monster_from_data()
# 체력바 생성 # 체력바 UI 생성
_create_hp_bar() _create_hp_bar()
## 피해 가하기 ## 피해 가하기
...@@ -209,28 +143,9 @@ func _create_hp_bar() -> void: ...@@ -209,28 +143,9 @@ func _create_hp_bar() -> void:
sprite.no_depth_test = false # 지형이나 다른 장막 뒤에 가려지도록 설정 sprite.no_depth_test = false # 지형이나 다른 장막 뒤에 가려지도록 설정
add_child(sprite) add_child(sprite)
## 몬스터 이동 상태에 맞춘 애니메이션 재생 제어 ## 몬스터 이동 상태에 맞춘 애니메이션 재생 제어 (상속 클래스에서 재정의)
func _update_monster_animation() -> void: func _update_monster_animation() -> void:
if not _model_anim_player: pass
return
var model_name: String = ""
if monster_data:
model_name = monster_data.model_name
elif _model_instance:
model_name = _model_instance.name
var anim_name: String = _resolve_anim_name(_model_anim_player, model_name, "Walking")
if anim_name != "":
var anim: Animation = _model_anim_player.get_animation(anim_name)
if anim:
anim.loop_mode = Animation.LOOP_LINEAR
if _last_anim_state != "walking":
_last_anim_state = "walking"
_model_anim_player.play(anim_name, -1, 1.2) # 1.2배속 재생
print("BaseMonster: Playing Walk animation: ", anim_name)
## 헬퍼: 자식 노드 중 AnimationPlayer 탐색 ## 헬퍼: 자식 노드 중 AnimationPlayer 탐색
func _find_animation_player(node: Node) -> AnimationPlayer: func _find_animation_player(node: Node) -> AnimationPlayer:
...@@ -249,7 +164,4 @@ func _resolve_anim_name(player: AnimationPlayer, model_name: String, anim_base_n ...@@ -249,7 +164,4 @@ func _resolve_anim_name(player: AnimationPlayer, model_name: String, anim_base_n
var lib_anim: String = model_name + "/" + anim_base_name var lib_anim: String = model_name + "/" + anim_base_name
if player.has_animation(lib_anim): if player.has_animation(lib_anim):
return lib_anim return lib_anim
var fbx_anim: String = "Armature|" + anim_base_name
if player.has_animation(fbx_anim):
return fbx_anim
return "" return ""
class_name NobleManMonster
extends BaseMonster
## Noble Man 전용 동작 및 비주얼 제어를 담당하는 클래스
func _setup_skin_and_animations() -> void:
_apply_noble_man_skin(_model_instance)
_model_anim_player = _find_animation_player(_model_instance)
if _model_anim_player:
print("NobleManMonster: Linked model AnimationPlayer")
var init_idle: String = _resolve_anim_name(_model_anim_player, "noble_man", "Idle")
if init_idle != "":
_model_anim_player.play(init_idle)
print("NobleManMonster: Playing initial Idle: ", init_idle)
## 몬스터 자식 메쉬에 noble_man_0.png 텍스처를 입히는 재귀 함수
func _apply_noble_man_skin(node: Node) -> void:
if node is MeshInstance3D:
var mesh_inst: MeshInstance3D = node as MeshInstance3D
var texture_path: String = "res://assets/models/monsters/noble_man/noble_man_0.png"
if ResourceLoader.exists(texture_path):
var texture: Texture2D = load(texture_path) as Texture2D
if texture:
var mat: StandardMaterial3D = StandardMaterial3D.new()
mat.albedo_texture = texture
mat.roughness = 0.5
mesh_inst.material_override = mat
for child: Node in node.get_children():
_apply_noble_man_skin(child)
## Noble Man 걷는 애니메이션 갱신 제어
func _update_monster_animation() -> void:
if not _model_anim_player:
return
var anim_name: String = _resolve_anim_name(_model_anim_player, "noble_man", "Walking")
if anim_name != "":
var anim: Animation = _model_anim_player.get_animation(anim_name)
if anim:
anim.loop_mode = Animation.LOOP_LINEAR
if _last_anim_state != "walking":
_last_anim_state = "walking"
_model_anim_player.play(anim_name, -1, 1.2) # 1.2배속 재생
print("NobleManMonster: Playing Walk animation: ", anim_name)
[gd_scene format=3 uid="uid://dimlohck6ebg7"] [gd_scene format=3 uid="uid://dimlohck6ebg7"]
[ext_resource type="Script" uid="uid://bj0j32wc3fvkg" path="res://src/entities/monsters/base_monster.gd" id="1_base_monster"] [ext_resource type="Script" path="res://src/entities/monsters/noble_man/noble_man_monster.gd" id="1_base_monster"]
[ext_resource type="PackedScene" uid="uid://dy3qfnuybgjg6" path="res://src/entities/monsters/noble_man/noble_man.tscn" id="2_noble_man"] [ext_resource type="PackedScene" uid="uid://dy3qfnuybgjg6" path="res://src/entities/monsters/noble_man/noble_man.tscn" id="2_noble_man"]
[sub_resource type="SphereShape3D" id="SphereShape3D_collision"] [sub_resource type="SphereShape3D" id="SphereShape3D_collision"]
......
class_name ZombieMonster
extends BaseMonster
## Zombie 전용 동작 및 비주얼 제어를 담당하는 클래스
func _setup_skin_and_animations() -> void:
_apply_zombie_skin(_model_instance)
_model_anim_player = _find_animation_player(_model_instance)
if _model_anim_player:
print("ZombieMonster: Linked model AnimationPlayer")
# 좀비 애니메이션 라이브러리 동적 로드 및 등록
var m_name: String = "zombie"
var anim_lib_path: String = "res://assets/models/monsters/" + m_name + "/" + m_name + "_animations.tres"
var path_to_load: String = ""
if ResourceLoader.exists(anim_lib_path):
path_to_load = anim_lib_path
if path_to_load.is_empty():
return
var lib: AnimationLibrary = load(path_to_load) as AnimationLibrary
if lib and not _model_anim_player.has_animation_library(m_name):
var already_registered: bool = false
for existing_lib_name in _model_anim_player.get_animation_library_list():
if _model_anim_player.get_animation_library(existing_lib_name) == lib:
already_registered = true
break
if not already_registered:
_model_anim_player.add_animation_library(m_name, lib)
print("ZombieMonster: Loaded and registered ", m_name, " animations library successfully.")
else:
print("ZombieMonster: Animation library already registered on model under another name.")
# 초기 Idle 애니메이션 재생 시도
var init_idle: String = _resolve_anim_name(_model_anim_player, m_name, "Idle")
if init_idle != "":
_model_anim_player.play(init_idle)
print("ZombieMonster: Playing initial Idle: ", init_idle)
## 몬스터 자식 메쉬에 zombie_0.png 텍스처를 입히는 재귀 함수
func _apply_zombie_skin(node: Node) -> void:
if node is MeshInstance3D:
var mesh_inst: MeshInstance3D = node as MeshInstance3D
var texture_path: String = "res://assets/models/monsters/zombie/zombie_0.png"
if ResourceLoader.exists(texture_path):
var texture: Texture2D = load(texture_path) as Texture2D
if texture:
var mat: StandardMaterial3D = StandardMaterial3D.new()
mat.albedo_texture = texture
mat.roughness = 0.5
mesh_inst.material_override = mat
for child: Node in node.get_children():
_apply_zombie_skin(child)
## Zombie 걷는 애니메이션 갱신 제어
func _update_monster_animation() -> void:
if not _model_anim_player:
return
var anim_name: String = _resolve_anim_name(_model_anim_player, "zombie", "Walking")
if anim_name != "":
var anim: Animation = _model_anim_player.get_animation(anim_name)
if anim:
anim.loop_mode = Animation.LOOP_LINEAR
if _last_anim_state != "walking":
_last_anim_state = "walking"
_model_anim_player.play(anim_name, -1, 1.2) # 1.2배속 재생
print("ZombieMonster: Playing Walk animation: ", anim_name)
[gd_scene format=3 uid="uid://dfsvswt2g4422"] [gd_scene format=3 uid="uid://dfsvswt2g4422"]
[ext_resource type="Script" uid="uid://bj0j32wc3fvkg" path="res://src/entities/monsters/base_monster.gd" id="1_base_monster"] [ext_resource type="Script" path="res://src/entities/monsters/zombie/zombie_monster.gd" id="1_base_monster"]
[ext_resource type="PackedScene" path="res://src/entities/monsters/zombie/zombie.tscn" id="2_zombie"] [ext_resource type="PackedScene" path="res://src/entities/monsters/zombie/zombie.tscn" id="2_zombie"]
[sub_resource type="SphereShape3D" id="SphereShape3D_collision"] [sub_resource type="SphereShape3D" id="SphereShape3D_collision"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment