mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-26 02:40:13 +00:00
新增对 InputSystem 的支持
Update BaseGraph.cs Update XCharts.Runtime.asmdef
This commit is contained in:
BIN
Documentation~/zh/img/inputsystem01.png
Normal file
BIN
Documentation~/zh/img/inputsystem01.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
BIN
Documentation~/zh/img/inputsystem02.png
Normal file
BIN
Documentation~/zh/img/inputsystem02.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
BIN
Documentation~/zh/img/inputsystem03.png
Normal file
BIN
Documentation~/zh/img/inputsystem03.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 59 KiB |
17
Documentation~/zh/inputsystem.md
Normal file
17
Documentation~/zh/inputsystem.md
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: 入门教程:从 Input Manager 转到 Input System
|
||||||
|
sidebar_position: 1
|
||||||
|
slug: /inputsystem
|
||||||
|
---
|
||||||
|
|
||||||
|
# 教程:从 Input Manager 转到 Input System
|
||||||
|
|
||||||
|
## 1. 按图示修改项目配置中输入模式为 Input System
|
||||||
|

|
||||||
|
|
||||||
|
## 2. 使用 Unity Package Manager 安装 Input System
|
||||||
|

|
||||||
|
## 3. 选中场景中 EventSystem 游戏对象,更换输入模组
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
@@ -70,6 +70,7 @@
|
|||||||
- 支持万级大数据量绘制,支持采样绘制。
|
- 支持万级大数据量绘制,支持采样绘制。
|
||||||
- 支持`TexMeshPro`。
|
- 支持`TexMeshPro`。
|
||||||
- 支持所有`5.6`以上的`Unity`版本。
|
- 支持所有`5.6`以上的`Unity`版本。
|
||||||
|
- 支持 Input System ([如何从 Input Manager 转 Input System](Documentation~/zh/inputsystem.md))。
|
||||||
|
|
||||||
## 截图
|
## 截图
|
||||||
|
|
||||||
|
|||||||
@@ -631,12 +631,12 @@ namespace XCharts.Runtime
|
|||||||
|
|
||||||
internal void UpdateStartLabelPosition(Vector3 pos)
|
internal void UpdateStartLabelPosition(Vector3 pos)
|
||||||
{
|
{
|
||||||
m_StartLabel.SetPosition(pos);
|
if (m_StartLabel != null) m_StartLabel.SetPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateEndLabelPosition(Vector3 pos)
|
internal void UpdateEndLabelPosition(Vector3 pos)
|
||||||
{
|
{
|
||||||
m_EndLabel.SetPosition(pos);
|
if (m_EndLabel != null) m_EndLabel.SetPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
public void UpdateRuntimeData(float chartX, float chartY, float chartWidth, float chartHeight)
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using XUGL;
|
using XUGL;
|
||||||
|
#if INPUT_SYSTEM_ENABLED
|
||||||
|
using Input = XCharts.Runtime.InputHelper;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ using UnityEngine;
|
|||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using XUGL;
|
using XUGL;
|
||||||
|
#if INPUT_SYSTEM_ENABLED
|
||||||
|
using Input = XCharts.Runtime.InputHelper;
|
||||||
|
#endif
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
[UnityEngine.Scripting.Preserve]
|
[UnityEngine.Scripting.Preserve]
|
||||||
|
|||||||
@@ -253,7 +253,15 @@ namespace XCharts.Runtime
|
|||||||
else
|
else
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
public T EnsureChartComponent<T>() where T : MainComponent
|
||||||
|
{
|
||||||
|
var component = GetChartComponent<T>();
|
||||||
|
if (component == null)
|
||||||
|
return AddChartComponent<T>();
|
||||||
|
else
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
public bool TryGetChartComponent<T>(out T component, int index = 0)
|
public bool TryGetChartComponent<T>(out T component, int index = 0)
|
||||||
where T : MainComponent
|
where T : MainComponent
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace XCharts.Runtime
|
|||||||
{
|
{
|
||||||
[AddComponentMenu("XCharts/EmptyChart", 10)]
|
[AddComponentMenu("XCharts/EmptyChart", 10)]
|
||||||
[ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
[RequireComponent(typeof(RectTransform))]
|
[RequireComponent(typeof(RectTransform),typeof(CanvasRenderer))]
|
||||||
[DisallowMultipleComponent]
|
[DisallowMultipleComponent]
|
||||||
public partial class BaseChart : BaseGraph, ISerializationCallbackReceiver
|
public partial class BaseChart : BaseGraph, ISerializationCallbackReceiver
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ using System;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
#if INPUT_SYSTEM_ENABLED
|
||||||
|
using Input = XCharts.Runtime.InputHelper;
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace XCharts.Runtime
|
namespace XCharts.Runtime
|
||||||
{
|
{
|
||||||
@@ -9,302 +12,303 @@ namespace XCharts.Runtime
|
|||||||
public partial class BaseGraph : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
|
public partial class BaseGraph : MaskableGraphic, IPointerDownHandler, IPointerUpHandler,
|
||||||
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
|
IPointerEnterHandler, IPointerExitHandler, IBeginDragHandler, IPointerClickHandler,
|
||||||
IDragHandler, IEndDragHandler, IScrollHandler
|
IDragHandler, IEndDragHandler, IScrollHandler
|
||||||
|
{
|
||||||
|
[SerializeField] protected bool m_EnableTextMeshPro = false;
|
||||||
|
|
||||||
|
protected Painter m_Painter;
|
||||||
|
protected int m_SiblingIndex;
|
||||||
|
|
||||||
|
protected float m_GraphWidth;
|
||||||
|
protected float m_GraphHeight;
|
||||||
|
protected float m_GraphX;
|
||||||
|
protected float m_GraphY;
|
||||||
|
protected Vector3 m_GraphPosition = Vector3.zero;
|
||||||
|
protected Vector2 m_GraphMinAnchor;
|
||||||
|
protected Vector2 m_GraphMaxAnchor;
|
||||||
|
protected Vector2 m_GraphPivot;
|
||||||
|
protected Vector2 m_GraphSizeDelta;
|
||||||
|
protected Vector2 m_GraphAnchoredPosition;
|
||||||
|
protected Rect m_GraphRect = new Rect(0, 0, 0, 0);
|
||||||
|
protected bool m_RefreshChart = false;
|
||||||
|
protected bool m_ForceOpenRaycastTarget;
|
||||||
|
protected bool m_IsControlledByLayout = false;
|
||||||
|
protected bool m_PainerDirty = false;
|
||||||
|
protected bool m_IsOnValidate = false;
|
||||||
|
protected Vector3 m_LastLocalPosition;
|
||||||
|
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnPointerClick;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnPointerDown;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnPointerUp;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnPointerEnter;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnPointerExit;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnBeginDrag;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnDrag;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnEndDrag;
|
||||||
|
protected Action<PointerEventData, BaseGraph> m_OnScroll;
|
||||||
|
|
||||||
|
public virtual HideFlags chartHideFlags { get { return HideFlags.None; } }
|
||||||
|
|
||||||
|
private ScrollRect m_ScrollRect;
|
||||||
|
|
||||||
|
public Painter painter { get { return m_Painter; } }
|
||||||
|
|
||||||
|
protected virtual void InitComponent()
|
||||||
{
|
{
|
||||||
[SerializeField] protected bool m_EnableTextMeshPro = false;
|
InitPainter();
|
||||||
|
}
|
||||||
|
|
||||||
protected Painter m_Painter;
|
protected override void Awake()
|
||||||
protected int m_SiblingIndex;
|
{
|
||||||
|
CheckTextMeshPro();
|
||||||
|
m_SiblingIndex = 0;
|
||||||
|
m_LastLocalPosition = transform.localPosition;
|
||||||
|
UpdateSize();
|
||||||
|
InitComponent();
|
||||||
|
CheckIsInScrollRect();
|
||||||
|
}
|
||||||
|
|
||||||
protected float m_GraphWidth;
|
protected override void Start()
|
||||||
protected float m_GraphHeight;
|
{
|
||||||
protected float m_GraphX;
|
m_RefreshChart = true;
|
||||||
protected float m_GraphY;
|
}
|
||||||
protected Vector3 m_GraphPosition = Vector3.zero;
|
|
||||||
protected Vector2 m_GraphMinAnchor;
|
|
||||||
protected Vector2 m_GraphMaxAnchor;
|
|
||||||
protected Vector2 m_GraphPivot;
|
|
||||||
protected Vector2 m_GraphSizeDelta;
|
|
||||||
protected Vector2 m_GraphAnchoredPosition;
|
|
||||||
protected Rect m_GraphRect = new Rect(0, 0, 0, 0);
|
|
||||||
protected bool m_RefreshChart = false;
|
|
||||||
protected bool m_ForceOpenRaycastTarget;
|
|
||||||
protected bool m_IsControlledByLayout = false;
|
|
||||||
protected bool m_PainerDirty = false;
|
|
||||||
protected bool m_IsOnValidate = false;
|
|
||||||
protected Vector3 m_LastLocalPosition;
|
|
||||||
|
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnPointerClick;
|
protected virtual void Update()
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnPointerDown;
|
{
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnPointerUp;
|
CheckSize();
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnPointerEnter;
|
if (m_IsOnValidate)
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnPointerExit;
|
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnBeginDrag;
|
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnDrag;
|
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnEndDrag;
|
|
||||||
protected Action<PointerEventData, BaseGraph> m_OnScroll;
|
|
||||||
|
|
||||||
public virtual HideFlags chartHideFlags { get { return HideFlags.None; } }
|
|
||||||
|
|
||||||
private ScrollRect m_ScrollRect;
|
|
||||||
|
|
||||||
public Painter painter { get { return m_Painter; } }
|
|
||||||
|
|
||||||
protected virtual void InitComponent()
|
|
||||||
{
|
|
||||||
InitPainter();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Awake()
|
|
||||||
{
|
{
|
||||||
|
m_IsOnValidate = false;
|
||||||
CheckTextMeshPro();
|
CheckTextMeshPro();
|
||||||
m_SiblingIndex = 0;
|
|
||||||
m_LastLocalPosition = transform.localPosition;
|
|
||||||
UpdateSize();
|
|
||||||
InitComponent();
|
InitComponent();
|
||||||
CheckIsInScrollRect();
|
RefreshGraph();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
protected override void Start()
|
|
||||||
{
|
{
|
||||||
m_RefreshChart = true;
|
CheckComponent();
|
||||||
}
|
}
|
||||||
|
CheckPointerPos();
|
||||||
|
CheckRefreshChart();
|
||||||
|
CheckRefreshPainter();
|
||||||
|
}
|
||||||
|
|
||||||
protected virtual void Update()
|
protected virtual void SetAllComponentDirty()
|
||||||
{
|
{
|
||||||
CheckSize();
|
|
||||||
if (m_IsOnValidate)
|
|
||||||
{
|
|
||||||
m_IsOnValidate = false;
|
|
||||||
CheckTextMeshPro();
|
|
||||||
InitComponent();
|
|
||||||
RefreshGraph();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CheckComponent();
|
|
||||||
}
|
|
||||||
CheckPointerPos();
|
|
||||||
CheckRefreshChart();
|
|
||||||
CheckRefreshPainter();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void SetAllComponentDirty()
|
|
||||||
{
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (!Application.isPlaying)
|
if (!Application.isPlaying)
|
||||||
{
|
|
||||||
m_IsOnValidate = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
m_PainerDirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void CheckComponent()
|
|
||||||
{
|
|
||||||
if (m_PainerDirty)
|
|
||||||
{
|
|
||||||
InitPainter();
|
|
||||||
m_PainerDirty = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckTextMeshPro()
|
|
||||||
{
|
|
||||||
#if dUI_TextMeshPro
|
|
||||||
var enableTextMeshPro = true;
|
|
||||||
#else
|
|
||||||
var enableTextMeshPro = false;
|
|
||||||
#endif
|
|
||||||
if (m_EnableTextMeshPro != enableTextMeshPro)
|
|
||||||
{
|
|
||||||
m_EnableTextMeshPro = enableTextMeshPro;
|
|
||||||
RebuildChartObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
protected override void Reset() { }
|
|
||||||
|
|
||||||
protected override void OnValidate()
|
|
||||||
{
|
{
|
||||||
m_IsOnValidate = true;
|
m_IsOnValidate = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
m_PainerDirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDestroy()
|
protected virtual void CheckComponent()
|
||||||
|
{
|
||||||
|
if (m_PainerDirty)
|
||||||
{
|
{
|
||||||
for (int i = transform.childCount - 1; i >= 0; i--)
|
InitPainter();
|
||||||
{
|
m_PainerDirty = false;
|
||||||
DestroyImmediate(transform.GetChild(i).gameObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void OnPopulateMesh(VertexHelper vh)
|
|
||||||
{
|
|
||||||
vh.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void InitPainter()
|
|
||||||
{
|
|
||||||
m_Painter = ChartHelper.AddPainterObject("painter_b", transform, m_GraphMinAnchor,
|
|
||||||
m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1);
|
|
||||||
m_Painter.type = Painter.Type.Base;
|
|
||||||
m_Painter.onPopulateMesh = OnDrawPainterBase;
|
|
||||||
m_Painter.transform.SetSiblingIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckSize()
|
|
||||||
{
|
|
||||||
var currWidth = rectTransform.rect.width;
|
|
||||||
var currHeight = rectTransform.rect.height;
|
|
||||||
|
|
||||||
if (m_GraphWidth == 0 && m_GraphHeight == 0 && (currWidth != 0 || currHeight != 0))
|
|
||||||
{
|
|
||||||
Awake();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_GraphWidth != currWidth ||
|
|
||||||
m_GraphHeight != currHeight ||
|
|
||||||
m_GraphMinAnchor != rectTransform.anchorMin ||
|
|
||||||
m_GraphMaxAnchor != rectTransform.anchorMax ||
|
|
||||||
m_GraphAnchoredPosition != rectTransform.anchoredPosition)
|
|
||||||
{
|
|
||||||
UpdateSize();
|
|
||||||
}
|
|
||||||
if (!ChartHelper.IsValueEqualsVector3(m_LastLocalPosition, transform.localPosition))
|
|
||||||
{
|
|
||||||
m_LastLocalPosition = transform.localPosition;
|
|
||||||
OnLocalPositionChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void UpdateSize()
|
|
||||||
{
|
|
||||||
m_GraphWidth = rectTransform.rect.width;
|
|
||||||
m_GraphHeight = rectTransform.rect.height;
|
|
||||||
|
|
||||||
m_GraphMaxAnchor = rectTransform.anchorMax;
|
|
||||||
m_GraphMinAnchor = rectTransform.anchorMin;
|
|
||||||
m_GraphSizeDelta = rectTransform.sizeDelta;
|
|
||||||
m_GraphAnchoredPosition = rectTransform.anchoredPosition;
|
|
||||||
|
|
||||||
rectTransform.pivot = LayerHelper.ResetChartPositionAndPivot(m_GraphMinAnchor, m_GraphMaxAnchor,
|
|
||||||
m_GraphWidth, m_GraphHeight, ref m_GraphX, ref m_GraphY);
|
|
||||||
m_GraphPivot = rectTransform.pivot;
|
|
||||||
|
|
||||||
m_GraphRect.x = m_GraphX;
|
|
||||||
m_GraphRect.y = m_GraphY;
|
|
||||||
m_GraphRect.width = m_GraphWidth;
|
|
||||||
m_GraphRect.height = m_GraphHeight;
|
|
||||||
m_GraphPosition.x = m_GraphX;
|
|
||||||
m_GraphPosition.y = m_GraphY;
|
|
||||||
|
|
||||||
OnSizeChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckPointerPos()
|
|
||||||
{
|
|
||||||
if (!isPointerInChart) return;
|
|
||||||
if (canvas == null) return;
|
|
||||||
Vector2 local;
|
|
||||||
if (!ScreenPointToChartPoint(Input.mousePosition, out local))
|
|
||||||
{
|
|
||||||
pointerPos = Vector2.zero;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pointerPos = local;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void CheckIsInScrollRect()
|
|
||||||
{
|
|
||||||
m_ScrollRect = GetComponentInParent<ScrollRect>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void CheckRefreshChart()
|
|
||||||
{
|
|
||||||
if (m_RefreshChart)
|
|
||||||
{
|
|
||||||
m_Painter.Refresh();
|
|
||||||
m_RefreshChart = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void CheckRefreshPainter()
|
|
||||||
{
|
|
||||||
m_Painter.CheckRefresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
internal virtual void RefreshPainter(Painter painter)
|
|
||||||
{
|
|
||||||
if (painter == null) return;
|
|
||||||
painter.Refresh();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnSizeChanged()
|
|
||||||
{
|
|
||||||
m_RefreshChart = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void OnLocalPositionChanged() { }
|
|
||||||
|
|
||||||
protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter)
|
|
||||||
{
|
|
||||||
DrawPainterBase(vh);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual void DrawPainterBase(VertexHelper vh) { }
|
|
||||||
|
|
||||||
public virtual void OnPointerClick(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_OnPointerClick != null) m_OnPointerClick(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnPointerDown(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_OnPointerDown != null) m_OnPointerDown(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnPointerUp(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_OnPointerUp != null) m_OnPointerUp(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnPointerEnter(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
isPointerInChart = true;
|
|
||||||
if (m_OnPointerEnter != null) m_OnPointerEnter(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnPointerExit(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
isPointerInChart = false;
|
|
||||||
if (m_OnPointerExit != null) m_OnPointerExit(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnBeginDrag(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_ScrollRect != null) m_ScrollRect.OnBeginDrag(eventData);
|
|
||||||
if (m_OnBeginDrag != null) m_OnBeginDrag(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnEndDrag(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_ScrollRect != null) m_ScrollRect.OnEndDrag(eventData);
|
|
||||||
if (m_OnEndDrag != null) m_OnEndDrag(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnDrag(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_ScrollRect != null) m_ScrollRect.OnDrag(eventData);
|
|
||||||
if (m_OnDrag != null) m_OnDrag(eventData, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void OnScroll(PointerEventData eventData)
|
|
||||||
{
|
|
||||||
if (m_ScrollRect != null) m_ScrollRect.OnScroll(eventData);
|
|
||||||
if (m_OnScroll != null) m_OnScroll(eventData, this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CheckTextMeshPro()
|
||||||
|
{
|
||||||
|
#if dUI_TextMeshPro
|
||||||
|
var enableTextMeshPro = true;
|
||||||
|
#else
|
||||||
|
var enableTextMeshPro = false;
|
||||||
|
#endif
|
||||||
|
if (m_EnableTextMeshPro != enableTextMeshPro)
|
||||||
|
{
|
||||||
|
m_EnableTextMeshPro = enableTextMeshPro;
|
||||||
|
RebuildChartObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
protected override void Reset() { }
|
||||||
|
|
||||||
|
protected override void OnValidate()
|
||||||
|
{
|
||||||
|
m_IsOnValidate = true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
protected override void OnDestroy()
|
||||||
|
{
|
||||||
|
for (int i = transform.childCount - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
DestroyImmediate(transform.GetChild(i).gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnPopulateMesh(VertexHelper vh)
|
||||||
|
{
|
||||||
|
vh.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void InitPainter()
|
||||||
|
{
|
||||||
|
m_Painter = ChartHelper.AddPainterObject("painter_b", transform, m_GraphMinAnchor,
|
||||||
|
m_GraphMaxAnchor, m_GraphPivot, new Vector2(m_GraphWidth, m_GraphHeight), chartHideFlags, 1);
|
||||||
|
m_Painter.type = Painter.Type.Base;
|
||||||
|
m_Painter.onPopulateMesh = OnDrawPainterBase;
|
||||||
|
m_Painter.transform.SetSiblingIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckSize()
|
||||||
|
{
|
||||||
|
var currWidth = rectTransform.rect.width;
|
||||||
|
var currHeight = rectTransform.rect.height;
|
||||||
|
|
||||||
|
if (m_GraphWidth == 0 && m_GraphHeight == 0 && (currWidth != 0 || currHeight != 0))
|
||||||
|
{
|
||||||
|
Awake();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_GraphWidth != currWidth ||
|
||||||
|
m_GraphHeight != currHeight ||
|
||||||
|
m_GraphMinAnchor != rectTransform.anchorMin ||
|
||||||
|
m_GraphMaxAnchor != rectTransform.anchorMax ||
|
||||||
|
m_GraphAnchoredPosition != rectTransform.anchoredPosition)
|
||||||
|
{
|
||||||
|
UpdateSize();
|
||||||
|
}
|
||||||
|
if (!ChartHelper.IsValueEqualsVector3(m_LastLocalPosition, transform.localPosition))
|
||||||
|
{
|
||||||
|
m_LastLocalPosition = transform.localPosition;
|
||||||
|
OnLocalPositionChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void UpdateSize()
|
||||||
|
{
|
||||||
|
m_GraphWidth = rectTransform.rect.width;
|
||||||
|
m_GraphHeight = rectTransform.rect.height;
|
||||||
|
|
||||||
|
m_GraphMaxAnchor = rectTransform.anchorMax;
|
||||||
|
m_GraphMinAnchor = rectTransform.anchorMin;
|
||||||
|
m_GraphSizeDelta = rectTransform.sizeDelta;
|
||||||
|
m_GraphAnchoredPosition = rectTransform.anchoredPosition;
|
||||||
|
|
||||||
|
rectTransform.pivot = LayerHelper.ResetChartPositionAndPivot(m_GraphMinAnchor, m_GraphMaxAnchor,
|
||||||
|
m_GraphWidth, m_GraphHeight, ref m_GraphX, ref m_GraphY);
|
||||||
|
m_GraphPivot = rectTransform.pivot;
|
||||||
|
|
||||||
|
m_GraphRect.x = m_GraphX;
|
||||||
|
m_GraphRect.y = m_GraphY;
|
||||||
|
m_GraphRect.width = m_GraphWidth;
|
||||||
|
m_GraphRect.height = m_GraphHeight;
|
||||||
|
m_GraphPosition.x = m_GraphX;
|
||||||
|
m_GraphPosition.y = m_GraphY;
|
||||||
|
|
||||||
|
OnSizeChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckPointerPos()
|
||||||
|
{
|
||||||
|
if (!isPointerInChart) return;
|
||||||
|
if (canvas == null) return;
|
||||||
|
Vector2 mousePos = Input.mousePosition;
|
||||||
|
Vector2 local;
|
||||||
|
if (!ScreenPointToChartPoint(mousePos, out local))
|
||||||
|
{
|
||||||
|
pointerPos = Vector2.zero;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pointerPos = local;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void CheckIsInScrollRect()
|
||||||
|
{
|
||||||
|
m_ScrollRect = GetComponentInParent<ScrollRect>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void CheckRefreshChart()
|
||||||
|
{
|
||||||
|
if (m_RefreshChart)
|
||||||
|
{
|
||||||
|
m_Painter.Refresh();
|
||||||
|
m_RefreshChart = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void CheckRefreshPainter()
|
||||||
|
{
|
||||||
|
m_Painter.CheckRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal virtual void RefreshPainter(Painter painter)
|
||||||
|
{
|
||||||
|
if (painter == null) return;
|
||||||
|
painter.Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnSizeChanged()
|
||||||
|
{
|
||||||
|
m_RefreshChart = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void OnLocalPositionChanged() { }
|
||||||
|
|
||||||
|
protected virtual void OnDrawPainterBase(VertexHelper vh, Painter painter)
|
||||||
|
{
|
||||||
|
DrawPainterBase(vh);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void DrawPainterBase(VertexHelper vh) { }
|
||||||
|
|
||||||
|
public virtual void OnPointerClick(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_OnPointerClick != null) m_OnPointerClick(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPointerDown(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_OnPointerDown != null) m_OnPointerDown(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPointerUp(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_OnPointerUp != null) m_OnPointerUp(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPointerEnter(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
isPointerInChart = true;
|
||||||
|
if (m_OnPointerEnter != null) m_OnPointerEnter(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnPointerExit(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
isPointerInChart = false;
|
||||||
|
if (m_OnPointerExit != null) m_OnPointerExit(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnBeginDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_ScrollRect != null) m_ScrollRect.OnBeginDrag(eventData);
|
||||||
|
if (m_OnBeginDrag != null) m_OnBeginDrag(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnEndDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_ScrollRect != null) m_ScrollRect.OnEndDrag(eventData);
|
||||||
|
if (m_OnEndDrag != null) m_OnEndDrag(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_ScrollRect != null) m_ScrollRect.OnDrag(eventData);
|
||||||
|
if (m_OnDrag != null) m_OnDrag(eventData, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual void OnScroll(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (m_ScrollRect != null) m_ScrollRect.OnScroll(eventData);
|
||||||
|
if (m_OnScroll != null) m_OnScroll(eventData, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
111
Runtime/Internal/Utilities/InputHelper.cs
Normal file
111
Runtime/Internal/Utilities/InputHelper.cs
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
#if INPUT_SYSTEM_ENABLED
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
using UnityEngine.InputSystem.LowLevel;
|
||||||
|
|
||||||
|
namespace XCharts.Runtime
|
||||||
|
{
|
||||||
|
public class InputHelper
|
||||||
|
{
|
||||||
|
public static Vector2 mousePosition
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var value = Vector2.zero;
|
||||||
|
if (null != Mouse.current)
|
||||||
|
{
|
||||||
|
value = Mouse.current.position.ReadValue();
|
||||||
|
}
|
||||||
|
else if (null != Touchscreen.current && Touchscreen.current.touches.Count > 0)
|
||||||
|
{
|
||||||
|
value = Touchscreen.current.touches[0].position.ReadValue();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static int touchCount
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
var value = 0;
|
||||||
|
if (null != Touchscreen.current)
|
||||||
|
{
|
||||||
|
value = Touchscreen.current.touches.Count;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Touch GetTouch(int v)
|
||||||
|
{
|
||||||
|
UnityEngine.TouchPhase PhaseConvert(TouchState state)
|
||||||
|
{
|
||||||
|
UnityEngine.TouchPhase temp = UnityEngine.TouchPhase.Began;
|
||||||
|
switch (state.phase)
|
||||||
|
{
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.Began:
|
||||||
|
temp = UnityEngine.TouchPhase.Began;
|
||||||
|
break;
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.Moved:
|
||||||
|
temp = UnityEngine.TouchPhase.Moved;
|
||||||
|
break;
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.Canceled:
|
||||||
|
temp = UnityEngine.TouchPhase.Canceled;
|
||||||
|
break;
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.Stationary:
|
||||||
|
temp = UnityEngine.TouchPhase.Stationary;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.Ended:
|
||||||
|
case UnityEngine.InputSystem.TouchPhase.None:
|
||||||
|
temp = UnityEngine.TouchPhase.Ended;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
var touch = Touchscreen.current.touches[v];
|
||||||
|
var value = touch.ReadValue();
|
||||||
|
//copy touchcontrol's touchstate data into touch
|
||||||
|
return new Touch
|
||||||
|
{
|
||||||
|
deltaPosition = value.delta,
|
||||||
|
fingerId = value.touchId,
|
||||||
|
position = value.position,
|
||||||
|
phase = PhaseConvert(value),
|
||||||
|
pressure = value.pressure,
|
||||||
|
radius = value.radius.magnitude,
|
||||||
|
radiusVariance = value.radius.sqrMagnitude,
|
||||||
|
type = value.isPrimaryTouch ? TouchType.Direct : TouchType.Indirect,
|
||||||
|
tapCount = value.tapCount,
|
||||||
|
deltaTime = Time.realtimeSinceStartup - (float)value.startTime,
|
||||||
|
rawPosition = value.startPosition,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetKeyDown(KeyCode keyCode)
|
||||||
|
{
|
||||||
|
var value = false;
|
||||||
|
if (null != Keyboard.current)
|
||||||
|
{
|
||||||
|
var key = Keyboard.current.spaceKey;
|
||||||
|
switch (keyCode)
|
||||||
|
{
|
||||||
|
case KeyCode.Space:
|
||||||
|
key = Keyboard.current.spaceKey;
|
||||||
|
break;
|
||||||
|
case KeyCode.L:
|
||||||
|
key = Keyboard.current.lKey;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Debug.LogError($"{nameof(InputHelper)}: not support {keyCode} yet , please add it yourself if needed");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
value = key.wasPressedThisFrame;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
11
Runtime/Internal/Utilities/InputHelper.cs.meta
Normal file
11
Runtime/Internal/Utilities/InputHelper.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5069defa9fe8c7a43843e1189e2d606c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,13 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "XCharts.Runtime",
|
"name": "XCharts.Runtime",
|
||||||
"references": [
|
"references": [],
|
||||||
],
|
|
||||||
"optionalUnityReferences": [],
|
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
"allowUnsafeCode": false,
|
"allowUnsafeCode": false,
|
||||||
"overrideReferences": false,
|
"overrideReferences": false,
|
||||||
"precompiledReferences": [],
|
"precompiledReferences": [],
|
||||||
"autoReferenced": true,
|
"autoReferenced": true,
|
||||||
"defineConstraints": []
|
"defineConstraints": [],
|
||||||
|
"versionDefines": [],
|
||||||
|
"noEngineReferences": false
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user