Merge pull request #248 from Ambitroc/master

支持除鼠标以外其他输入方式的Point位置获取,比如VR项目
This commit is contained in:
monitor1394
2023-03-10 11:46:13 +08:00
committed by GitHub
2 changed files with 7 additions and 5 deletions

View File

@@ -51,7 +51,8 @@ namespace XCharts.Runtime
/// Whether the mouse pointer is in the chart. /// Whether the mouse pointer is in the chart.
/// |鼠标是否在图表内。 /// |鼠标是否在图表内。
/// </summary> /// </summary>
public bool isPointerInChart { get; protected set; } public bool isPointerInChart
{ get { return m_PointerEventData != null; } }
/// <summary> /// <summary>
/// 警告信息。 /// 警告信息。
/// </summary> /// </summary>

View File

@@ -1,4 +1,4 @@
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using UnityEngine.UI; using UnityEngine.UI;
@@ -35,6 +35,7 @@ namespace XCharts.Runtime
protected bool m_PainerDirty = false; protected bool m_PainerDirty = false;
protected bool m_IsOnValidate = false; protected bool m_IsOnValidate = false;
protected Vector3 m_LastLocalPosition; protected Vector3 m_LastLocalPosition;
protected PointerEventData m_PointerEventData;
protected Action<PointerEventData, BaseGraph> m_OnPointerClick; protected Action<PointerEventData, BaseGraph> m_OnPointerClick;
protected Action<PointerEventData, BaseGraph> m_OnPointerDown; protected Action<PointerEventData, BaseGraph> m_OnPointerDown;
@@ -209,7 +210,7 @@ namespace XCharts.Runtime
{ {
if (!isPointerInChart) return; if (!isPointerInChart) return;
if (canvas == null) return; if (canvas == null) return;
Vector2 mousePos = Input.mousePosition; Vector2 mousePos = m_PointerEventData.position;
Vector2 local; Vector2 local;
if (!ScreenPointToChartPoint(mousePos, out local)) if (!ScreenPointToChartPoint(mousePos, out local))
{ {
@@ -278,13 +279,13 @@ namespace XCharts.Runtime
public virtual void OnPointerEnter(PointerEventData eventData) public virtual void OnPointerEnter(PointerEventData eventData)
{ {
isPointerInChart = true; m_PointerEventData = eventData;
if (m_OnPointerEnter != null) m_OnPointerEnter(eventData, this); if (m_OnPointerEnter != null) m_OnPointerEnter(eventData, this);
} }
public virtual void OnPointerExit(PointerEventData eventData) public virtual void OnPointerExit(PointerEventData eventData)
{ {
isPointerInChart = false; m_PointerEventData = null;
if (m_OnPointerExit != null) m_OnPointerExit(eventData, this); if (m_OnPointerExit != null) m_OnPointerExit(eventData, this);
} }