diff options
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem')
12 files changed, 113 insertions, 47 deletions
diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventData/BaseEventData.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventData/BaseEventData.cs index 62e6cb4..7b5a60d 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventData/BaseEventData.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventData/BaseEventData.cs @@ -2,7 +2,7 @@ namespace UnityEngine.EventSystems { public abstract class AbstractEventData { - protected bool m_Used; + protected bool m_Used; // 当前事件是否被吞(被处理) public virtual void Reset() { 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(); } diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs index 6f4f179..11d1c1c 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs @@ -5,6 +5,9 @@ using UnityEngine.Serialization; namespace UnityEngine.EventSystems { + //c 一个辅助组件,给一个事件添加自定义的回调函数 + //继承了所有接口,效率不高,慎用。只是比较方便 + [AddComponentMenu("Event/Event Trigger")] public class EventTrigger : MonoBehaviour, diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs index bf77717..71fd9f3 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs @@ -233,8 +233,10 @@ namespace UnityEngine.EventSystems } } + //IEventSystemHandler是所有接口的基类 private static readonly ObjectPool<List<IEventSystemHandler>> s_HandlerListPool = new ObjectPool<List<IEventSystemHandler>>(null, l => l.Clear()); + // 向target gameobject发送一个事件,对每个实现了T接口的类执行functor方法(就是接口中定义的回调) public static bool Execute<T>(GameObject target, BaseEventData eventData, EventFunction<T> functor) where T : IEventSystemHandler { var internalHandlers = s_HandlerListPool.Get(); @@ -242,6 +244,8 @@ namespace UnityEngine.EventSystems // if (s_InternalHandlers.Count > 0) // Debug.Log("Executinng " + typeof (T) + " on " + target); + // 拿到实现了T接口的组件,调用对应的方法 + for (var i = 0; i < internalHandlers.Count; i++) { T arg; @@ -289,6 +293,7 @@ namespace UnityEngine.EventSystems return null; } + //c component是否匹配类型T且是否被激活 private static bool ShouldSendToComponent<T>(Component component) where T : IEventSystemHandler { var valid = component is T; @@ -315,8 +320,10 @@ namespace UnityEngine.EventSystems var components = ListPool<Component>.Get(); go.GetComponents(components); + // 遍历所有的组件,找到匹配类型T的 for (var i = 0; i < components.Count; i++) { + // 如果不匹配类型T,跳过这个 if (!ShouldSendToComponent<T>(components[i])) continue; diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInput.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInput.cs index a761057..8d22d04 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInput.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInput.cs @@ -1,5 +1,8 @@ namespace UnityEngine.EventSystems { + + //c 对UnityEngine.Input进行一次简单包装,方便调试 + // 另外如果希望自定义输入,继承这个类,并实现这些属性 public class BaseInput : UIBehaviour { public virtual string compositionString diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs index 7125a4d..7661a8e 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs @@ -14,9 +14,12 @@ namespace UnityEngine.EventSystems private EventSystem m_EventSystem; private BaseEventData m_BaseEventData; - protected BaseInput m_InputOverride; - private BaseInput m_DefaultInput; - +#region 输入系统 + // 如果m_InputOverride不为空就用它,否则用默认的m_DefaultInput + // 如果要自己实现BaseInput,继承此类并给这个字段赋值 + // StandaloneInputModule没有自定义,直接采用的是BaseInput + protected BaseInput m_InputOverride; + private BaseInput m_DefaultInput; public BaseInput input { get @@ -40,12 +43,12 @@ namespace UnityEngine.EventSystems if (m_DefaultInput == null) m_DefaultInput = gameObject.AddComponent<BaseInput>(); } - return m_DefaultInput; } } +#endregion - protected EventSystem eventSystem + protected EventSystem eventSystem { get { return m_EventSystem; } } @@ -54,13 +57,13 @@ namespace UnityEngine.EventSystems { base.OnEnable(); m_EventSystem = GetComponent<EventSystem>(); - m_EventSystem.UpdateModules(); + m_EventSystem.UpdateModules(); // 把此input module加入EventSystem } protected override void OnDisable() { - m_EventSystem.UpdateModules(); - base.OnDisable(); + m_EventSystem.UpdateModules();// 把此input module移出EventSystem + base.OnDisable(); } public abstract void Process(); diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs index d31f433..9103162 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs @@ -16,7 +16,7 @@ namespace UnityEngine.EventSystems protected bool GetPointerData(int id, out PointerEventData data, bool create) { - if (!m_PointerData.TryGetValue(id, out data) && create) + if (!m_PointerData.TryGetValue(id, out data) && create) // 一个池子 { data = new PointerEventData(eventSystem) { @@ -33,29 +33,33 @@ namespace UnityEngine.EventSystems m_PointerData.Remove(data.pointerId); } + //c 根据touch数据得到pointEventData,并且保存raycaster结果 protected PointerEventData GetTouchPointerEventData(Touch input, out bool pressed, out bool released) { PointerEventData pointerData; - var created = GetPointerData(input.fingerId, out pointerData, true); + var created = GetPointerData(input.fingerId, out pointerData, true); // 拿到存储结构,返回是否是新建结构 pointerData.Reset(); - pressed = created || (input.phase == TouchPhase.Began); - released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended); + // pressed和released用来判断抬起或者放下 - if (created) + pressed = created || (input.phase == TouchPhase.Began); // 如果结构是新建的或input phase是bagan,说明是刚按下 + released = (input.phase == TouchPhase.Canceled) || (input.phase == TouchPhase.Ended); // 如果phase是这两种,说明是抬起来了 + + if (created)//如果是新建的,记录下起始位置,否则还保留旧值,下面用来计算delta pointerData.position = input.position; - if (pressed) + if (pressed)//如果是刚按下,delta置为0 pointerData.delta = Vector2.zero; else - pointerData.delta = input.position - pointerData.position; + pointerData.delta = input.position - pointerData.position; // 计算delta - pointerData.position = input.position; + pointerData.position = input.position; // 计算完delta后覆盖 - pointerData.button = PointerEventData.InputButton.Left; + pointerData.button = PointerEventData.InputButton.Left; // 这里不知道为什么 - eventSystem.RaycastAll(pointerData, m_RaycastResultCache); + // 用这个触摸数据做射线检测,检测结果在m_RaycastResultCache + eventSystem.RaycastAll(pointerData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); pointerData.pointerCurrentRaycast = raycast; diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs index ee6f216..f9a2f77 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs @@ -1,3 +1,9 @@ +/* + * StandaloneInputModule : + * PointerInputModule : + * BaseInputModule + */ + using System; using UnityEngine; using UnityEngine.Serialization; @@ -11,6 +17,7 @@ namespace UnityEngine.EventSystems private Vector2 m_LastMoveVector; private int m_ConsecutiveMoveCount = 0; + // 上一个鼠标位置和当前鼠标位置,每帧更新 private Vector2 m_LastMousePosition; private Vector2 m_MousePosition; @@ -136,11 +143,14 @@ namespace UnityEngine.EventSystems } } + //c 更新鼠标坐标 public override void UpdateModule() { + // 如果没有获取焦点,且忽略没有焦点时的事件,返回(除非开启远程连接,否则会这样) if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) return; + // 更新鼠标位置 m_LastMousePosition = m_MousePosition; m_MousePosition = input.mousePosition; } @@ -190,41 +200,49 @@ namespace UnityEngine.EventSystems base.DeactivateModule(); ClearSelection(); } - + + //c input module事件处理主入口 public override void Process() { - if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) + if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) // 如果没有获取焦点,不需要处理 return; + //event 给选中的对象发布更新事件 bool usedEvent = SendUpdateEventToSelectedObject(); + // 如果勾上了,发送move , submit, cancel事件 if (eventSystem.sendNavigationEvents) { if (!usedEvent) - usedEvent |= SendMoveEventToSelectedObject(); + usedEvent |= SendMoveEventToSelectedObject(); //event 键盘方向键移动时给eventSystem选中的对象发布IMoveHandler事件 if (!usedEvent) - SendSubmitEventToSelectedObject(); + SendSubmitEventToSelectedObject(); //event 如果按了相应按键,发布submit或者cancel事件 } + // 模拟触摸或鼠标输入 // touch needs to take precedence because of the mouse emulation layer - if (!ProcessTouchEvents() && input.mousePresent) + usedEvent = ProcessTouchEvents(); //event 发布触摸事件 + + if(!usedEvent && input.mousePresent) ProcessMouseEvent(); } + //c 触摸事件 private bool ProcessTouchEvents() { - for (int i = 0; i < input.touchCount; ++i) + for (int i = 0; i < input.touchCount; ++i) //多点触控 { Touch touch = input.GetTouch(i); if (touch.type == TouchType.Indirect) continue; - bool released; - bool pressed; - var pointer = GetTouchPointerEventData(touch, out pressed, out released); + bool released; // 这是一个手指抬起操作 + bool pressed; // 这是一个手指放下操作 + var pointer = GetTouchPointerEventData(touch, out pressed, out released); // 射线检测并保存检测结果 + // 处理触摸或抬起反馈,已经准备好了被触摸的物体 ProcessTouchPress(pointer, pressed, released); if (!released) @@ -238,10 +256,12 @@ namespace UnityEngine.EventSystems return input.touchCount > 0; } + //c 处理触摸\抬起 protected void ProcessTouchPress(PointerEventData pointerEvent, bool pressed, bool released) { var currentOverGo = pointerEvent.pointerCurrentRaycast.gameObject; + // 触摸反馈 // PointerDown notification if (pressed) { @@ -261,6 +281,7 @@ namespace UnityEngine.EventSystems pointerEvent.pointerEnter = currentOverGo; } + //event IPointerDownHandler // search for the control that will receive the press // if we can't find a press handler set the press // handler to be what would receive a click. @@ -301,6 +322,7 @@ namespace UnityEngine.EventSystems ExecuteEvents.Execute(pointerEvent.pointerDrag, pointerEvent, ExecuteEvents.initializePotentialDrag); } + // 抬起反馈 // PointerUp notification if (released) { @@ -310,14 +332,14 @@ namespace UnityEngine.EventSystems // Debug.Log("KeyCode: " + pointer.eventData.keyCode); // see if we mouse up on the same element that we clicked on... - var pointerUpHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); + var pointerUpHandler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(currentOverGo); // 从这个对象开始往上找,直到一个挂了继承了IPointerClickHandler的组件 // PointerClick and Drop events - if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) + if (pointerEvent.pointerPress == pointerUpHandler && pointerEvent.eligibleForClick) //只有在pointerPress == pointerUpHandler时才会触发click事件 { ExecuteEvents.Execute(pointerEvent.pointerPress, pointerEvent, ExecuteEvents.pointerClickHandler); } - else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) + else if (pointerEvent.pointerDrag != null && pointerEvent.dragging) // 如果两者不相等,触发drop事件 { ExecuteEvents.ExecuteHierarchy(currentOverGo, pointerEvent, ExecuteEvents.dropHandler); } @@ -346,6 +368,8 @@ namespace UnityEngine.EventSystems if (eventSystem.currentSelectedGameObject == null) return false; + // 发布submit事件或者cancel事件 + var data = GetBaseEventData(); if (input.GetButtonDown(m_SubmitButton)) ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.submitHandler); @@ -386,15 +410,16 @@ namespace UnityEngine.EventSystems float time = Time.unscaledTime; Vector2 movement = GetRawMoveVector(); - if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f)) + if (Mathf.Approximately(movement.x, 0f) && Mathf.Approximately(movement.y, 0f)) // 如果键盘方向键没动,返回 { m_ConsecutiveMoveCount = 0; return false; } + //allow即是否允许发布事件 // If user pressed key again, always allow event bool allow = input.GetButtonDown(m_HorizontalAxis) || input.GetButtonDown(m_VerticalAxis); - bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0); + bool similarDir = (Vector2.Dot(movement, m_LastMoveVector) > 0); // 和之前的方向是否夹角在90°以内,如果是的话说明很接近 if (!allow) { // Otherwise, user held down key or axis. @@ -408,15 +433,18 @@ namespace UnityEngine.EventSystems if (!allow) return false; + // 发布IMoveHandler事件 + // Debug.Log(m_ProcessingEvent.rawType + " axis:" + m_AllowAxisEvents + " value:" + "(" + x + "," + y + ")"); var axisEventData = GetAxisEventData(movement.x, movement.y, 0.6f); if (axisEventData.moveDir != MoveDirection.None) { - ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); + ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisEventData, ExecuteEvents.moveHandler); // IMoveHandler.OnMove if (!similarDir) m_ConsecutiveMoveCount = 0; m_ConsecutiveMoveCount++; + m_PrevActionTime = time; m_LastMoveVector = movement; } @@ -473,6 +501,7 @@ namespace UnityEngine.EventSystems return false; var data = GetBaseEventData(); + //event 向eventSystem当前选中的gameobject发布一个更新事件IUpdateSelectedHandler,比如inputfield ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, data, ExecuteEvents.updateSelectedHandler); return data.used; } diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs index 4f04f42..58ac97c 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/TouchInputModule.cs @@ -4,13 +4,15 @@ using UnityEngine.Serialization; namespace UnityEngine.EventSystems { - [Obsolete("TouchInputModule is no longer required as Touch input is now handled in StandaloneInputModule.")] + //c TouchInputModule被废弃了,统一在standaloneInputModule中处理 + [Obsolete("TouchInputModule is no longer required as Touch input is now handled in StandaloneInputModule.")] [AddComponentMenu("Event/Touch Input Module")] public class TouchInputModule : PointerInputModule { protected TouchInputModule() {} + // 触摸点位置 private Vector2 m_LastMousePosition; private Vector2 m_MousePosition; @@ -31,6 +33,7 @@ namespace UnityEngine.EventSystems set { m_ForceModuleActive = value; } } + //c 更新鼠标(触摸点)位置 public override void UpdateModule() { m_LastMousePosition = m_MousePosition; diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs index 12a339b..666ef8d 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs @@ -1,5 +1,6 @@ namespace UnityEngine.EventSystems { + // UGUI射线检测结果 public struct RaycastResult { private GameObject m_GameObject; // Game object hit by the raycast diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs index 783cf95..6346938 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/Physics2DRaycaster.cs @@ -13,6 +13,7 @@ namespace UnityEngine.EventSystems protected Physics2DRaycaster() {} + // 发射线 public override void Raycast(PointerEventData eventData, List<RaycastResult> resultAppendList) { if (eventCamera == null) diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs index 2b4bea3..c7d431c 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/PhysicsRaycaster.cs @@ -3,6 +3,8 @@ using UnityEngine.UI; namespace UnityEngine.EventSystems { + //c 投射3D物体的相机挂这个脚本 + /// <summary> /// Simple event system using physics raycasts. /// </summary> @@ -66,7 +68,7 @@ namespace UnityEngine.EventSystems { ray = eventCamera.ScreenPointToRay(eventData.position); // compensate far plane distance - see MouseEvents.cs - float projectionDirection = ray.direction.z; + float projectionDirection = ray.direction.z; // ray.direction是归一化了的 distanceToClipPlane = Mathf.Approximately(0.0f, projectionDirection) ? Mathf.Infinity : Mathf.Abs((eventCamera.farClipPlane - eventCamera.nearClipPlane) / projectionDirection); @@ -78,6 +80,7 @@ namespace UnityEngine.EventSystems if (eventCamera == null || !eventCamera.pixelRect.Contains(eventData.position)) return; + // 根据触摸数据拿到射线 Ray ray; float distanceToClipPlane; ComputeRayAndDistance(eventData, out ray, out distanceToClipPlane); |