Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

69 lines
1.5 KiB

using UnityEngine;
namespace LeTai.TrueShadow
{
[RequireComponent(typeof(TrueShadow))]
public class InsetOnPress : AnimatedBiStateButton
{
TrueShadow[] shadows;
float[] normalOpacity;
bool wasInset;
void OnEnable()
{
shadows = GetComponents<TrueShadow>();
normalOpacity = new float[shadows.Length];
}
protected override void Animate(float visualPressAmount)
{
void SetAllOpacity(float lerpProgress)
{
for (var i = 0; i < shadows.Length; i++)
{
var color = shadows[i].Color;
color.a = Mathf.Lerp(0, normalOpacity[i], lerpProgress);
shadows[i].Color = color;
}
}
bool shouldInset = visualPressAmount > .5f;
if (shouldInset != wasInset)
{
for (var i = 0; i < shadows.Length; i++)
{
shadows[i].Inset = shouldInset;
}
wasInset = shouldInset;
}
if (shouldInset)
{
SetAllOpacity(visualPressAmount * 2f - 1f);
}
else
{
SetAllOpacity(1 - visualPressAmount * 2f);
}
}
void MemorizeOpacity()
{
if (IsAnimating) return;
for (var i = 0; i < shadows.Length; i++)
{
normalOpacity[i] = shadows[i].Color.a;
}
}
protected override void OnWillPress()
{
wasInset = shadows[0].Inset;
MemorizeOpacity();
base.OnWillPress();
}
}
}