Files
Continentis/Assets/Scripts/MainGame/Card/CardView/CardViewFunctions.cs

107 lines
3.4 KiB
C#
Raw Normal View History

2025-10-23 00:49:44 -04:00
using DG.Tweening;
using UnityEngine;
namespace Continentis.MainGame.Card
{
public abstract partial class CardViewBase
{
2026-03-20 11:56:50 -04:00
private Tweener hintShadowTweener;
private Tweener selectShadowTweener;
2025-10-23 00:49:44 -04:00
public void ClearShadows()
{
hintShadowTweener?.Kill(true);
selectShadowTweener?.Kill(true);
hintShadow.gameObject.SetActive(false);
selectShadow.gameObject.SetActive(false);
}
public void TryDisableAllShadows(bool immediately = false)
{
DisableHintShadow(immediately);
DisableSelectShadow(immediately);
}
2026-03-20 11:56:50 -04:00
2025-10-23 00:49:44 -04:00
public void EnableHintShadow(Color shadowColor)
{
hintShadow.gameObject.SetActive(true);
hintShadow.color = Color.clear;
hintShadowTweener = hintShadow.DOColor(shadowColor, 0.2f).Play();
}
public void DisableHintShadow(bool immediately = false)
{
if (immediately)
{
hintShadowTweener?.Kill(true);
hintShadow.gameObject.SetActive(false);
}
else
{
2026-03-20 11:56:50 -04:00
hintShadowTweener = hintShadow.DOColor(Color.clear, 0.2f)
.OnComplete(() => { hintShadow.gameObject.SetActive(false); }).Play();
2025-10-23 00:49:44 -04:00
}
}
2026-04-01 12:23:27 -04:00
/// <summary>
/// 根据颜色智能更新提示阴影null 关闭,非 null 启用对应颜色。
/// 避免相同颜色重复 tween 导致闪烁。
/// </summary>
public void UpdateHintShadow(Color? color)
{
if (color == null)
{
if (hintShadow.gameObject.activeSelf)
{
DisableHintShadow();
}
return;
}
Color targetColor = color.Value;
if (hintShadow.gameObject.activeSelf)
{
// 已启用:仅在颜色差异足够大时 tween避免每帧闪烁
if (!ApproximatelyEqualColor(hintShadow.color, targetColor))
{
hintShadowTweener?.Kill();
hintShadowTweener = hintShadow.DOColor(targetColor, 0.2f).Play();
}
}
else
{
EnableHintShadow(targetColor);
}
}
private static bool ApproximatelyEqualColor(Color a, Color b, float tolerance = 0.01f)
{
return Mathf.Abs(a.r - b.r) < tolerance
&& Mathf.Abs(a.g - b.g) < tolerance
&& Mathf.Abs(a.b - b.b) < tolerance
&& Mathf.Abs(a.a - b.a) < tolerance;
}
2025-10-23 00:49:44 -04:00
public void EnableSelectShadow()
{
selectShadow.gameObject.SetActive(true);
selectShadow.color = Color.clear;
selectShadowTweener = selectShadow.DOColor(new Color(0.33f, 0.66f, 1f), 0.2f).Play();
}
public void DisableSelectShadow(bool immediately = false)
{
if (immediately)
{
selectShadowTweener?.Kill(true);
selectShadow.gameObject.SetActive(false);
}
else
{
2026-03-20 11:56:50 -04:00
selectShadowTweener = selectShadow.DOColor(Color.clear, 0.2f)
.OnComplete(() => { selectShadow.gameObject.SetActive(false); }).Play();
2025-10-23 00:49:44 -04:00
}
}
}
2026-03-20 11:56:50 -04:00
}