1
0
mirror of https://github.com/xiaopeng12138/MaiDXR.git synced 2024-11-28 04:50:48 +01:00
MaiDXR/Assets/Scripts/TouchPanelManager.cs

39 lines
1.2 KiB
C#
Raw Normal View History

2022-08-12 02:20:00 +02:00
using UnityEngine;
using System;
public class TouchPanelManager : MonoBehaviour
{
2022-08-16 23:22:52 +02:00
int Area;
2022-08-12 02:20:00 +02:00
private int _insideColliderCount = 0;
public static event Action touchDidChange;
2022-08-16 23:22:52 +02:00
void Start()
{
Area = (int)Enum.Parse(typeof(TouchArea), gameObject.name);
}
2022-08-12 02:20:00 +02:00
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
SerialManager.ChangeTouch(true, (int)Area, true);
touchDidChange?.Invoke();
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
if (_insideColliderCount == 0)
{
SerialManager.ChangeTouch(true, (int)Area, false);
touchDidChange?.Invoke();
}
}
2022-08-16 23:22:52 +02:00
enum TouchArea
{
A1 = 0, A2 = 1, A3 = 2, A4 = 3, A5 = 4,
A6 = 8, A7 = 9, A8 = 10, B1 = 11, B2 = 12,
B3 = 16, B4 = 17, B5 = 18, B6 = 19, B7 = 20,
B8 = 24, C1 = 25, C2 = 26, D1 = 27, D2 = 28,
D3 = 32, D4 = 33, D5 = 34, D6 = 35, D7 = 36,
D8 = 40, E1 = 41, E2 = 42, E3 = 43, E4 = 44,
E5 = 48, E6 = 49, E7 = 50, E8 = 51,
}
2022-08-12 02:20:00 +02:00
}