Files
Continentis/Assets/Scripts/MainGame/Card/CardView/CardViewFunctions.cs
SoulliesOfficial c3b1561375 更新
2026-04-01 12:23:27 -04:00

107 lines
3.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DG.Tweening;
using UnityEngine;
namespace Continentis.MainGame.Card
{
public abstract partial class CardViewBase
{
private Tweener hintShadowTweener;
private Tweener selectShadowTweener;
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);
}
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
{
hintShadowTweener = hintShadow.DOColor(Color.clear, 0.2f)
.OnComplete(() => { hintShadow.gameObject.SetActive(false); }).Play();
}
}
/// <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;
}
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
{
selectShadowTweener = selectShadow.DOColor(Color.clear, 0.2f)
.OnComplete(() => { selectShadow.gameObject.SetActive(false); }).Play();
}
}
}
}