From ff5a3fbf31db349db11bbc5c60ba199d26780f19 Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 7 Apr 2021 15:38:57 +0800 Subject: =?UTF-8?q?*=E7=A7=BB=E5=8A=A8=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UnityEngine.UI/EventSystem/EventHandle.cs | 11 - .../UnityEngine.UI/EventSystem/EventHandle.cs.meta | 13 - .../UnityEngine.UI/EventSystem/EventHandler.meta | 8 + .../EventSystem/EventHandler/EventHandle.cs | 11 + .../EventSystem/EventHandler/EventHandle.cs.meta | 11 + .../EventSystem/EventHandler/EventInterfaces.cs | 91 +++++ .../EventHandler/EventInterfaces.cs.meta | 11 + .../EventSystem/EventHandler/EventSystem.cs | 328 ++++++++++++++++++ .../EventSystem/EventHandler/EventSystem.cs.meta | 11 + .../EventSystem/EventHandler/EventTrigger.cs | 159 +++++++++ .../EventSystem/EventHandler/EventTrigger.cs.meta | 11 + .../EventSystem/EventHandler/EventTriggerType.cs | 29 ++ .../EventHandler/EventTriggerType.cs.meta | 11 + .../EventSystem/EventHandler/ExecuteEvents.cs | 368 +++++++++++++++++++++ .../EventSystem/EventHandler/ExecuteEvents.cs.meta | 11 + .../EventSystem/EventHandler/MoveDirection.cs | 11 + .../EventSystem/EventHandler/MoveDirection.cs.meta | 13 + .../UnityEngine.UI/EventSystem/EventInterfaces.cs | 91 ----- .../EventSystem/EventInterfaces.cs.meta | 13 - .../UnityEngine.UI/EventSystem/EventSystem.cs | 324 ------------------ .../UnityEngine.UI/EventSystem/EventSystem.cs.meta | 13 - .../UnityEngine.UI/EventSystem/EventTrigger.cs | 159 --------- .../EventSystem/EventTrigger.cs.meta | 13 - .../UnityEngine.UI/EventSystem/EventTriggerType.cs | 29 -- .../EventSystem/EventTriggerType.cs.meta | 13 - .../UnityEngine.UI/EventSystem/ExecuteEvents.cs | 368 --------------------- .../EventSystem/ExecuteEvents.cs.meta | 13 - .../EventSystem/InputModules/BaseInputModule.cs | 3 + .../EventSystem/InputModules/PointerInputModule.cs | 1 + .../UnityEngine.UI/EventSystem/MoveDirection.cs | 11 - .../EventSystem/MoveDirection.cs.meta | 13 - .../UnityEngine.UI/EventSystem/RaycastResult.cs | 65 ---- .../EventSystem/RaycastResult.cs.meta | 13 - .../UnityEngine.UI/EventSystem/RaycasterManager.cs | 29 -- .../EventSystem/RaycasterManager.cs.meta | 13 - .../EventSystem/Raycasters/RaycastResult.cs | 65 ++++ .../EventSystem/Raycasters/RaycastResult.cs.meta | 11 + .../EventSystem/Raycasters/RaycasterManager.cs | 29 ++ .../Raycasters/RaycasterManager.cs.meta | 11 + 39 files changed, 1204 insertions(+), 1204 deletions(-) delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs.meta delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs delete mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs.meta create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs create mode 100644 Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs.meta (limited to 'Assets/uGUI-2017.1/UnityEngine.UI/EventSystem') diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs deleted file mode 100644 index 977514f..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace UnityEngine.EventSystems -{ - [Flags] - public enum EventHandle - { - Unused = 0, - Used = 1 - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs.meta deleted file mode 100644 index 484a7cd..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandle.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 5919f1bb652e12b46a1abbf58653b28c -timeCreated: 1602119378 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler.meta new file mode 100644 index 0000000..732637d --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 146a9b1a2f14b51468a9381c1562257e +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs new file mode 100644 index 0000000..977514f --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs @@ -0,0 +1,11 @@ +using System; + +namespace UnityEngine.EventSystems +{ + [Flags] + public enum EventHandle + { + Unused = 0, + Used = 1 + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs.meta new file mode 100644 index 0000000..1e2c52f --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventHandle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0c5751e0f52a2d9459e76555a888ad06 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs new file mode 100644 index 0000000..b808e6c --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs @@ -0,0 +1,91 @@ +namespace UnityEngine.EventSystems +{ + public interface IEventSystemHandler + { + } + + public interface IPointerEnterHandler : IEventSystemHandler + { + void OnPointerEnter(PointerEventData eventData); + } + + public interface IPointerExitHandler : IEventSystemHandler + { + void OnPointerExit(PointerEventData eventData); + } + + public interface IPointerDownHandler : IEventSystemHandler + { + void OnPointerDown(PointerEventData eventData); + } + + public interface IPointerUpHandler : IEventSystemHandler + { + void OnPointerUp(PointerEventData eventData); + } + + public interface IPointerClickHandler : IEventSystemHandler + { + void OnPointerClick(PointerEventData eventData); + } + + public interface IBeginDragHandler : IEventSystemHandler + { + void OnBeginDrag(PointerEventData eventData); + } + + public interface IInitializePotentialDragHandler : IEventSystemHandler + { + void OnInitializePotentialDrag(PointerEventData eventData); + } + + public interface IDragHandler : IEventSystemHandler + { + void OnDrag(PointerEventData eventData); + } + + public interface IEndDragHandler : IEventSystemHandler + { + void OnEndDrag(PointerEventData eventData); + } + + public interface IDropHandler : IEventSystemHandler + { + void OnDrop(PointerEventData eventData); + } + + public interface IScrollHandler : IEventSystemHandler + { + void OnScroll(PointerEventData eventData); + } + + public interface IUpdateSelectedHandler : IEventSystemHandler + { + void OnUpdateSelected(BaseEventData eventData); + } + + public interface ISelectHandler : IEventSystemHandler + { + void OnSelect(BaseEventData eventData); + } + + public interface IDeselectHandler : IEventSystemHandler + { + void OnDeselect(BaseEventData eventData); + } + + public interface IMoveHandler : IEventSystemHandler + { + void OnMove(AxisEventData eventData); + } + + public interface ISubmitHandler : IEventSystemHandler + { + void OnSubmit(BaseEventData eventData); + } + + public interface ICancelHandler : IEventSystemHandler + { + void OnCancel(BaseEventData eventData); + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs.meta new file mode 100644 index 0000000..2a369ae --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventInterfaces.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7bb73ff56f2f85b4ca62f8cb5ea59840 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs new file mode 100644 index 0000000..1440547 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs @@ -0,0 +1,328 @@ +using System; +using System.Collections.Generic; +using System.Text; +using UnityEngine; +using UnityEngine.Serialization; + +namespace UnityEngine.EventSystems +{ + [AddComponentMenu("Event/Event System")] + public class EventSystem : UIBehaviour + { + // 获得当前EventSystem挂着的BaseInputModule的派生类,一般来说只会挂一个StandableInputModule + private List m_SystemInputModules = new List(); + + private BaseInputModule m_CurrentInputModule; + + public static EventSystem current { get; set; } + + [SerializeField] + [FormerlySerializedAs("m_Selected")] + private GameObject m_FirstSelected; + + [SerializeField] + private bool m_sendNavigationEvents = true; // Should the EventSystem allow navigation events (move / submit / cancel). + + public bool sendNavigationEvents + { + get { return m_sendNavigationEvents; } + set { m_sendNavigationEvents = value; } + } + + [SerializeField] + private int m_DragThreshold = 5; + public int pixelDragThreshold + { + get { return m_DragThreshold; } + set { m_DragThreshold = value; } + } + + private GameObject m_CurrentSelected; + + public BaseInputModule currentInputModule + { + get { return m_CurrentInputModule; } + } + + /// + /// Only one object can be selected at a time. Think: controller-selected button. + /// + public GameObject firstSelectedGameObject + { + get { return m_FirstSelected; } + set { m_FirstSelected = value; } + } + + public GameObject currentSelectedGameObject + { + get { return m_CurrentSelected; } + } + + [Obsolete("lastSelectedGameObject is no longer supported")] + public GameObject lastSelectedGameObject + { + get { return null; } + } + + private bool m_HasFocus = true; + + public bool isFocused + { + get { return m_HasFocus; } + } + + protected EventSystem() + {} + + //c 把挂着的input modules加入m_SystemInputModules + public void UpdateModules() + { + // 拿到当前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); + } + } + + private bool m_SelectionGuard; + public bool alreadySelecting + { + get { return m_SelectionGuard; } + } + + public void SetSelectedGameObject(GameObject selected, BaseEventData pointer) + { + if (m_SelectionGuard) + { + Debug.LogError("Attempting to select " + selected + "while already selecting an object."); + return; + } + + m_SelectionGuard = true; + if (selected == m_CurrentSelected) + { + m_SelectionGuard = false; + return; + } + + // Debug.Log("Selection: new (" + selected + ") old (" + m_CurrentSelected + ")"); + ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.deselectHandler); + m_CurrentSelected = selected; + ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.selectHandler); + m_SelectionGuard = false; + } + + private BaseEventData m_DummyData; + private BaseEventData baseEventDataCache + { + get + { + if (m_DummyData == null) + m_DummyData = new BaseEventData(this); + + return m_DummyData; + } + } + + public void SetSelectedGameObject(GameObject selected) + { + SetSelectedGameObject(selected, baseEventDataCache); + } + + private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs) + { + if (lhs.module != rhs.module) + { + var lhsEventCamera = lhs.module.eventCamera; + var rhsEventCamera = rhs.module.eventCamera; + if (lhsEventCamera != null && rhsEventCamera != null && lhsEventCamera.depth != rhsEventCamera.depth) + { + // need to reverse the standard compareTo + if (lhsEventCamera.depth < rhsEventCamera.depth) + return 1; + if (lhsEventCamera.depth == rhsEventCamera.depth) + return 0; + + return -1; + } + + if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority) + return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority); + + if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority) + return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority); + } + + if (lhs.sortingLayer != rhs.sortingLayer) + { + // Uses the layer value to properly compare the relative order of the layers. + var rid = SortingLayer.GetLayerValueFromID(rhs.sortingLayer); + var lid = SortingLayer.GetLayerValueFromID(lhs.sortingLayer); + return rid.CompareTo(lid); + } + + + if (lhs.sortingOrder != rhs.sortingOrder) + return rhs.sortingOrder.CompareTo(lhs.sortingOrder); + + if (lhs.depth != rhs.depth) + return rhs.depth.CompareTo(lhs.depth); + + if (lhs.distance != rhs.distance) + return lhs.distance.CompareTo(rhs.distance); + + return lhs.index.CompareTo(rhs.index); + } + + #region 射线检测 + + private static readonly Comparison s_RaycastComparer = RaycastComparer; + + // 从PointerInputModule.GetTouchPointerEventData()来的触摸数据 + public void RaycastAll(PointerEventData eventData, List raycastResults) + { + raycastResults.Clear(); + //包括场景中所有的raycaster + var modules = RaycasterManager.GetRaycasters(); + for (int i = 0; i < modules.Count; ++i) + { + var module = modules[i]; + if (module == null || !module.IsActive()) + continue; + + module.Raycast(eventData, raycastResults); + } + + raycastResults.Sort(s_RaycastComparer); + } + + #endregion + + //c 是否点击到某个物体 + public bool IsPointerOverGameObject() + { + return IsPointerOverGameObject(PointerInputModule.kMouseLeftId); + } + + //c 是否点击到某个物体 + public bool IsPointerOverGameObject(int pointerId) + { + if (m_CurrentInputModule == null) + return false; + + return m_CurrentInputModule.IsPointerOverGameObject(pointerId); + } + + protected override void OnEnable() + { + base.OnEnable(); + if (EventSystem.current == null) + EventSystem.current = this; +#if UNITY_EDITOR + else + { + Debug.LogWarning("Multiple EventSystems in scene... this is not supported"); + } +#endif + } + + protected override void OnDisable() + { + if (m_CurrentInputModule != null) + { + m_CurrentInputModule.DeactivateModule(); + m_CurrentInputModule = null; + } + + if (EventSystem.current == this) + EventSystem.current = null; + + 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) + m_SystemInputModules[i].UpdateModule(); + } + } + + //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++) + { + var module = m_SystemInputModules[i]; + if (module.IsModuleSupported() && module.ShouldActivateModule()) + { + if (m_CurrentInputModule != module) + { + ChangeEventModule(module); + changedModule = true; + } + break; + } + } + // no event module set... set the first valid one... + if (m_CurrentInputModule == null) + { + for (var i = 0; i < m_SystemInputModules.Count; i++) + { + var module = m_SystemInputModules[i]; + if (module.IsModuleSupported()) + { + ChangeEventModule(module); + changedModule = true; + break; + } + } + } + + //c! 执行事件处理主入口,通常情况下,如果没有自定义的inputModule,就是走StandaloneInputModule的Process + if (!changedModule && m_CurrentInputModule != null) + m_CurrentInputModule.Process(); + } + + private void ChangeEventModule(BaseInputModule module) + { + if (m_CurrentInputModule == module) + return; + + if (m_CurrentInputModule != null) + m_CurrentInputModule.DeactivateModule(); + + if (module != null) + module.ActivateModule(); + m_CurrentInputModule = module; + } + + public override string ToString() + { + var sb = new StringBuilder(); + sb.AppendLine("Selected:" + currentSelectedGameObject); + sb.AppendLine(); + sb.AppendLine(); + sb.AppendLine(m_CurrentInputModule != null ? m_CurrentInputModule.ToString() : "No module"); + return sb.ToString(); + } + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs.meta new file mode 100644 index 0000000..8ff114e --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 153642a2f08376d4daebdf63af9e161a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs new file mode 100644 index 0000000..11d1c1c --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs @@ -0,0 +1,159 @@ +using System; +using System.Collections.Generic; +using UnityEngine.Events; +using UnityEngine.Serialization; + +namespace UnityEngine.EventSystems +{ + //c 一个辅助组件,给一个事件添加自定义的回调函数 + //继承了所有接口,效率不高,慎用。只是比较方便 + + [AddComponentMenu("Event/Event Trigger")] + public class EventTrigger : + MonoBehaviour, + IPointerEnterHandler, + IPointerExitHandler, + IPointerDownHandler, + IPointerUpHandler, + IPointerClickHandler, + IInitializePotentialDragHandler, + IBeginDragHandler, + IDragHandler, + IEndDragHandler, + IDropHandler, + IScrollHandler, + IUpdateSelectedHandler, + ISelectHandler, + IDeselectHandler, + IMoveHandler, + ISubmitHandler, + ICancelHandler + { + [Serializable] + public class TriggerEvent : UnityEvent + {} + + [Serializable] + public class Entry + { + public EventTriggerType eventID = EventTriggerType.PointerClick; + public TriggerEvent callback = new TriggerEvent(); + } + + [FormerlySerializedAs("delegates")] + [SerializeField] + private List m_Delegates; + + [Obsolete("Please use triggers instead (UnityUpgradable) -> triggers", true)] + public List delegates; + + protected EventTrigger() + {} + + public List triggers + { + get + { + if (m_Delegates == null) + m_Delegates = new List(); + return m_Delegates; + } + set { m_Delegates = value; } + } + + private void Execute(EventTriggerType id, BaseEventData eventData) + { + for (int i = 0, imax = triggers.Count; i < imax; ++i) + { + var ent = triggers[i]; + if (ent.eventID == id && ent.callback != null) + ent.callback.Invoke(eventData); + } + } + + public virtual void OnPointerEnter(PointerEventData eventData) + { + Execute(EventTriggerType.PointerEnter, eventData); + } + + public virtual void OnPointerExit(PointerEventData eventData) + { + Execute(EventTriggerType.PointerExit, eventData); + } + + public virtual void OnDrag(PointerEventData eventData) + { + Execute(EventTriggerType.Drag, eventData); + } + + public virtual void OnDrop(PointerEventData eventData) + { + Execute(EventTriggerType.Drop, eventData); + } + + public virtual void OnPointerDown(PointerEventData eventData) + { + Execute(EventTriggerType.PointerDown, eventData); + } + + public virtual void OnPointerUp(PointerEventData eventData) + { + Execute(EventTriggerType.PointerUp, eventData); + } + + public virtual void OnPointerClick(PointerEventData eventData) + { + Execute(EventTriggerType.PointerClick, eventData); + } + + public virtual void OnSelect(BaseEventData eventData) + { + Execute(EventTriggerType.Select, eventData); + } + + public virtual void OnDeselect(BaseEventData eventData) + { + Execute(EventTriggerType.Deselect, eventData); + } + + public virtual void OnScroll(PointerEventData eventData) + { + Execute(EventTriggerType.Scroll, eventData); + } + + public virtual void OnMove(AxisEventData eventData) + { + Execute(EventTriggerType.Move, eventData); + } + + public virtual void OnUpdateSelected(BaseEventData eventData) + { + Execute(EventTriggerType.UpdateSelected, eventData); + } + + public virtual void OnInitializePotentialDrag(PointerEventData eventData) + { + Execute(EventTriggerType.InitializePotentialDrag, eventData); + } + + public virtual void OnBeginDrag(PointerEventData eventData) + { + Execute(EventTriggerType.BeginDrag, eventData); + } + + public virtual void OnEndDrag(PointerEventData eventData) + { + Execute(EventTriggerType.EndDrag, eventData); + } + + public virtual void OnSubmit(BaseEventData eventData) + { + Execute(EventTriggerType.Submit, eventData); + } + + public virtual void OnCancel(BaseEventData eventData) + { + Execute(EventTriggerType.Cancel, eventData); + } + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs.meta new file mode 100644 index 0000000..af5beba --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTrigger.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bacfe5cf756f51b4f8c77a4addae254e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs new file mode 100644 index 0000000..11c232c --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs @@ -0,0 +1,29 @@ +namespace UnityEngine.EventSystems +{ + /// + /// This class is capable of triggering one or more remote functions from a specified event. + /// Usage: Attach it to an object with a collider, or to a GUI Graphic of your choice. + /// NOTE: Doing this will make this object intercept ALL events, and no event bubbling will occur from this object! + /// + + public enum EventTriggerType + { + PointerEnter = 0, + PointerExit = 1, + PointerDown = 2, + PointerUp = 3, + PointerClick = 4, + Drag = 5, + Drop = 6, + Scroll = 7, + UpdateSelected = 8, + Select = 9, + Deselect = 10, + Move = 11, + InitializePotentialDrag = 12, + BeginDrag = 13, + EndDrag = 14, + Submit = 15, + Cancel = 16 + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs.meta new file mode 100644 index 0000000..4647857 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/EventTriggerType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec8af6a988832aa46844f9df796dfc4c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs new file mode 100644 index 0000000..a749ce8 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs @@ -0,0 +1,368 @@ +using System; +using System.Collections.Generic; +using UnityEngine.UI; + +namespace UnityEngine.EventSystems +{ + // 最关键的类,调用gameobject对应的回调函数 + public static class ExecuteEvents + { + public delegate void EventFunction(T1 handler, BaseEventData eventData); + + public static T ValidateEventData(BaseEventData data) where T : class + { + if ((data as T) == null) + throw new ArgumentException(String.Format("Invalid type: {0} passed to event expecting {1}", data.GetType(), typeof(T))); + return data as T; + } + + private static readonly EventFunction s_PointerEnterHandler = Execute; + + private static void Execute(IPointerEnterHandler handler, BaseEventData eventData) + { + handler.OnPointerEnter(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_PointerExitHandler = Execute; + + private static void Execute(IPointerExitHandler handler, BaseEventData eventData) + { + handler.OnPointerExit(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_PointerDownHandler = Execute; + + private static void Execute(IPointerDownHandler handler, BaseEventData eventData) + { + handler.OnPointerDown(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_PointerUpHandler = Execute; + + private static void Execute(IPointerUpHandler handler, BaseEventData eventData) + { + handler.OnPointerUp(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_PointerClickHandler = Execute; + + private static void Execute(IPointerClickHandler handler, BaseEventData eventData) + { + handler.OnPointerClick(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_InitializePotentialDragHandler = Execute; + + private static void Execute(IInitializePotentialDragHandler handler, BaseEventData eventData) + { + handler.OnInitializePotentialDrag(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_BeginDragHandler = Execute; + + private static void Execute(IBeginDragHandler handler, BaseEventData eventData) + { + handler.OnBeginDrag(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_DragHandler = Execute; + + private static void Execute(IDragHandler handler, BaseEventData eventData) + { + handler.OnDrag(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_EndDragHandler = Execute; + + private static void Execute(IEndDragHandler handler, BaseEventData eventData) + { + handler.OnEndDrag(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_DropHandler = Execute; + + private static void Execute(IDropHandler handler, BaseEventData eventData) + { + handler.OnDrop(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_ScrollHandler = Execute; + + private static void Execute(IScrollHandler handler, BaseEventData eventData) + { + handler.OnScroll(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_UpdateSelectedHandler = Execute; + + private static void Execute(IUpdateSelectedHandler handler, BaseEventData eventData) + { + handler.OnUpdateSelected(eventData); + } + + private static readonly EventFunction s_SelectHandler = Execute; + + private static void Execute(ISelectHandler handler, BaseEventData eventData) + { + handler.OnSelect(eventData); + } + + private static readonly EventFunction s_DeselectHandler = Execute; + + private static void Execute(IDeselectHandler handler, BaseEventData eventData) + { + handler.OnDeselect(eventData); + } + + private static readonly EventFunction s_MoveHandler = Execute; + + private static void Execute(IMoveHandler handler, BaseEventData eventData) + { + handler.OnMove(ValidateEventData(eventData)); + } + + private static readonly EventFunction s_SubmitHandler = Execute; + + private static void Execute(ISubmitHandler handler, BaseEventData eventData) + { + handler.OnSubmit(eventData); + } + + private static readonly EventFunction s_CancelHandler = Execute; + + private static void Execute(ICancelHandler handler, BaseEventData eventData) + { + handler.OnCancel(eventData); + } + + public static EventFunction pointerEnterHandler + { + get { return s_PointerEnterHandler; } + } + + public static EventFunction pointerExitHandler + { + get { return s_PointerExitHandler; } + } + + public static EventFunction pointerDownHandler + { + get { return s_PointerDownHandler; } + } + + public static EventFunction pointerUpHandler + { + get { return s_PointerUpHandler; } + } + + public static EventFunction pointerClickHandler + { + get { return s_PointerClickHandler; } + } + + public static EventFunction initializePotentialDrag + { + get { return s_InitializePotentialDragHandler; } + } + + public static EventFunction beginDragHandler + { + get { return s_BeginDragHandler; } + } + + public static EventFunction dragHandler + { + get { return s_DragHandler; } + } + + public static EventFunction endDragHandler + { + get { return s_EndDragHandler; } + } + + public static EventFunction dropHandler + { + get { return s_DropHandler; } + } + + public static EventFunction scrollHandler + { + get { return s_ScrollHandler; } + } + + public static EventFunction updateSelectedHandler + { + get { return s_UpdateSelectedHandler; } + } + + public static EventFunction selectHandler + { + get { return s_SelectHandler; } + } + + public static EventFunction deselectHandler + { + get { return s_DeselectHandler; } + } + + public static EventFunction moveHandler + { + get { return s_MoveHandler; } + } + + public static EventFunction submitHandler + { + get { return s_SubmitHandler; } + } + + public static EventFunction cancelHandler + { + get { return s_CancelHandler; } + } + + private static void GetEventChain(GameObject root, IList eventChain) + { + eventChain.Clear(); + if (root == null) + return; + + var t = root.transform; + while (t != null) + { + eventChain.Add(t); + t = t.parent; + } + } + + //IEventSystemHandler是所有接口的基类 + private static readonly ObjectPool> s_HandlerListPool = new ObjectPool>(null, l => l.Clear()); + + // 向target gameobject发送一个事件,对每个实现了T接口的类执行functor方法(就是接口中定义的回调) + public static bool Execute(GameObject target, BaseEventData eventData, EventFunction functor) where T : IEventSystemHandler + { + var internalHandlers = s_HandlerListPool.Get(); + GetEventList(target, internalHandlers); + // if (s_InternalHandlers.Count > 0) + // Debug.Log("Executinng " + typeof (T) + " on " + target); + + // 拿到实现了T接口的组件,调用对应的方法 + + for (var i = 0; i < internalHandlers.Count; i++) + { + T arg; + try + { + arg = (T)internalHandlers[i]; + } + catch (Exception e) + { + var temp = internalHandlers[i]; + Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); + continue; + } + + try + { + functor(arg, eventData); + } + catch (Exception e) + { + Debug.LogException(e); + } + } + + var handlerCount = internalHandlers.Count; + s_HandlerListPool.Release(internalHandlers); + return handlerCount > 0; + } + + /// + /// Execute the specified event on the first game object underneath the current touch. + /// + private static readonly List s_InternalTransformList = new List(30); + + public static GameObject ExecuteHierarchy(GameObject root, BaseEventData eventData, EventFunction callbackFunction) where T : IEventSystemHandler + { + GetEventChain(root, s_InternalTransformList); + + for (var i = 0; i < s_InternalTransformList.Count; i++) + { + var transform = s_InternalTransformList[i]; + if (Execute(transform.gameObject, eventData, callbackFunction)) + return transform.gameObject; + } + return null; + } + + //c component是否匹配类型T且是否被激活 + private static bool ShouldSendToComponent(Component component) where T : IEventSystemHandler + { + var valid = component is T; + if (!valid) + return false; + + var behaviour = component as Behaviour; + if (behaviour != null) + return behaviour.isActiveAndEnabled; + return true; + } + + /// + /// Get the specified object's event event. + /// + private static void GetEventList(GameObject go, IList results) where T : IEventSystemHandler + { + // Debug.LogWarning("GetEventList<" + typeof(T).Name + ">"); + if (results == null) + throw new ArgumentException("Results array is null", "results"); + + if (go == null || !go.activeInHierarchy) + return; + + var components = ListPool.Get(); + go.GetComponents(components); + // 遍历所有的组件,找到匹配类型T的 + for (var i = 0; i < components.Count; i++) + { + // 如果不匹配类型T,跳过这个 + if (!ShouldSendToComponent(components[i])) + continue; + + // Debug.Log(string.Format("{2} found! On {0}.{1}", go, s_GetComponentsScratch[i].GetType(), typeof(T))); + results.Add(components[i] as IEventSystemHandler); + } + ListPool.Release(components); + // Debug.LogWarning("end GetEventList<" + typeof(T).Name + ">"); + } + + /// + /// Whether the specified game object will be able to handle the specified event. + /// + public static bool CanHandleEvent(GameObject go) where T : IEventSystemHandler + { + var internalHandlers = s_HandlerListPool.Get(); + GetEventList(go, internalHandlers); + var handlerCount = internalHandlers.Count; + s_HandlerListPool.Release(internalHandlers); + return handlerCount != 0; + } + + /// + /// Bubble the specified event on the game object, figuring out which object will actually receive the event. + /// + public static GameObject GetEventHandler(GameObject root) where T : IEventSystemHandler + { + if (root == null) + return null; + + Transform t = root.transform; + while (t != null) + { + if (CanHandleEvent(t.gameObject)) + return t.gameObject; + t = t.parent; + } + return null; + } + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs.meta new file mode 100644 index 0000000..6317afb --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/ExecuteEvents.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 06bc2e6f5036fa848bb09004f4ab4e54 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs new file mode 100644 index 0000000..4f4147c --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs @@ -0,0 +1,11 @@ +namespace UnityEngine.EventSystems +{ + public enum MoveDirection + { + Left, + Up, + Right, + Down, + None + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs.meta new file mode 100644 index 0000000..ba67175 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventHandler/MoveDirection.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: a1de2f5af1cc8aa4aa68afe78b9c671e +timeCreated: 1602119379 +licenseType: Free +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs deleted file mode 100644 index b808e6c..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs +++ /dev/null @@ -1,91 +0,0 @@ -namespace UnityEngine.EventSystems -{ - public interface IEventSystemHandler - { - } - - public interface IPointerEnterHandler : IEventSystemHandler - { - void OnPointerEnter(PointerEventData eventData); - } - - public interface IPointerExitHandler : IEventSystemHandler - { - void OnPointerExit(PointerEventData eventData); - } - - public interface IPointerDownHandler : IEventSystemHandler - { - void OnPointerDown(PointerEventData eventData); - } - - public interface IPointerUpHandler : IEventSystemHandler - { - void OnPointerUp(PointerEventData eventData); - } - - public interface IPointerClickHandler : IEventSystemHandler - { - void OnPointerClick(PointerEventData eventData); - } - - public interface IBeginDragHandler : IEventSystemHandler - { - void OnBeginDrag(PointerEventData eventData); - } - - public interface IInitializePotentialDragHandler : IEventSystemHandler - { - void OnInitializePotentialDrag(PointerEventData eventData); - } - - public interface IDragHandler : IEventSystemHandler - { - void OnDrag(PointerEventData eventData); - } - - public interface IEndDragHandler : IEventSystemHandler - { - void OnEndDrag(PointerEventData eventData); - } - - public interface IDropHandler : IEventSystemHandler - { - void OnDrop(PointerEventData eventData); - } - - public interface IScrollHandler : IEventSystemHandler - { - void OnScroll(PointerEventData eventData); - } - - public interface IUpdateSelectedHandler : IEventSystemHandler - { - void OnUpdateSelected(BaseEventData eventData); - } - - public interface ISelectHandler : IEventSystemHandler - { - void OnSelect(BaseEventData eventData); - } - - public interface IDeselectHandler : IEventSystemHandler - { - void OnDeselect(BaseEventData eventData); - } - - public interface IMoveHandler : IEventSystemHandler - { - void OnMove(AxisEventData eventData); - } - - public interface ISubmitHandler : IEventSystemHandler - { - void OnSubmit(BaseEventData eventData); - } - - public interface ICancelHandler : IEventSystemHandler - { - void OnCancel(BaseEventData eventData); - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs.meta deleted file mode 100644 index 436f77b..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventInterfaces.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 40c86ee97518df241a850e926719dbc2 -timeCreated: 1602119378 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs deleted file mode 100644 index 801daae..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs +++ /dev/null @@ -1,324 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using UnityEngine; -using UnityEngine.Serialization; - -namespace UnityEngine.EventSystems -{ - [AddComponentMenu("Event/Event System")] - public class EventSystem : UIBehaviour - { - // 获得当前EventSystem挂着的BaseInputModule的派生类,一般来说只会挂一个StandableInputModule - private List m_SystemInputModules = new List(); - - private BaseInputModule m_CurrentInputModule; - - public static EventSystem current { get; set; } - - [SerializeField] - [FormerlySerializedAs("m_Selected")] - private GameObject m_FirstSelected; - - [SerializeField] - private bool m_sendNavigationEvents = true; // Should the EventSystem allow navigation events (move / submit / cancel). - - public bool sendNavigationEvents - { - get { return m_sendNavigationEvents; } - set { m_sendNavigationEvents = value; } - } - - [SerializeField] - private int m_DragThreshold = 5; - public int pixelDragThreshold - { - get { return m_DragThreshold; } - set { m_DragThreshold = value; } - } - - private GameObject m_CurrentSelected; - - public BaseInputModule currentInputModule - { - get { return m_CurrentInputModule; } - } - - /// - /// Only one object can be selected at a time. Think: controller-selected button. - /// - public GameObject firstSelectedGameObject - { - get { return m_FirstSelected; } - set { m_FirstSelected = value; } - } - - public GameObject currentSelectedGameObject - { - get { return m_CurrentSelected; } - } - - [Obsolete("lastSelectedGameObject is no longer supported")] - public GameObject lastSelectedGameObject - { - get { return null; } - } - - private bool m_HasFocus = true; - - public bool isFocused - { - get { return m_HasFocus; } - } - - protected EventSystem() - {} - - //c 把挂着的input modules加入m_SystemInputModules - public void UpdateModules() - { - // 拿到当前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); - } - } - - private bool m_SelectionGuard; - public bool alreadySelecting - { - get { return m_SelectionGuard; } - } - - public void SetSelectedGameObject(GameObject selected, BaseEventData pointer) - { - if (m_SelectionGuard) - { - Debug.LogError("Attempting to select " + selected + "while already selecting an object."); - return; - } - - m_SelectionGuard = true; - if (selected == m_CurrentSelected) - { - m_SelectionGuard = false; - return; - } - - // Debug.Log("Selection: new (" + selected + ") old (" + m_CurrentSelected + ")"); - ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.deselectHandler); - m_CurrentSelected = selected; - ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.selectHandler); - m_SelectionGuard = false; - } - - private BaseEventData m_DummyData; - private BaseEventData baseEventDataCache - { - get - { - if (m_DummyData == null) - m_DummyData = new BaseEventData(this); - - return m_DummyData; - } - } - - public void SetSelectedGameObject(GameObject selected) - { - SetSelectedGameObject(selected, baseEventDataCache); - } - - private static int RaycastComparer(RaycastResult lhs, RaycastResult rhs) - { - if (lhs.module != rhs.module) - { - var lhsEventCamera = lhs.module.eventCamera; - var rhsEventCamera = rhs.module.eventCamera; - if (lhsEventCamera != null && rhsEventCamera != null && lhsEventCamera.depth != rhsEventCamera.depth) - { - // need to reverse the standard compareTo - if (lhsEventCamera.depth < rhsEventCamera.depth) - return 1; - if (lhsEventCamera.depth == rhsEventCamera.depth) - return 0; - - return -1; - } - - if (lhs.module.sortOrderPriority != rhs.module.sortOrderPriority) - return rhs.module.sortOrderPriority.CompareTo(lhs.module.sortOrderPriority); - - if (lhs.module.renderOrderPriority != rhs.module.renderOrderPriority) - return rhs.module.renderOrderPriority.CompareTo(lhs.module.renderOrderPriority); - } - - if (lhs.sortingLayer != rhs.sortingLayer) - { - // Uses the layer value to properly compare the relative order of the layers. - var rid = SortingLayer.GetLayerValueFromID(rhs.sortingLayer); - var lid = SortingLayer.GetLayerValueFromID(lhs.sortingLayer); - return rid.CompareTo(lid); - } - - - if (lhs.sortingOrder != rhs.sortingOrder) - return rhs.sortingOrder.CompareTo(lhs.sortingOrder); - - if (lhs.depth != rhs.depth) - return rhs.depth.CompareTo(lhs.depth); - - if (lhs.distance != rhs.distance) - return lhs.distance.CompareTo(rhs.distance); - - return lhs.index.CompareTo(rhs.index); - } - - private static readonly Comparison s_RaycastComparer = RaycastComparer; - - // 从PointerInputModule.GetTouchPointerEventData()来的触摸数据 - public void RaycastAll(PointerEventData eventData, List raycastResults) - { - raycastResults.Clear(); - //包括场景中所有的raycaster - var modules = RaycasterManager.GetRaycasters(); - for (int i = 0; i < modules.Count; ++i) - { - var module = modules[i]; - if (module == null || !module.IsActive()) - continue; - - module.Raycast(eventData, raycastResults); - } - - raycastResults.Sort(s_RaycastComparer); - } - - //c 是否点击到某个物体 - public bool IsPointerOverGameObject() - { - return IsPointerOverGameObject(PointerInputModule.kMouseLeftId); - } - - //c 是否点击到某个物体 - public bool IsPointerOverGameObject(int pointerId) - { - if (m_CurrentInputModule == null) - return false; - - return m_CurrentInputModule.IsPointerOverGameObject(pointerId); - } - - protected override void OnEnable() - { - base.OnEnable(); - if (EventSystem.current == null) - EventSystem.current = this; -#if UNITY_EDITOR - else - { - Debug.LogWarning("Multiple EventSystems in scene... this is not supported"); - } -#endif - } - - protected override void OnDisable() - { - if (m_CurrentInputModule != null) - { - m_CurrentInputModule.DeactivateModule(); - m_CurrentInputModule = null; - } - - if (EventSystem.current == this) - EventSystem.current = null; - - 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) - m_SystemInputModules[i].UpdateModule(); - } - } - - //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++) - { - var module = m_SystemInputModules[i]; - if (module.IsModuleSupported() && module.ShouldActivateModule()) - { - if (m_CurrentInputModule != module) - { - ChangeEventModule(module); - changedModule = true; - } - break; - } - } - // no event module set... set the first valid one... - if (m_CurrentInputModule == null) - { - for (var i = 0; i < m_SystemInputModules.Count; i++) - { - var module = m_SystemInputModules[i]; - if (module.IsModuleSupported()) - { - ChangeEventModule(module); - changedModule = true; - break; - } - } - } - - //c! 执行事件处理主入口,通常情况下,如果没有自定义的inputModule,就是走StandaloneInputModule的Process - if (!changedModule && m_CurrentInputModule != null) - m_CurrentInputModule.Process(); - } - - private void ChangeEventModule(BaseInputModule module) - { - if (m_CurrentInputModule == module) - return; - - if (m_CurrentInputModule != null) - m_CurrentInputModule.DeactivateModule(); - - if (module != null) - module.ActivateModule(); - m_CurrentInputModule = module; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.AppendLine("Selected:" + currentSelectedGameObject); - sb.AppendLine(); - sb.AppendLine(); - sb.AppendLine(m_CurrentInputModule != null ? m_CurrentInputModule.ToString() : "No module"); - return sb.ToString(); - } - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs.meta deleted file mode 100644 index ad6192d..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventSystem.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 47dabc676519a2840ab00d4e00228528 -timeCreated: 1602119378 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs deleted file mode 100644 index 11d1c1c..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs +++ /dev/null @@ -1,159 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine.Events; -using UnityEngine.Serialization; - -namespace UnityEngine.EventSystems -{ - //c 一个辅助组件,给一个事件添加自定义的回调函数 - //继承了所有接口,效率不高,慎用。只是比较方便 - - [AddComponentMenu("Event/Event Trigger")] - public class EventTrigger : - MonoBehaviour, - IPointerEnterHandler, - IPointerExitHandler, - IPointerDownHandler, - IPointerUpHandler, - IPointerClickHandler, - IInitializePotentialDragHandler, - IBeginDragHandler, - IDragHandler, - IEndDragHandler, - IDropHandler, - IScrollHandler, - IUpdateSelectedHandler, - ISelectHandler, - IDeselectHandler, - IMoveHandler, - ISubmitHandler, - ICancelHandler - { - [Serializable] - public class TriggerEvent : UnityEvent - {} - - [Serializable] - public class Entry - { - public EventTriggerType eventID = EventTriggerType.PointerClick; - public TriggerEvent callback = new TriggerEvent(); - } - - [FormerlySerializedAs("delegates")] - [SerializeField] - private List m_Delegates; - - [Obsolete("Please use triggers instead (UnityUpgradable) -> triggers", true)] - public List delegates; - - protected EventTrigger() - {} - - public List triggers - { - get - { - if (m_Delegates == null) - m_Delegates = new List(); - return m_Delegates; - } - set { m_Delegates = value; } - } - - private void Execute(EventTriggerType id, BaseEventData eventData) - { - for (int i = 0, imax = triggers.Count; i < imax; ++i) - { - var ent = triggers[i]; - if (ent.eventID == id && ent.callback != null) - ent.callback.Invoke(eventData); - } - } - - public virtual void OnPointerEnter(PointerEventData eventData) - { - Execute(EventTriggerType.PointerEnter, eventData); - } - - public virtual void OnPointerExit(PointerEventData eventData) - { - Execute(EventTriggerType.PointerExit, eventData); - } - - public virtual void OnDrag(PointerEventData eventData) - { - Execute(EventTriggerType.Drag, eventData); - } - - public virtual void OnDrop(PointerEventData eventData) - { - Execute(EventTriggerType.Drop, eventData); - } - - public virtual void OnPointerDown(PointerEventData eventData) - { - Execute(EventTriggerType.PointerDown, eventData); - } - - public virtual void OnPointerUp(PointerEventData eventData) - { - Execute(EventTriggerType.PointerUp, eventData); - } - - public virtual void OnPointerClick(PointerEventData eventData) - { - Execute(EventTriggerType.PointerClick, eventData); - } - - public virtual void OnSelect(BaseEventData eventData) - { - Execute(EventTriggerType.Select, eventData); - } - - public virtual void OnDeselect(BaseEventData eventData) - { - Execute(EventTriggerType.Deselect, eventData); - } - - public virtual void OnScroll(PointerEventData eventData) - { - Execute(EventTriggerType.Scroll, eventData); - } - - public virtual void OnMove(AxisEventData eventData) - { - Execute(EventTriggerType.Move, eventData); - } - - public virtual void OnUpdateSelected(BaseEventData eventData) - { - Execute(EventTriggerType.UpdateSelected, eventData); - } - - public virtual void OnInitializePotentialDrag(PointerEventData eventData) - { - Execute(EventTriggerType.InitializePotentialDrag, eventData); - } - - public virtual void OnBeginDrag(PointerEventData eventData) - { - Execute(EventTriggerType.BeginDrag, eventData); - } - - public virtual void OnEndDrag(PointerEventData eventData) - { - Execute(EventTriggerType.EndDrag, eventData); - } - - public virtual void OnSubmit(BaseEventData eventData) - { - Execute(EventTriggerType.Submit, eventData); - } - - public virtual void OnCancel(BaseEventData eventData) - { - Execute(EventTriggerType.Cancel, eventData); - } - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs.meta deleted file mode 100644 index bbb941c..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTrigger.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 17193886a08901d45ba6c4e9cebb18f6 -timeCreated: 1602119377 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs deleted file mode 100644 index 11c232c..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs +++ /dev/null @@ -1,29 +0,0 @@ -namespace UnityEngine.EventSystems -{ - /// - /// This class is capable of triggering one or more remote functions from a specified event. - /// Usage: Attach it to an object with a collider, or to a GUI Graphic of your choice. - /// NOTE: Doing this will make this object intercept ALL events, and no event bubbling will occur from this object! - /// - - public enum EventTriggerType - { - PointerEnter = 0, - PointerExit = 1, - PointerDown = 2, - PointerUp = 3, - PointerClick = 4, - Drag = 5, - Drop = 6, - Scroll = 7, - UpdateSelected = 8, - Select = 9, - Deselect = 10, - Move = 11, - InitializePotentialDrag = 12, - BeginDrag = 13, - EndDrag = 14, - Submit = 15, - Cancel = 16 - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs.meta deleted file mode 100644 index a01a6b5..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/EventTriggerType.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: fe5c20ffd1028d540b638b6843759dcf -timeCreated: 1602119380 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs deleted file mode 100644 index a749ce8..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs +++ /dev/null @@ -1,368 +0,0 @@ -using System; -using System.Collections.Generic; -using UnityEngine.UI; - -namespace UnityEngine.EventSystems -{ - // 最关键的类,调用gameobject对应的回调函数 - public static class ExecuteEvents - { - public delegate void EventFunction(T1 handler, BaseEventData eventData); - - public static T ValidateEventData(BaseEventData data) where T : class - { - if ((data as T) == null) - throw new ArgumentException(String.Format("Invalid type: {0} passed to event expecting {1}", data.GetType(), typeof(T))); - return data as T; - } - - private static readonly EventFunction s_PointerEnterHandler = Execute; - - private static void Execute(IPointerEnterHandler handler, BaseEventData eventData) - { - handler.OnPointerEnter(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_PointerExitHandler = Execute; - - private static void Execute(IPointerExitHandler handler, BaseEventData eventData) - { - handler.OnPointerExit(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_PointerDownHandler = Execute; - - private static void Execute(IPointerDownHandler handler, BaseEventData eventData) - { - handler.OnPointerDown(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_PointerUpHandler = Execute; - - private static void Execute(IPointerUpHandler handler, BaseEventData eventData) - { - handler.OnPointerUp(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_PointerClickHandler = Execute; - - private static void Execute(IPointerClickHandler handler, BaseEventData eventData) - { - handler.OnPointerClick(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_InitializePotentialDragHandler = Execute; - - private static void Execute(IInitializePotentialDragHandler handler, BaseEventData eventData) - { - handler.OnInitializePotentialDrag(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_BeginDragHandler = Execute; - - private static void Execute(IBeginDragHandler handler, BaseEventData eventData) - { - handler.OnBeginDrag(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_DragHandler = Execute; - - private static void Execute(IDragHandler handler, BaseEventData eventData) - { - handler.OnDrag(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_EndDragHandler = Execute; - - private static void Execute(IEndDragHandler handler, BaseEventData eventData) - { - handler.OnEndDrag(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_DropHandler = Execute; - - private static void Execute(IDropHandler handler, BaseEventData eventData) - { - handler.OnDrop(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_ScrollHandler = Execute; - - private static void Execute(IScrollHandler handler, BaseEventData eventData) - { - handler.OnScroll(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_UpdateSelectedHandler = Execute; - - private static void Execute(IUpdateSelectedHandler handler, BaseEventData eventData) - { - handler.OnUpdateSelected(eventData); - } - - private static readonly EventFunction s_SelectHandler = Execute; - - private static void Execute(ISelectHandler handler, BaseEventData eventData) - { - handler.OnSelect(eventData); - } - - private static readonly EventFunction s_DeselectHandler = Execute; - - private static void Execute(IDeselectHandler handler, BaseEventData eventData) - { - handler.OnDeselect(eventData); - } - - private static readonly EventFunction s_MoveHandler = Execute; - - private static void Execute(IMoveHandler handler, BaseEventData eventData) - { - handler.OnMove(ValidateEventData(eventData)); - } - - private static readonly EventFunction s_SubmitHandler = Execute; - - private static void Execute(ISubmitHandler handler, BaseEventData eventData) - { - handler.OnSubmit(eventData); - } - - private static readonly EventFunction s_CancelHandler = Execute; - - private static void Execute(ICancelHandler handler, BaseEventData eventData) - { - handler.OnCancel(eventData); - } - - public static EventFunction pointerEnterHandler - { - get { return s_PointerEnterHandler; } - } - - public static EventFunction pointerExitHandler - { - get { return s_PointerExitHandler; } - } - - public static EventFunction pointerDownHandler - { - get { return s_PointerDownHandler; } - } - - public static EventFunction pointerUpHandler - { - get { return s_PointerUpHandler; } - } - - public static EventFunction pointerClickHandler - { - get { return s_PointerClickHandler; } - } - - public static EventFunction initializePotentialDrag - { - get { return s_InitializePotentialDragHandler; } - } - - public static EventFunction beginDragHandler - { - get { return s_BeginDragHandler; } - } - - public static EventFunction dragHandler - { - get { return s_DragHandler; } - } - - public static EventFunction endDragHandler - { - get { return s_EndDragHandler; } - } - - public static EventFunction dropHandler - { - get { return s_DropHandler; } - } - - public static EventFunction scrollHandler - { - get { return s_ScrollHandler; } - } - - public static EventFunction updateSelectedHandler - { - get { return s_UpdateSelectedHandler; } - } - - public static EventFunction selectHandler - { - get { return s_SelectHandler; } - } - - public static EventFunction deselectHandler - { - get { return s_DeselectHandler; } - } - - public static EventFunction moveHandler - { - get { return s_MoveHandler; } - } - - public static EventFunction submitHandler - { - get { return s_SubmitHandler; } - } - - public static EventFunction cancelHandler - { - get { return s_CancelHandler; } - } - - private static void GetEventChain(GameObject root, IList eventChain) - { - eventChain.Clear(); - if (root == null) - return; - - var t = root.transform; - while (t != null) - { - eventChain.Add(t); - t = t.parent; - } - } - - //IEventSystemHandler是所有接口的基类 - private static readonly ObjectPool> s_HandlerListPool = new ObjectPool>(null, l => l.Clear()); - - // 向target gameobject发送一个事件,对每个实现了T接口的类执行functor方法(就是接口中定义的回调) - public static bool Execute(GameObject target, BaseEventData eventData, EventFunction functor) where T : IEventSystemHandler - { - var internalHandlers = s_HandlerListPool.Get(); - GetEventList(target, internalHandlers); - // if (s_InternalHandlers.Count > 0) - // Debug.Log("Executinng " + typeof (T) + " on " + target); - - // 拿到实现了T接口的组件,调用对应的方法 - - for (var i = 0; i < internalHandlers.Count; i++) - { - T arg; - try - { - arg = (T)internalHandlers[i]; - } - catch (Exception e) - { - var temp = internalHandlers[i]; - Debug.LogException(new Exception(string.Format("Type {0} expected {1} received.", typeof(T).Name, temp.GetType().Name), e)); - continue; - } - - try - { - functor(arg, eventData); - } - catch (Exception e) - { - Debug.LogException(e); - } - } - - var handlerCount = internalHandlers.Count; - s_HandlerListPool.Release(internalHandlers); - return handlerCount > 0; - } - - /// - /// Execute the specified event on the first game object underneath the current touch. - /// - private static readonly List s_InternalTransformList = new List(30); - - public static GameObject ExecuteHierarchy(GameObject root, BaseEventData eventData, EventFunction callbackFunction) where T : IEventSystemHandler - { - GetEventChain(root, s_InternalTransformList); - - for (var i = 0; i < s_InternalTransformList.Count; i++) - { - var transform = s_InternalTransformList[i]; - if (Execute(transform.gameObject, eventData, callbackFunction)) - return transform.gameObject; - } - return null; - } - - //c component是否匹配类型T且是否被激活 - private static bool ShouldSendToComponent(Component component) where T : IEventSystemHandler - { - var valid = component is T; - if (!valid) - return false; - - var behaviour = component as Behaviour; - if (behaviour != null) - return behaviour.isActiveAndEnabled; - return true; - } - - /// - /// Get the specified object's event event. - /// - private static void GetEventList(GameObject go, IList results) where T : IEventSystemHandler - { - // Debug.LogWarning("GetEventList<" + typeof(T).Name + ">"); - if (results == null) - throw new ArgumentException("Results array is null", "results"); - - if (go == null || !go.activeInHierarchy) - return; - - var components = ListPool.Get(); - go.GetComponents(components); - // 遍历所有的组件,找到匹配类型T的 - for (var i = 0; i < components.Count; i++) - { - // 如果不匹配类型T,跳过这个 - if (!ShouldSendToComponent(components[i])) - continue; - - // Debug.Log(string.Format("{2} found! On {0}.{1}", go, s_GetComponentsScratch[i].GetType(), typeof(T))); - results.Add(components[i] as IEventSystemHandler); - } - ListPool.Release(components); - // Debug.LogWarning("end GetEventList<" + typeof(T).Name + ">"); - } - - /// - /// Whether the specified game object will be able to handle the specified event. - /// - public static bool CanHandleEvent(GameObject go) where T : IEventSystemHandler - { - var internalHandlers = s_HandlerListPool.Get(); - GetEventList(go, internalHandlers); - var handlerCount = internalHandlers.Count; - s_HandlerListPool.Release(internalHandlers); - return handlerCount != 0; - } - - /// - /// Bubble the specified event on the game object, figuring out which object will actually receive the event. - /// - public static GameObject GetEventHandler(GameObject root) where T : IEventSystemHandler - { - if (root == null) - return null; - - Transform t = root.transform; - while (t != null) - { - if (CanHandleEvent(t.gameObject)) - return t.gameObject; - t = t.parent; - } - return null; - } - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs.meta deleted file mode 100644 index 55a5661..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/ExecuteEvents.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: f026ab7af2955364588010a84939930e -timeCreated: 1602119380 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: 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 66736d1..f25f3fe 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/BaseInputModule.cs @@ -56,6 +56,9 @@ namespace UnityEngine.EventSystems protected override void OnEnable() { base.OnEnable(); + if(input != null) + { + } m_EventSystem = GetComponent(); m_EventSystem.UpdateModules(); // 把此input module加入EventSystem } 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 3f93e7a..3aa8e09 100644 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/InputModules/PointerInputModule.cs @@ -14,6 +14,7 @@ namespace UnityEngine.EventSystems public const int kFakeTouchesId = -4; + // 一个池子 protected Dictionary m_PointerData = new Dictionary(); protected bool GetPointerData(int id, out PointerEventData data, bool create) diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs deleted file mode 100644 index 4f4147c..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace UnityEngine.EventSystems -{ - public enum MoveDirection - { - Left, - Up, - Right, - Down, - None - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs.meta deleted file mode 100644 index ba67175..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/MoveDirection.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: a1de2f5af1cc8aa4aa68afe78b9c671e -timeCreated: 1602119379 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs deleted file mode 100644 index 666ef8d..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace UnityEngine.EventSystems -{ - // UGUI射线检测结果 - public struct RaycastResult - { - private GameObject m_GameObject; // Game object hit by the raycast - - public GameObject gameObject - { - get { return m_GameObject; } - set { m_GameObject = value; } - } - - public BaseRaycaster module; // Event system that hit this object - public float distance; // The distance from the origin this hit was. - public float index; // The index this element is in the raycastList (used for sorting) - public int depth; - public int sortingLayer; - public int sortingOrder; - // World-space position where a ray cast into the screen hits something - public Vector3 worldPosition; - // World-space normal where a ray cast into the screen hits something - public Vector3 worldNormal; - - public Vector2 screenPosition; - - public bool isValid - { - get { return module != null && gameObject != null; } - } - - public void Clear() - { - gameObject = null; - module = null; - distance = 0; - index = 0; - depth = 0; - sortingLayer = 0; - sortingOrder = 0; - worldNormal = Vector3.up; - worldPosition = Vector3.zero; - screenPosition = Vector2.zero; - } - - public override string ToString() - { - if (!isValid) - return ""; - - return "Name: " + gameObject + "\n" + - "module: " + module + "\n" + - "distance: " + distance + "\n" + - "index: " + index + "\n" + - "depth: " + depth + "\n" + - "worldNormal: " + worldNormal + "\n" + - "worldPosition: " + worldPosition + "\n" + - "screenPosition: " + screenPosition + "\n" + - "module.sortOrderPriority: " + module.sortOrderPriority + "\n" + - "module.renderOrderPriority: " + module.renderOrderPriority + "\n" + - "sortingLayer: " + sortingLayer + "\n" + - "sortingOrder: " + sortingOrder; - } - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs.meta deleted file mode 100644 index 34d3799..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycastResult.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: 500a96364b902574fb3486a1c93591b3 -timeCreated: 1602119378 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs deleted file mode 100644 index c3480b4..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Collections.Generic; - -namespace UnityEngine.EventSystems -{ - internal static class RaycasterManager - { - private static readonly List s_Raycasters = new List(); - - public static void AddRaycaster(BaseRaycaster baseRaycaster) - { - if (s_Raycasters.Contains(baseRaycaster)) - return; - - s_Raycasters.Add(baseRaycaster); - } - - public static List GetRaycasters() - { - return s_Raycasters; - } - - public static void RemoveRaycasters(BaseRaycaster baseRaycaster) - { - if (!s_Raycasters.Contains(baseRaycaster)) - return; - s_Raycasters.Remove(baseRaycaster); - } - } -} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs.meta deleted file mode 100644 index 9351151..0000000 --- a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/RaycasterManager.cs.meta +++ /dev/null @@ -1,13 +0,0 @@ -fileFormatVersion: 2 -guid: b028797ae6e79fd48b667fede5f64ca9 -timeCreated: 1602119379 -licenseType: Free -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs new file mode 100644 index 0000000..666ef8d --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs @@ -0,0 +1,65 @@ +namespace UnityEngine.EventSystems +{ + // UGUI射线检测结果 + public struct RaycastResult + { + private GameObject m_GameObject; // Game object hit by the raycast + + public GameObject gameObject + { + get { return m_GameObject; } + set { m_GameObject = value; } + } + + public BaseRaycaster module; // Event system that hit this object + public float distance; // The distance from the origin this hit was. + public float index; // The index this element is in the raycastList (used for sorting) + public int depth; + public int sortingLayer; + public int sortingOrder; + // World-space position where a ray cast into the screen hits something + public Vector3 worldPosition; + // World-space normal where a ray cast into the screen hits something + public Vector3 worldNormal; + + public Vector2 screenPosition; + + public bool isValid + { + get { return module != null && gameObject != null; } + } + + public void Clear() + { + gameObject = null; + module = null; + distance = 0; + index = 0; + depth = 0; + sortingLayer = 0; + sortingOrder = 0; + worldNormal = Vector3.up; + worldPosition = Vector3.zero; + screenPosition = Vector2.zero; + } + + public override string ToString() + { + if (!isValid) + return ""; + + return "Name: " + gameObject + "\n" + + "module: " + module + "\n" + + "distance: " + distance + "\n" + + "index: " + index + "\n" + + "depth: " + depth + "\n" + + "worldNormal: " + worldNormal + "\n" + + "worldPosition: " + worldPosition + "\n" + + "screenPosition: " + screenPosition + "\n" + + "module.sortOrderPriority: " + module.sortOrderPriority + "\n" + + "module.renderOrderPriority: " + module.renderOrderPriority + "\n" + + "sortingLayer: " + sortingLayer + "\n" + + "sortingOrder: " + sortingOrder; + } + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs.meta new file mode 100644 index 0000000..c2d01ba --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycastResult.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5f5a2c96e65809c43ad8a958f062ef1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs new file mode 100644 index 0000000..c3480b4 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace UnityEngine.EventSystems +{ + internal static class RaycasterManager + { + private static readonly List s_Raycasters = new List(); + + public static void AddRaycaster(BaseRaycaster baseRaycaster) + { + if (s_Raycasters.Contains(baseRaycaster)) + return; + + s_Raycasters.Add(baseRaycaster); + } + + public static List GetRaycasters() + { + return s_Raycasters; + } + + public static void RemoveRaycasters(BaseRaycaster baseRaycaster) + { + if (!s_Raycasters.Contains(baseRaycaster)) + return; + s_Raycasters.Remove(baseRaycaster); + } + } +} diff --git a/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs.meta b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs.meta new file mode 100644 index 0000000..594b8d2 --- /dev/null +++ b/Assets/uGUI-2017.1/UnityEngine.UI/EventSystem/Raycasters/RaycasterManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5c12b7bf7a4800945ba532802a36b165 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0