diff --git a/Assets/Scenes/HuoShanFixScene.unity b/Assets/Scenes/HuoShanFixScene.unity index 1bbb41e70..e8b97844d 100644 --- a/Assets/Scenes/HuoShanFixScene.unity +++ b/Assets/Scenes/HuoShanFixScene.unity @@ -10194,15 +10194,15 @@ SpriteRenderer: m_SortingLayerID: 1134468525 m_SortingLayer: 10 m_SortingOrder: 4 - m_Sprite: {fileID: 21300000, guid: 7936cdb0ed1814d46968c96dbdcb90fa, type: 3} + m_Sprite: {fileID: 21300000, guid: 89c122ac23995894999ff246a846baff, type: 3} m_Color: {r: 1, g: 1, b: 1, a: 0} m_FlipX: 0 m_FlipY: 0 m_DrawMode: 0 - m_Size: {x: 2.36, y: 2.13} + m_Size: {x: 2.0232558, y: 1.4418604} m_AdaptiveModeThreshold: 0.5 m_SpriteTileMode: 0 - m_WasSpriteAssigned: 0 + m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 --- !u!1 &966944386 diff --git a/Assets/Scripts/FixSystem/HeatMap/HeatMapController.cs b/Assets/Scripts/FixSystem/HeatMap/HeatMapController.cs index 11d948692..6ebeeb6eb 100644 --- a/Assets/Scripts/FixSystem/HeatMap/HeatMapController.cs +++ b/Assets/Scripts/FixSystem/HeatMap/HeatMapController.cs @@ -30,23 +30,18 @@ public class HeatMapController : MonoBehaviour [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; + private Tween _temptureTween; + + /// 热力图面板当前是否在显示(用于 SetHeat 决定硬切还是平滑)。 + public bool IsHeatMapVisible => + heatmapGameobject != null && heatmapGameobject.activeInHierarchy; - //public GameObject heatMap; public float Tempture { get => tempture; @@ -71,6 +66,7 @@ public class HeatMapController : MonoBehaviour heatmapGameobject.transform.localPosition = outPos; heatmapGameobject.SetActive(true); + SetDataToMaterial(); heatmapGameobject.transform.DOLocalMove(inPos, 1f); yield return new WaitForSeconds(1f); // 等待动画完成 heatmapGameobject.GetComponent().UnlockDrag(); @@ -137,26 +133,31 @@ public class HeatMapController : MonoBehaviour void Start() { bodyModuleSystem = FindObjectOfType(); - // // 初始调用,设置初始位置 - //tempture=1; - // // 初始化数据,这里是示例,你可以根据实际需求设置 SetDataToMaterial(); } + void OnDestroy() + { + _temptureTween?.Kill(); + } + /// - /// 热点尺寸:优先 SpriteRenderer,其次 UI Image,最后用 RectTransform 尺寸。 + /// 热点尺寸(世界单位):自身 Sprite/Image → 父级 Sprite → RectTransform。 + /// UFheatmap 等空 Sprite 锚点会回退到父级 Module Pic,避免静默变成 (1,1) 导致热区偏小。 /// private static bool TryGetHotspotSize(Transform t, out Vector2 size) { size = default; if (t == null) return false; - var sr = t.GetComponent(); - if (sr != null && sr.sprite != null) - { - var b = sr.sprite.bounds.size; - size = new Vector2(b.x, b.y); + if (TryGetSpriteLocalSize(t, out size)) return true; + + // 空 SpriteRenderer / 纯锚点:沿父链找有 sprite 的模块图 + for (var p = t.parent; p != null; p = p.parent) + { + if (TryGetSpriteLocalSize(p, out size)) + return true; } var image = t.GetComponent(); @@ -176,27 +177,37 @@ public class HeatMapController : MonoBehaviour return false; } + private static bool TryGetSpriteLocalSize(Transform t, out Vector2 size) + { + size = default; + var sr = t.GetComponent(); + if (sr == null || sr.sprite == null) + return false; + + var b = sr.sprite.bounds.size; + var ls = t.lossyScale; + size = new Vector2(b.x * Mathf.Abs(ls.x), b.y * Mathf.Abs(ls.y)); + return size.x > 0.001f || size.y > 0.001f; + } + public void SetDataToMaterial() { - if (tempture >= 0 && tempture <= 1) + // 逻辑温度 0~2 → shader 侧发热强度;各段端点连续,避免跨档跳变。 + // t=0 冷态压低,接近「看不见」;t=1/2 保持原有发热观感。 + if (tempture <= 1f) { - uftempture = Mathf.Lerp(2.0f, 2.8f, tempture); // 线性插值 - modulesTempture = Mathf.Lerp(1.2f, 1.6f, tempture); - backtemture = Mathf.Lerp(1.5f, 2.25f, tempture); + float t = Mathf.Clamp01(tempture); + uftempture = Mathf.Lerp(0.85f, 2.8f, t); + modulesTempture = Mathf.Lerp(0.55f, 1.6f, t); + backtemture = Mathf.Lerp(0.7f, 2.25f, t); } - else if (tempture >= 1 && tempture <= 2) + else { - 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); + float t = Mathf.Clamp01(tempture - 1f); + uftempture = Mathf.Lerp(2.8f, 3.2f, t); + modulesTempture = Mathf.Lerp(1.6f, 2.3f, t); // 原 1.8 起点与上一段不连续 + backtemture = Mathf.Lerp(2.25f, 3.4f, t); } - // else if (tempture >= 2) - // { - // uftempture =3.2f; - // modulesTempture = 2.6f; - // backtemture = 3.8f; - // } - if (Pos == null || heatMaterial == null) return; @@ -227,7 +238,10 @@ public class HeatMapController : MonoBehaviour } if (!TryGetHotspotSize(currentTransform, out var boxSize)) + { + Debug.LogWarning($"[HeatMapController] Pos[{i}] '{Pos[i].name}' 无法取得热点尺寸,回退为 (1,1)。请检查 Sprite 或父级 Module Pic。", Pos[i]); boxSize = Vector2.one; + } properties[i] = new Vector4(boxSize.x, boxSize.y, 0.0f, 0.0f); } @@ -239,11 +253,15 @@ public class HeatMapController : MonoBehaviour public void SetTemptureDirect(float value) { + _temptureTween?.Kill(); Tempture = value; } public void SetTemptureSmooth(float targetValue, float duration) { - DOTween.To(() => tempture, x => Tempture = x, targetValue, duration); + _temptureTween?.Kill(); + _temptureTween = DOTween.To(() => tempture, x => Tempture = x, targetValue, duration) + .SetEase(Ease.InOutQuad) + .SetTarget(this); } -} \ No newline at end of file +} diff --git a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs index 38104e494..276f70d13 100644 --- a/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs +++ b/Assets/Scripts/FixSystemNew/BodyModule/BodyModuleSystem.cs @@ -231,13 +231,32 @@ namespace AibisDream.FixSystem } /// - /// 设置发热 + /// 设置发热。逻辑档位立即更新;视觉温度按热力图是否打开决定硬切/平滑, + /// 且降温动画已落到冷态附近时,Yarn 的 SetHeat(0) 不再把 0.5 硬切成 0。 /// public void SetHeat(int targetHeatValue) { HeatValue = targetHeatValue; - heatMapController?.SetTemptureDirect(HeatValue); + if (heatMapController == null) + return; + + // 降温协程已把视觉温度收到 ~0.5,随后对话里的 SetHeat(0) 只清逻辑,不冲掉视觉。 + if (targetHeatValue <= 0 && heatMapController.Tempture <= 0.55f) + return; + + bool mapVisible = heatMapController.IsHeatMapVisible; + if (mapVisible) + { + // 热力图已打开:升温/降温都走短 tween,避免档位硬切 + float duration = targetHeatValue <= 0 ? 0.6f : 1.0f; + heatMapController.SetTemptureSmooth(targetHeatValue, duration); + } + else + { + // 面板未显示:直接落到目标,打开时不会再闪一下 + heatMapController.SetTemptureDirect(targetHeatValue); + } } public void ShowHeatMap()