State machine rework
This commit is contained in:
parent
3f99f1b8dd
commit
87919ed890
25 changed files with 102 additions and 76 deletions
|
|
@ -23,7 +23,6 @@ func on_transition_required(to: StringName):
|
|||
return
|
||||
|
||||
change_state(states[to])
|
||||
change_state_to_name.rpc(to)
|
||||
|
||||
func change_state(to_state: State) -> void:
|
||||
if current_state != null:
|
||||
|
|
@ -31,19 +30,6 @@ func change_state(to_state: State) -> void:
|
|||
current_state = to_state
|
||||
current_state.enter()
|
||||
|
||||
@rpc("authority","call_local","reliable")
|
||||
func change_state_to_name(to_name: StringName):
|
||||
if current_state != null:
|
||||
current_state.exit()
|
||||
current_state = states[to_name]
|
||||
current_state.enter()
|
||||
|
||||
@rpc("authority","call_local","unreliable")
|
||||
func clear_state():
|
||||
if current_state == null:
|
||||
return
|
||||
current_state.exit()
|
||||
current_state = null
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_state == null:
|
||||
|
|
|
|||
|
|
@ -7,8 +7,21 @@ class_name State
|
|||
|
||||
signal transition(to: StringName)
|
||||
|
||||
@abstract func enter() -> void
|
||||
@abstract func exit() -> void
|
||||
@abstract func _enter() -> void
|
||||
@abstract func _exit() -> void
|
||||
|
||||
@rpc("authority","call_remote","reliable")
|
||||
func enter():
|
||||
_enter()
|
||||
if is_multiplayer_authority():
|
||||
enter.rpc()
|
||||
|
||||
@rpc("authority","call_remote","reliable")
|
||||
func exit():
|
||||
_exit()
|
||||
if is_multiplayer_authority():
|
||||
exit.rpc()
|
||||
|
||||
func update(delta: float) -> void:
|
||||
pass
|
||||
func physics_update(delta: float) -> void:
|
||||
|
|
|
|||
|
|
@ -4,12 +4,11 @@ class_name SubStateMachine
|
|||
|
||||
@export var enter_state: State
|
||||
|
||||
func enter() -> void:
|
||||
func _enter() -> void:
|
||||
change_state(enter_state)
|
||||
|
||||
func exit() -> void:
|
||||
if is_multiplayer_authority():
|
||||
clear_state.rpc()
|
||||
func _exit() -> void:
|
||||
current_state.exit()
|
||||
|
||||
func update(delta: float) -> void:
|
||||
if current_state == null:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue