summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs31
1 files changed, 20 insertions, 11 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs
index 7ddabb8..3456e7b 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs
@@ -9,6 +9,7 @@ namespace UnityEngine.EventSystems
[AddComponentMenu("Event/Event System")]
public class EventSystem : UIBehaviour
{
+ // 获得当前EventSystem挂着的BaseInputModule的派生类,一般来说只会挂一个StandableInputModule
private List<BaseInputModule> m_SystemInputModules = new List<BaseInputModule>();
private BaseInputModule m_CurrentInputModule;
@@ -20,7 +21,7 @@ namespace UnityEngine.EventSystems
private GameObject m_FirstSelected;
[SerializeField]
- private bool m_sendNavigationEvents = true;
+ private bool m_sendNavigationEvents = true; // Should the EventSystem allow navigation events (move / submit / cancel).
public bool sendNavigationEvents
{
@@ -73,14 +74,15 @@ namespace UnityEngine.EventSystems
protected EventSystem()
{}
+ //c 把挂着的input modules加入m_SystemInputModules
public void UpdateModules()
- {
- GetComponents(m_SystemInputModules);
- for (int i = m_SystemInputModules.Count - 1; i >= 0; i--)
+ {
+ // 拿到当前EventSystem下面挂着的inputmodule,通常来说只会挂一个standaloneInputModule
+ GetComponents(m_SystemInputModules);
+ for (int i = m_SystemInputModules.Count - 1; i >= 0; i--)
{
if (m_SystemInputModules[i] && m_SystemInputModules[i].IsActive())
continue;
-
m_SystemInputModules.RemoveAt(i);
}
}
@@ -177,6 +179,7 @@ namespace UnityEngine.EventSystems
private static readonly Comparison<RaycastResult> s_RaycastComparer = RaycastComparer;
+ // 从PointerInputModule.GetTouchPointerEventData()来的触摸数据
public void RaycastAll(PointerEventData eventData, List<RaycastResult> raycastResults)
{
raycastResults.Clear();
@@ -193,11 +196,13 @@ namespace UnityEngine.EventSystems
raycastResults.Sort(s_RaycastComparer);
}
+ //c 是否点击到某个物体
public bool IsPointerOverGameObject()
{
return IsPointerOverGameObject(PointerInputModule.kMouseLeftId);
}
+ //c 是否点击到某个物体
public bool IsPointerOverGameObject(int pointerId)
{
if (m_CurrentInputModule == null)
@@ -233,8 +238,14 @@ namespace UnityEngine.EventSystems
base.OnDisable();
}
+ protected virtual void OnApplicationFocus(bool hasFocus)
+ {
+ m_HasFocus = hasFocus;
+ }
+
private void TickModules()
{
+ // 只有standaloneInputModule一个
for (var i = 0; i < m_SystemInputModules.Count; i++)
{
if (m_SystemInputModules[i] != null)
@@ -242,17 +253,15 @@ namespace UnityEngine.EventSystems
}
}
- protected virtual void OnApplicationFocus(bool hasFocus)
- {
- m_HasFocus = hasFocus;
- }
-
+ //c 事件处理跑在一个update里,以轮训的方式检测输入
protected virtual void Update()
{
if (current != this)
return;
+
TickModules();
+ // 将m_CurrentInputModule设置为m_SystemInputModules第一个可用的module
bool changedModule = false;
for (var i = 0; i < m_SystemInputModules.Count; i++)
{
@@ -267,7 +276,6 @@ namespace UnityEngine.EventSystems
break;
}
}
-
// no event module set... set the first valid one...
if (m_CurrentInputModule == null)
{
@@ -283,6 +291,7 @@ namespace UnityEngine.EventSystems
}
}
+ //c 执行事件处理主入口,通常情况下,如果没有自定义的inputModule,就是走StandaloneInputModule的Process
if (!changedModule && m_CurrentInputModule != null)
m_CurrentInputModule.Process();
}