55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
//using System.Drawing;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HeatMapController : MonoBehaviour
|
|
{
|
|
public Material heatMaterial; // 需要传递数据的材质
|
|
|
|
public Transform[]Pos;
|
|
|
|
[HideInInspector]
|
|
private Vector4[] points = new Vector4[7]; // 存储6个点的数组,(x, y, z) = center, w = temperature
|
|
|
|
[HideInInspector]
|
|
private Vector4[] properties = new Vector4[7]; // 存储6个盒子大小的数组, (x,y) = boxsize
|
|
|
|
public Slider slider;
|
|
|
|
//public Texture2D hotspotShapeTexture; // 引用热点形状纹理
|
|
|
|
|
|
private float tempture;
|
|
|
|
void Start()
|
|
{
|
|
tempture=slider.value;
|
|
// 初始化数据,这里是示例,你可以根据实际需求设置
|
|
SetDataToMaterial();
|
|
|
|
}
|
|
public void SetDataToMaterial()
|
|
{
|
|
tempture=slider.value;
|
|
|
|
tempture=Map(tempture,0,1,0.5f,2.3f);
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
RectTransform transform=Pos[i].GetComponent<RectTransform>();
|
|
|
|
points[i] = new Vector4(Pos[i].position.x, Pos[i].position.y, tempture, 0); // (x, y, z, temperature)
|
|
properties[i] = new Vector4(transform.rect.width*1, transform.rect.height*1, 0.0f, 0.0f); // (boxsize x, boxsize y, unused, unused)
|
|
}
|
|
|
|
// 将数据传递给 Shader
|
|
heatMaterial.SetVectorArray("_Points", points);
|
|
heatMaterial.SetVectorArray("_Properties", properties);
|
|
|
|
}
|
|
float Map(float value, float minSource, float maxSource, float minTarget, float maxTarget)
|
|
{
|
|
return minTarget + (value - minSource) * (maxTarget - minTarget) / (maxSource - minSource);
|
|
}
|
|
}
|
|
|