1
0
mirror of synced 2024-12-14 07:12:54 +01:00
WACVR/Assets/Script/ColliderToSerial.cs
Kylemc1413 9c0f3dd989 Improve Touch Delay
Reduce Touch Overhead by only sending input state once a second to keep the game reading alive, on top of whenever a change in the state happens. Also add a small cube to the scene to use for debugging touch in editor when needed
2022-05-24 19:29:59 -04:00

40 lines
1016 B
C#

using UnityEngine;
using System.IO.Ports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class ColliderToSerial : MonoBehaviour
{
private Renderer cr;
private int _insideColliderCount = 0;
public static event Action touchDidChange;
private void Start()
{
cr = GetComponent<Renderer>();
}
private void OnTriggerEnter(Collider other)
{
_insideColliderCount += 1;
Serial.SetTouch(Convert.ToInt32(gameObject.name), true);
touchDidChange?.Invoke();
cr.material.color = new Color(1f, 1f, 1f, 1f);
}
private void OnTriggerExit(Collider other)
{
_insideColliderCount -= 1;
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
if (_insideColliderCount == 0)
{
Serial.SetTouch(Convert.ToInt32(gameObject.name), false);
touchDidChange?.Invoke();
cr.material.color = new Color(0f, 0f, 0f, 0f);
}
}
}