privatevoidTickModules() { var systemInputModulesCount = m_SystemInputModules.Count; for (var i = 0; i < systemInputModulesCount; i++) { if (m_SystemInputModules[i] != null) m_SystemInputModules[i].UpdateModule(); } } }
在每一帧中首先会确保Tick的是当前的组件,之后对所有存储的InputModule进行Tick。
InputSystemUIModule并没有重写UpdateModule()函数。
验证、切换当前生效的InputModule
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
bool changedModule = false; var systemInputModulesCount = m_SystemInputModules.Count; // 检查当前InputModule是否被切换 for (var i = 0; i < systemInputModulesCount; i++) { var module = m_SystemInputModules[i]; if (module.IsModuleSupported() && module.ShouldActivateModule()) { if (m_CurrentInputModule != module) { // 切换InputModule ChangeEventModule(module); changedModule = true; } break; } }
privatevoidChangeEventModule(BaseInputModule module) { if (m_CurrentInputModule == module) return;
if (m_CurrentInputModule != null) m_CurrentInputModule.DeactivateModule();
if (module != null) module.ActivateModule(); m_CurrentInputModule = module; }
假如此时当前的InputModule没有设置的话,就会进入设置流程:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// no event module set... set the first valid one... if (m_CurrentInputModule == null) { for (var i = 0; i < systemInputModulesCount; i++) { var module = m_SystemInputModules[i]; if (module.IsModuleSupported()) { ChangeEventModule(module); changedModule = true; break; } } }
publicoverridevoidProcess() { // 处理过期的Pointer if (m_NeedToPurgeStalePointers) PurgeStalePointers();
// Reset devices of changes since we don't want to spool up changes once we gain focus. if (!eventSystem.isFocused && !shouldIgnoreFocus) { for (var i = 0; i < m_PointerStates.length; ++i) m_PointerStates[i].OnFrameFinished(); } else { // 处理NavigationInput // ... // Pointer input. for (var i = 0; i < m_PointerStates.length; i++) { refvar state = refGetPointerStateForIndex(i);
ProcessPointer(ref state);
// If it's a touch and the touch has ended, release the pointer state. // NOTE: We defer this by one frame such that OnPointerUp happens in the frame of release // and OnPointerExit happens one frame later. This is so that IsPointerOverGameObject() // stays true for the touch in the frame of release (see UI_TouchPointersAreKeptForOneFrameAfterRelease). if (state.pointerType == UIPointerType.Touch && !state.leftButton.isPressed && !state.leftButton.wasReleasedThisFrame) { RemovePointerAtIndex(i); --i; continue; }