Scene管理器V0.3
This commit is contained in:
parent
1199bc736a
commit
93aa31c38e
|
|
@ -0,0 +1,21 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
@onready var act_manager: ActManager = $ReedScene/ActManager
|
||||||
|
|
||||||
|
var s := 1
|
||||||
|
|
||||||
|
func _unhandled_input(event: InputEvent) -> void:
|
||||||
|
if act_manager == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
if event.is_action_pressed("ui_right"):
|
||||||
|
s = clampi(s+1,0,2)
|
||||||
|
act_manager.switch_act_with_id(s)
|
||||||
|
|
||||||
|
elif event.is_action_pressed("ui_left"):
|
||||||
|
s = clampi(s-1,0,2)
|
||||||
|
act_manager.switch_act_with_id(s)
|
||||||
|
elif event.is_action_pressed("ui_up"):
|
||||||
|
act_manager.switch_act_with_id(3)
|
||||||
|
elif event.is_action_pressed("ui_down"):
|
||||||
|
act_manager.switch_act_with_id(4)
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://ds6jy3s0hhmwt
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -12,10 +12,6 @@ var door_state_id: int = 0
|
||||||
##门移动动画结束广播,输出0为关闭,输出1为开启
|
##门移动动画结束广播,输出0为关闭,输出1为开启
|
||||||
signal door_move_finished(int)
|
signal door_move_finished(int)
|
||||||
|
|
||||||
func _ready() -> void:
|
|
||||||
await get_tree().create_timer(.2).timeout
|
|
||||||
$PropComponent.change_state(1,true)
|
|
||||||
|
|
||||||
##开门
|
##开门
|
||||||
func door_open() -> void:
|
func door_open() -> void:
|
||||||
door_move(door_open_poser)
|
door_move(door_open_poser)
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,49 @@ var _gen_empty_act: Callable = Callable(self, "_editor_generate_empty_act")
|
||||||
var max_index := max(prop_state_map.size() - 1, 0)
|
var max_index := max(prop_state_map.size() - 1, 0)
|
||||||
init_act_id = clamp(value, 0, max_index)
|
init_act_id = clamp(value, 0, max_index)
|
||||||
|
|
||||||
|
## ====================
|
||||||
|
## Private Field
|
||||||
|
## ====================
|
||||||
|
var _current_act: Act = null
|
||||||
|
var _current_act_id: int = -1
|
||||||
signal act_changed(from_act_id: int, to_act_id: int)
|
signal act_changed(from_act_id: int, to_act_id: int)
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
##初始默认把act 切换到Default状态
|
||||||
|
switch_act_with_id(0)
|
||||||
|
|
||||||
|
##通过ID切换act
|
||||||
|
func switch_act_with_id(act_id: int) -> void:
|
||||||
|
if not prop_state_map.has(act_id):
|
||||||
|
push_warning("[ActManager] Act id not found: %d" % act_id)
|
||||||
|
return
|
||||||
|
|
||||||
|
var act := prop_state_map[act_id]
|
||||||
|
_switch_act_internal(act, act_id)
|
||||||
|
|
||||||
|
##内部通过ID和Act来切换状态
|
||||||
|
func _switch_act_internal(act: Act, act_id: int) -> void:
|
||||||
|
if act == null:
|
||||||
|
return
|
||||||
|
|
||||||
|
var from_id := _current_act_id
|
||||||
|
|
||||||
|
_current_act = act
|
||||||
|
_current_act_id = act_id
|
||||||
|
|
||||||
|
for pid in act.prop_state_map.keys():
|
||||||
|
var single := act.prop_state_map[pid]
|
||||||
|
if single == null:
|
||||||
|
continue
|
||||||
|
|
||||||
|
var prop := _find_prop_by_id(pid)
|
||||||
|
if prop == null:
|
||||||
|
continue
|
||||||
|
|
||||||
|
prop.change_state(single.state_id, single.use_trans)
|
||||||
|
|
||||||
|
emit_signal("act_changed", from_id, act_id)
|
||||||
|
|
||||||
##用来扫描prop
|
##用来扫描prop
|
||||||
func _scan_scene_for_props(scene_root: Node) -> Dictionary:
|
func _scan_scene_for_props(scene_root: Node) -> Dictionary:
|
||||||
var result := {}
|
var result := {}
|
||||||
|
|
@ -158,3 +199,27 @@ func _find_next_free_act_id() -> int:
|
||||||
while prop_state_map.has(id):
|
while prop_state_map.has(id):
|
||||||
id += 1
|
id += 1
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
##通过ID寻找Prop
|
||||||
|
func _find_prop_by_id(prop_id: int) -> PropComponent:
|
||||||
|
var scene := _get_owner_scene()
|
||||||
|
if scene == null:
|
||||||
|
return null
|
||||||
|
|
||||||
|
var props_root := scene.get_node_or_null(scene.props_root_path)
|
||||||
|
if props_root == null:
|
||||||
|
return null
|
||||||
|
|
||||||
|
return _find_prop_recursive(props_root, prop_id)
|
||||||
|
|
||||||
|
##递归的寻找Prop
|
||||||
|
func _find_prop_recursive(node: Node, prop_id: int) -> PropComponent:
|
||||||
|
if node is PropComponent and node.prop_id == prop_id:
|
||||||
|
return node as PropComponent
|
||||||
|
|
||||||
|
for child in node.get_children():
|
||||||
|
var r := _find_prop_recursive(child, prop_id)
|
||||||
|
if r != null:
|
||||||
|
return r
|
||||||
|
|
||||||
|
return null
|
||||||
|
|
|
||||||
|
|
@ -2,3 +2,4 @@ class_name SingleAct extends Resource
|
||||||
|
|
||||||
@export var state_id: int = 0
|
@export var state_id: int = 0
|
||||||
@export var use_trans: bool = false
|
@export var use_trans: bool = false
|
||||||
|
@export var context: Dictionary
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,6 @@ func _on_act_changed(from_act: int, to_act: int) -> void:
|
||||||
if debug_log:
|
if debug_log:
|
||||||
print("[ReedScene] Act changed:", from_act, "->", to_act)
|
print("[ReedScene] Act changed:", from_act, "->", to_act)
|
||||||
|
|
||||||
for prop_comp in _prop_map.values():
|
|
||||||
prop_comp.on_act_changed(from_act, to_act)
|
|
||||||
|
|
||||||
##进入场景树,自动添加ActManager,PropsRoot,和SceneManager
|
##进入场景树,自动添加ActManager,PropsRoot,和SceneManager
|
||||||
func _editor_ensure_scene_nodes() -> void:
|
func _editor_ensure_scene_nodes() -> void:
|
||||||
_editor_ensure_node(SCENE_MANAGER_NAME, SceneManager)
|
_editor_ensure_node(SCENE_MANAGER_NAME, SceneManager)
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,35 @@ V0.1
|
||||||
|
|
||||||
- 添加了基础的Act,Prop,Scene的概念。
|
- 添加了基础的Act,Prop,Scene的概念。
|
||||||
|
|
||||||
|
V0.2
|
||||||
|
|
||||||
|
- 实现了通过切换PropState来切换Prop的功能
|
||||||
|
|
||||||
|
V0.3
|
||||||
|
|
||||||
|
- 实现了通过切换ActID来切换Act的功能
|
||||||
|
|
||||||
## 更新计划
|
## 更新计划
|
||||||
|
|
||||||
V0.1
|
V0.1
|
||||||
|
|
||||||
主要的工作是搭建一个插件的基本架构
|
主要的工作是搭建一个插件的基本架构
|
||||||
|
|
||||||
- [x] 角色墙滑
|
V0.2
|
||||||
|
|
||||||
|
完善PropState的功能
|
||||||
|
|
||||||
|
V0.3
|
||||||
|
|
||||||
|
完善Act的功能
|
||||||
|
|
||||||
|
- Act管理器,负责切换Act,广播通知当前Scene下属的Prop进行状态切换。
|
||||||
|
- Act的快捷创建各种不同的Act。
|
||||||
|
|
||||||
|
V0.4
|
||||||
|
|
||||||
|
完善Scene的功能
|
||||||
|
|
||||||
|
- Scene具有全局唯一的ID,
|
||||||
|
- SceneManager可以切换Act,也可以切换PropState,也可以通过ID获取到Prop
|
||||||
|
-
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue