180 lines
5.5 KiB
C#
180 lines
5.5 KiB
C#
//using System.Drawing;
|
|
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Yarn.Unity;
|
|
using DG.Tweening;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using AibisDream;
|
|
using AibisDream.FixSystem;
|
|
|
|
public class HeatMapController : MonoBehaviour
|
|
{
|
|
public Material heatMaterial; // 需要传递数据的材质
|
|
|
|
public Transform[] Pos;
|
|
|
|
private BodyModuleSystem bodyModuleSystem;
|
|
|
|
public GameObject heatmapGameobject;
|
|
|
|
[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;
|
|
private float tempNum = 0;
|
|
|
|
private float uftempture = 1;
|
|
private float backtemture = 1;
|
|
|
|
private float modulesTempture = 1;
|
|
|
|
//public float uf=1;
|
|
//public float back=1;
|
|
|
|
//public float module=0.7f;
|
|
//public Texture2D hotspotShapeTexture; // 引用热点形状纹理
|
|
|
|
private float tempture = 1;
|
|
|
|
//public GameObject heatMap;
|
|
public float Tempture
|
|
{
|
|
get => tempture;
|
|
set
|
|
{
|
|
if (tempture != value)
|
|
{
|
|
tempture = value;
|
|
SetDataToMaterial(); // 调用方法更新材质数据
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ShowHeatMap()
|
|
{
|
|
heatmapGameobject.SetActive(true);
|
|
heatmapGameobject.GetComponent<DraggableUI>().isDone = false;
|
|
}
|
|
public void HideHeatMap()
|
|
{
|
|
heatmapGameobject.SetActive(false);
|
|
}
|
|
|
|
public void StartCooling()
|
|
{
|
|
StartCoroutine(ReduceValueCoroutine());
|
|
}
|
|
|
|
IEnumerator ReduceValueCoroutine()
|
|
{
|
|
if (Tempture>=2)
|
|
{
|
|
Debug.Log("降温失败");
|
|
heatmapGameobject.GetComponent<DraggableUI>().isDone = true;
|
|
yield return new WaitForSeconds(1);
|
|
if(DialogController.Instance!=null)
|
|
DialogController.Instance.StartDialogNode("降温失败");
|
|
yield break;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("降温成功");
|
|
heatmapGameobject.GetComponent<DraggableUI>().isDone = true;
|
|
float duration = 2f;
|
|
SetTemptureSmooth(0,duration);
|
|
yield return new WaitForSeconds(duration);
|
|
DialogController.Instance.StartDialogNode("降温成功");
|
|
bodyModuleSystem.OnCooling();
|
|
Debug.Log("Value has reached zero.");
|
|
}
|
|
}
|
|
void Start()
|
|
{
|
|
bodyModuleSystem=FindObjectOfType<BodyModuleSystem>();
|
|
// // 初始调用,设置初始位置
|
|
//tempture=1;
|
|
// // 初始化数据,这里是示例,你可以根据实际需求设置
|
|
SetDataToMaterial();
|
|
}
|
|
|
|
|
|
// public void SetTemture(float value)
|
|
// {
|
|
// tempture=value;
|
|
|
|
// }
|
|
|
|
public void SetDataToMaterial()
|
|
{
|
|
|
|
if (tempture >=0&&tempture<=1)
|
|
{
|
|
uftempture = Mathf.Lerp(1.5f, 2.8f, tempture ); // 线性插值
|
|
modulesTempture = Mathf.Lerp(1.5f, 1.8f, tempture);
|
|
backtemture = Mathf.Lerp(1.5f, 2.25f, tempture);
|
|
}
|
|
else if (tempture >= 1&&tempture<=2)
|
|
{
|
|
uftempture = Mathf.Lerp(2.8f, 3.2f, tempture - 1);
|
|
modulesTempture = Mathf.Lerp(1.8f, 2.3f, tempture - 1);
|
|
backtemture = Mathf.Lerp(2.25f, 3.4f, tempture - 1);
|
|
}
|
|
// else if (tempture >= 2)
|
|
// {
|
|
// uftempture =3.2f;
|
|
// modulesTempture = 2.6f;
|
|
// backtemture = 3.8f;
|
|
// }
|
|
|
|
|
|
for (int i = 0; i < 7; i++)
|
|
{
|
|
//RectTransform transform=Pos[i].GetComponent<RectTransform>();
|
|
Transform currentTransform=Pos[i].GetComponent<Transform>();
|
|
Debug.Log($"Point {i}: {points[i]}");
|
|
|
|
if (i == 0)
|
|
{
|
|
points[i] = new Vector4(Pos[i].position.x, Pos[i].position.y, uftempture, 0);
|
|
}
|
|
else if (i == 6)
|
|
{
|
|
points[i] = new Vector4(Pos[i].position.x, Pos[i].position.y, backtemture, 0);
|
|
}
|
|
else
|
|
{
|
|
points[i] = new Vector4(Pos[i].position.x, Pos[i].position.y, modulesTempture, 0); // (x, y, z, temperature)
|
|
|
|
}
|
|
Sprite currentSprite=currentTransform.GetComponent<SpriteRenderer>().sprite;
|
|
properties[i] = new Vector4(currentSprite.bounds.size.x, currentSprite.bounds.size.y, 0.0f, 0.0f); // (boxsize x, boxsize y, unused, unused)
|
|
Debug.Log($"Point {i}: {currentSprite.bounds.size.x}");
|
|
//properties[i] = new Vector4(transform.rect.width*1, transform.rect.height*1, 0.0f, 0.0f); // (boxsize x, boxsize y, unused, unused)
|
|
//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);
|
|
}
|
|
public void SetTemptureDirect(float value)
|
|
{
|
|
Tempture = value;
|
|
}
|
|
|
|
public void SetTemptureSmooth(float targetValue, float duration)
|
|
{
|
|
DOTween.To(() => tempture, x => Tempture = x, targetValue, duration);
|
|
}
|
|
|
|
float Map(float value, float minSource, float maxSource, float minTarget, float maxTarget)
|
|
{
|
|
return minTarget + (value - minSource) * (maxTarget - minTarget) / (maxSource - minSource);
|
|
}
|
|
}
|
|
|