@tool @icon("res://addons/reedscene/prop/icon/prop_state_icon.svg") class_name ReedPropState extends Node ##状态编号,默认为-1,-1是不可用编号,请修改 @export 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