summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-04-02 19:07:01 +0800
committerchai <chaifix@163.com>2021-04-02 19:07:01 +0800
commit6b25723ca33a657882588b2cc3a58101bb9d33e6 (patch)
treefa79c1e553f58586e4c659d0e71933f9f6ae3894 /Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules
parentb1276a1b76ac3b87add90e0c6b887d5afea1cfea (diff)
+misc
Diffstat (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules')
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs8
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs13
-rw-r--r--Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs28
3 files changed, 32 insertions, 17 deletions
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 7661a8e..66736d1 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs
@@ -15,10 +15,10 @@ namespace UnityEngine.EventSystems
private BaseEventData m_BaseEventData;
#region 输入系统
- // 如果m_InputOverride不为空就用它,否则用默认的m_DefaultInput
- // 如果要自己实现BaseInput,继承此类并给这个字段赋值
- // StandaloneInputModule没有自定义,直接采用的是BaseInput
- protected BaseInput m_InputOverride;
+ // 如果m_InputOverride不为空就用它,否则用默认的m_DefaultInput
+ // 如果要自己实现BaseInput,继承此类并给这个字段赋值
+ // StandaloneInputModule没有自定义,直接采用的是BaseInput
+ protected BaseInput m_InputOverride;
private BaseInput m_DefaultInput;
public BaseInput input
{
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 9103162..3f93e7a 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs
@@ -4,6 +4,8 @@ using UnityEngine.UI;
namespace UnityEngine.EventSystems
{
+
+ // 会处理触屏和鼠标
public abstract class PointerInputModule : BaseInputModule
{
public const int kMouseLeftId = -1;
@@ -37,7 +39,8 @@ namespace UnityEngine.EventSystems
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();
@@ -60,8 +63,10 @@ namespace UnityEngine.EventSystems
// 用这个触摸数据做射线检测,检测结果在m_RaycastResultCache
eventSystem.RaycastAll(pointerData, m_RaycastResultCache);
-
+
+ // 只取第一个,舍弃其他的
var raycast = FindFirstRaycast(m_RaycastResultCache);
+ Debug.Log("raycast: " + raycast.index);
pointerData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
return pointerData;
@@ -209,6 +214,8 @@ namespace UnityEngine.EventSystems
leftData.scrollDelta = input.mouseScrollDelta;
leftData.button = PointerEventData.InputButton.Left;
eventSystem.RaycastAll(leftData, m_RaycastResultCache);
+
+ // 只要第一个raycast结果
var raycast = FindFirstRaycast(m_RaycastResultCache);
leftData.pointerCurrentRaycast = raycast;
m_RaycastResultCache.Clear();
@@ -224,6 +231,7 @@ namespace UnityEngine.EventSystems
CopyFromTo(leftData, middleData);
middleData.button = PointerEventData.InputButton.Middle;
+ // 设置按键状态
m_MouseState.SetButtonState(PointerEventData.InputButton.Left, StateForMouseButton(0), leftData);
m_MouseState.SetButtonState(PointerEventData.InputButton.Right, StateForMouseButton(1), rightData);
m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, StateForMouseButton(2), middleData);
@@ -252,6 +260,7 @@ namespace UnityEngine.EventSystems
HandlePointerExitAndEnter(pointerEvent, targetGO);
}
+ // 发送drag事件
protected virtual void ProcessDrag(PointerEventData pointerEvent)
{
if (!pointerEvent.IsPointerMoving() ||
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 f9a2f77..7db371a 100644
--- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
+++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/StandaloneInputModule.cs
@@ -141,16 +141,16 @@ namespace UnityEngine.EventSystems
default:
return false;
}
- }
-
- //c 更新鼠标坐标
+ }
+
+ //c! 这里只更新鼠标位置
public override void UpdateModule()
{
- // 如果没有获取焦点,且忽略没有焦点时的事件,返回(除非开启远程连接,否则会这样)
+ // 如果没有获取焦点,且忽略没有焦点时的事件,返回(除非开启远程连接,否则会这样)
if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus())
return;
- // 更新鼠标位置
+ // 更新鼠标位置
m_LastMousePosition = m_MousePosition;
m_MousePosition = input.mousePosition;
}
@@ -201,16 +201,17 @@ namespace UnityEngine.EventSystems
ClearSelection();
}
- //c input module事件处理主入口
+ //c! input module事件处理主入口,每帧更新
public override void Process()
{
- if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus()) // 如果没有获取焦点,不需要处理
+ // 如果没有获取焦点,不需要处理
+ if (!eventSystem.isFocused && ShouldIgnoreEventsOnNoFocus())
return;
//event 给选中的对象发布更新事件
bool usedEvent = SendUpdateEventToSelectedObject();
- // 如果勾上了,发送move , submit, cancel事件
+ // 如果勾上了Send Navigation Events,发送move , submit, cancel事件
if (eventSystem.sendNavigationEvents)
{
if (!usedEvent)
@@ -222,10 +223,10 @@ namespace UnityEngine.EventSystems
// 模拟触摸或鼠标输入
// touch needs to take precedence because of the mouse emulation layer
- usedEvent = ProcessTouchEvents(); //event 发布触摸事件
+ usedEvent = ProcessTouchEvents(); //event 检测屏幕触摸,PC上没有
if(!usedEvent && input.mousePresent)
- ProcessMouseEvent();
+ ProcessMouseEvent(); // 处理鼠标事件
}
//c 触摸事件
@@ -233,6 +234,8 @@ namespace UnityEngine.EventSystems
{
for (int i = 0; i < input.touchCount; ++i) //多点触控
{
+ Debug.Log("Touch");
+
Touch touch = input.GetTouch(i);
if (touch.type == TouchType.Indirect)
@@ -240,7 +243,8 @@ namespace UnityEngine.EventSystems
bool released; // 这是一个手指抬起操作
bool pressed; // 这是一个手指放下操作
- var pointer = GetTouchPointerEventData(touch, out pressed, out released); // 射线检测并保存检测结果
+ //
+ PointerEventData pointer = GetTouchPointerEventData(touch, out pressed, out released); // 射线检测并保存检测结果
// 处理触摸或抬起反馈,已经准备好了被触摸的物体
ProcessTouchPress(pointer, pressed, released);
@@ -495,6 +499,7 @@ namespace UnityEngine.EventSystems
}
}
+ // 每帧发送一个OnUpdateSelected事件
protected bool SendUpdateEventToSelectedObject()
{
if (eventSystem.currentSelectedGameObject == null)
@@ -506,6 +511,7 @@ namespace UnityEngine.EventSystems
return data.used;
}
+ // 处理鼠标按下事件,发送消息,调用回调
/// <summary>
/// Process the current mouse press.
/// </summary>