godot-plateformer/addons/reedscene/prop/PropState.gd

57 lines
1.5 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
@icon("res://addons/reedscene/prop/icon/prop_state_icon.svg")
class_name ReedPropState extends Node
##状态编号,默认为-1-1是不可用编号状态编号由StateManager发布不可以自己修改。
@export_custom(PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY) var state_id: int = -1
##该State的信息是否需要被存入Save中
@export var save_game: bool = false
##预装的一些Effect可以用来对State进行一些初始化
@export var effects: Array[ReedPropEffect] = []
##State的拥有者
var _owner
##State的prop comp
var _owner_prop_comp
## 是否已经初始化
var _inited: bool = false
##初始化State
func init(owner: Node, prop_comp: Node) -> bool:
# 防止重复初始化
if _inited:
push_warning("ReedPropState [%s] already initialized." % name)
return false
if owner == null:
push_error("ReedPropState [%s] init failed: owner is null." % name)
return false
if prop_comp == null:
push_error("ReedPropState [%s] init failed: prop_comp is null." % name)
return false
_owner = owner
_owner_prop_comp = prop_comp
_inited = true
return true
##是否可以进入此状态,默认为真
func can_enter(_current: ReedPropState, _ctx: Dictionary) -> bool:
return true
##State进入
func on_enter(_from: ReedPropState, _ctx: Dictionary) -> void:
if not _inited:
push_error("ReedPropState [%s] entered before init!" % name)
return
for e in effects:
e.apply(_owner, _owner_prop_comp, _ctx)
##State退出
func on_exit(_to: ReedPropState, _ctx: Dictionary) -> void:
pass