You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.6 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class touchVisualizer : MonoBehaviour
{
public Transform debug_canvas;
public RectTransform _rect;
Dictionary<int, RectTransform> debug_touches = new Dictionary<int, RectTransform>();
// Update is called once per frame
void Update()
{
if (GetComponent<tuio_event>().VisualizeTouches)
debug_canvas.GetComponent<CanvasGroup>().alpha = 1f;
else
debug_canvas.GetComponent<CanvasGroup>().alpha = 0f;
var touches = TUIOManager.Instance.touches;
foreach (var id in touches.Keys)
{
RectTransform tran = null;
if (debug_touches.ContainsKey(id) == false)
{
GameObject t = Instantiate(_rect.gameObject, debug_canvas);
t.name = "debug" + id.ToString();
tran = t.GetComponent<RectTransform>();
debug_touches.Add(id, tran);
tran.position = touches[id].position;
}
else
{
tran = debug_touches[id];
tran.position = touches[id].position;
}
}
var removes = new HashSet<int>();
foreach (var id in debug_touches.Keys)
{
if (touches.ContainsKey(id) == false) // remove
{
removes.Add(id);
}
}
foreach (var id in removes)
{
debug_touches.Remove(id);
Destroy(GameObject.Find("debug" + id.ToString()));
}
}
}