2022-05-16 23:38:40 +02:00
|
|
|
using UnityEngine;
|
|
|
|
using System.IO.Ports;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
public class ColliderToSerial : MonoBehaviour
|
|
|
|
{
|
2022-06-07 02:07:08 +02:00
|
|
|
public GameObject LightManager;
|
|
|
|
private LightManager lightManager;
|
2022-05-16 23:38:40 +02:00
|
|
|
private int _insideColliderCount = 0;
|
2022-05-25 01:29:59 +02:00
|
|
|
public static event Action touchDidChange;
|
2022-06-07 02:07:08 +02:00
|
|
|
private int Area;
|
|
|
|
private void Start()
|
2022-05-23 07:00:35 +02:00
|
|
|
{
|
2022-06-07 02:07:08 +02:00
|
|
|
Area = Convert.ToInt32(gameObject.name);
|
|
|
|
lightManager = LightManager.GetComponent<LightManager>();
|
2022-05-23 07:00:35 +02:00
|
|
|
}
|
2022-05-16 23:38:40 +02:00
|
|
|
private void OnTriggerEnter(Collider other)
|
|
|
|
{
|
|
|
|
_insideColliderCount += 1;
|
2022-06-07 02:07:08 +02:00
|
|
|
Serial.SetTouch(Area, true);
|
2022-05-25 01:29:59 +02:00
|
|
|
touchDidChange?.Invoke();
|
2022-07-29 18:49:56 +02:00
|
|
|
lightManager.UpdateLightFade(Area, true);
|
2022-05-16 23:38:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
|
|
{
|
|
|
|
_insideColliderCount -= 1;
|
|
|
|
_insideColliderCount = Mathf.Max(0, _insideColliderCount);
|
|
|
|
if (_insideColliderCount == 0)
|
|
|
|
{
|
2022-06-07 02:07:08 +02:00
|
|
|
Serial.SetTouch(Area, false);
|
2022-05-25 01:29:59 +02:00
|
|
|
touchDidChange?.Invoke();
|
2022-07-29 18:49:56 +02:00
|
|
|
lightManager.UpdateLightFade(Area, false);
|
2022-05-16 23:38:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|