using System.Collections; using System.Collections.Generic; using UnityEngine; 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); t.name = "debug" + id.ToString(); tran = t.GetComponent(); debug_touches.Add(id, tran); var rt = tran.transform as RectTransform; rt.anchoredPosition = touches[id].position; //tran.position = touches[id].position; } else { tran = debug_touches[id]; tran.position = 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())); } } }