diff --git a/system/button_system.go b/system/button_system.go index 5fa86b5..112714a 100644 --- a/system/button_system.go +++ b/system/button_system.go @@ -24,11 +24,11 @@ var ( ) type ButtonSystem struct { - query *ecs.Query + selfRestQuery *ecs.Query } func NewButtonSystem() *ButtonSystem { - return &ButtonSystem{query: ecs.NewQuery(filter.Contains(ButtonStateComponent))} + return &ButtonSystem{selfRestQuery: ecs.NewQuery(filter.Contains(ButtonStateComponent, ButtonSelfRestTag))} } func NewButtonState() *ButtonState { return &ButtonState{Ckd: false} @@ -36,11 +36,9 @@ func NewButtonState() *ButtonState { // Update world 执行 func (me *ButtonSystem) Update(w ecs.World) { - me.query.Each(w, func(e *ecs.Entry) { - if e.HasComponent(ButtonSelfRestTag) { - state := ButtonStateComponent.Get(e) - me.calculateSelfRest(w, e, state) - } + me.selfRestQuery.Each(w, func(e *ecs.Entry) { + state := ButtonStateComponent.Get(e) + me.calculateSelfRest(w, e, state) }) }