| 69 | */ |
| 70 | @ECSSystem('InputSystem', { updateOrder: -1000 }) // 最先更新 | Update first |
| 71 | export class InputSystem extends EntitySystem { |
| 72 | private _inputManager: InputManager; |
| 73 | private _inputSubsystem: IPlatformInputSubsystem | null = null; |
| 74 | private _disableInEditor: boolean; |
| 75 | private _isInitialized: boolean = false; |
| 76 | |
| 77 | constructor(config: InputSystemConfig = {}) { |
| 78 | // 不匹配任何实体,只用于生命周期 | Match no entities, only for lifecycle |
| 79 | super(Matcher.nothing()); |
| 80 | |
| 81 | this._inputManager = config.inputManager ?? Input; |
| 82 | this._disableInEditor = config.disableInEditor ?? false; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * 设置平台输入子系统 |
| 87 | * Set platform input subsystem |
| 88 | * |
| 89 | * @param subsystem 平台输入子系统 | Platform input subsystem |
| 90 | */ |
| 91 | setInputSubsystem(subsystem: IPlatformInputSubsystem): void { |
| 92 | // 如果已有子系统,先解绑 | Unbind if already has subsystem |
| 93 | if (this._inputSubsystem && this._isInitialized) { |
| 94 | this.unbindEvents(); |
| 95 | } |
| 96 | |
| 97 | this._inputSubsystem = subsystem; |
| 98 | |
| 99 | // 如果已初始化,立即绑定 | Bind immediately if initialized |
| 100 | if (this._isInitialized) { |
| 101 | this.bindEvents(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * 获取输入管理器 |
| 107 | * Get input manager |
| 108 | */ |
| 109 | get inputManager(): InputManager { |
| 110 | return this._inputManager; |
| 111 | } |
| 112 | |
| 113 | protected override onInitialize(): void { |
| 114 | this._isInitialized = true; |
| 115 | |
| 116 | if (this._inputSubsystem) { |
| 117 | this.bindEvents(); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * 绑定平台输入事件 |
| 123 | * Bind platform input events |
| 124 | */ |
| 125 | private bindEvents(): void { |
| 126 | if (!this._inputSubsystem) return; |
| 127 | |
| 128 | const sub = this._inputSubsystem; |
nothing calls this directly
no test coverage detected