using UnityEngine; using UnityEngine.UI; public class HeatmapVisualizer : MonoBehaviour { public Material material; Image heatmapImage; void Start() { heatmapImage = GetComponent(); } void Update() { var feature = HeatmapRendererFeature.Instance; if (feature == null) return; var texture = feature.GetHeatmapTexture(); if (texture != null) { material.SetTexture("_MainTex", texture); } if (heatmapImage && texture != null) { Texture2D texture2D = new Texture2D(texture.rt.width, texture.rt.height, TextureFormat.RFloat, false); RenderTexture.active = texture; texture2D.ReadPixels(new Rect(0, 0, texture.rt.width, texture.rt.height), 0, 0); texture2D.Apply(); heatmapImage.sprite = Sprite.Create(texture2D, new Rect(0, 0, texture.rt.width, texture.rt.height), new Vector2(0.5f, 0.5f)); } } }