mirror of
https://github.com/XCharts-Team/XCharts.git
synced 2026-05-28 12:08:46 +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`。
|
||||
- 支持所有`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)
|
||||
{
|
||||
m_StartLabel.SetPosition(pos);
|
||||
if (m_StartLabel != null) m_StartLabel.SetPosition(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)
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
#if INPUT_SYSTEM_ENABLED
|
||||
using Input = XCharts.Runtime.InputHelper;
|
||||
#endif
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
|
||||
@@ -3,7 +3,9 @@ using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using XUGL;
|
||||
|
||||
#if INPUT_SYSTEM_ENABLED
|
||||
using Input = XCharts.Runtime.InputHelper;
|
||||
#endif
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
[UnityEngine.Scripting.Preserve]
|
||||
|
||||
@@ -253,6 +253,14 @@ namespace XCharts.Runtime
|
||||
else
|
||||
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)
|
||||
where T : MainComponent
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace XCharts.Runtime
|
||||
{
|
||||
[AddComponentMenu("XCharts/EmptyChart", 10)]
|
||||
[ExecuteInEditMode]
|
||||
[RequireComponent(typeof(RectTransform))]
|
||||
[RequireComponent(typeof(RectTransform),typeof(CanvasRenderer))]
|
||||
[DisallowMultipleComponent]
|
||||
public partial class BaseChart : BaseGraph, ISerializationCallbackReceiver
|
||||
{
|
||||
|
||||
@@ -2,6 +2,9 @@ using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
#if INPUT_SYSTEM_ENABLED
|
||||
using Input = XCharts.Runtime.InputHelper;
|
||||
#endif
|
||||
|
||||
namespace XCharts.Runtime
|
||||
{
|
||||
@@ -206,8 +209,9 @@ namespace XCharts.Runtime
|
||||
{
|
||||
if (!isPointerInChart) return;
|
||||
if (canvas == null) return;
|
||||
Vector2 mousePos = Input.mousePosition;
|
||||
Vector2 local;
|
||||
if (!ScreenPointToChartPoint(Input.mousePosition, out local))
|
||||
if (!ScreenPointToChartPoint(mousePos, out local))
|
||||
{
|
||||
pointerPos = Vector2.zero;
|
||||
}
|
||||
|
||||
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",
|
||||
"references": [
|
||||
],
|
||||
"optionalUnityReferences": [],
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": []
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
Reference in New Issue
Block a user