using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class touchVisualizer : MonoBehaviour { public RectTransform debug_canvas; public RectTransform _rect; Dictionary debug_touches = new Dictionary(); // Update is called once per frame void Update() { if (GetComponent().VisualizeTouches) debug_canvas.GetComponent().alpha = 1f; else debug_canvas.GetComponent().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); float r = Random.Range(0.5f, 1f); float g = Random.Range(0.5f, 1f); float b = Random.Range(0.5f, 1f); t.GetComponent().color = new Color(r, g, b); t.name = "debug" + id.ToString(); tran = t.GetComponent(); debug_touches.Add(id, tran); tran.anchoredPosition = touches[id].position; //tran.position = touches[id].position; } else { tran = debug_touches[id]; tran.anchoredPosition = touches[id].position; } } var removes = new HashSet(); 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())); } } }