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

3 years ago
  1. using UnityEngine;
  2. namespace LeTai.TrueShadow
  3. {
  4. [RequireComponent(typeof(TrueShadow))]
  5. public class InsetOnPress : AnimatedBiStateButton
  6. {
  7. TrueShadow[] shadows;
  8. float[] normalOpacity;
  9. bool wasInset;
  10. void OnEnable()
  11. {
  12. shadows = GetComponents<TrueShadow>();
  13. normalOpacity = new float[shadows.Length];
  14. }
  15. protected override void Animate(float visualPressAmount)
  16. {
  17. void SetAllOpacity(float lerpProgress)
  18. {
  19. for (var i = 0; i < shadows.Length; i++)
  20. {
  21. var color = shadows[i].Color;
  22. color.a = Mathf.Lerp(0, normalOpacity[i], lerpProgress);
  23. shadows[i].Color = color;
  24. }
  25. }
  26. bool shouldInset = visualPressAmount > .5f;
  27. if (shouldInset != wasInset)
  28. {
  29. for (var i = 0; i < shadows.Length; i++)
  30. {
  31. shadows[i].Inset = shouldInset;
  32. }
  33. wasInset = shouldInset;
  34. }
  35. if (shouldInset)
  36. {
  37. SetAllOpacity(visualPressAmount * 2f - 1f);
  38. }
  39. else
  40. {
  41. SetAllOpacity(1 - visualPressAmount * 2f);
  42. }
  43. }
  44. void MemorizeOpacity()
  45. {
  46. if (IsAnimating) return;
  47. for (var i = 0; i < shadows.Length; i++)
  48. {
  49. normalOpacity[i] = shadows[i].Color.a;
  50. }
  51. }
  52. protected override void OnWillPress()
  53. {
  54. wasInset = shadows[0].Inset;
  55. MemorizeOpacity();
  56. base.OnWillPress();
  57. }
  58. }
  59. }