SliderMath.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using static AnimationKeyInfo;
  4. namespace SliderUnlocker
  5. {
  6. public static class SliderMath
  7. {
  8. public static Vector3 CalculateScale(List<AnmKeyInfo> list, float rate)
  9. {
  10. Vector3 min = list[0].scl;
  11. Vector3 max = list[list.Count - 1].scl;
  12. return min + (max - min) * rate;
  13. }
  14. public static Vector3 CalculatePosition(List<AnmKeyInfo> list, float rate)
  15. {
  16. Vector3 min = list[0].pos;
  17. Vector3 max = list[list.Count - 1].pos;
  18. return min + (max - min) * rate;
  19. }
  20. public static Vector3 CalculateRotation(List<AnmKeyInfo> list, float rate)
  21. {
  22. Vector3 rot1 = list[0].rot;
  23. Vector3 rot2 = list[1].rot;
  24. Vector3 rot3 = list[list.Count - 1].rot;
  25. Vector3 vector = rot2 - rot1;
  26. Vector3 vector2 = rot3 - rot1;
  27. bool xFlag = vector.x >= 0f;
  28. bool yFlag = vector.y >= 0f;
  29. bool zFlag = vector.z >= 0f;
  30. if (vector2.x > 0f && !xFlag)
  31. {
  32. vector2.x -= 360f;
  33. }
  34. else if (vector2.x < 0f && xFlag)
  35. {
  36. vector2.x += 360f;
  37. }
  38. if (vector2.y > 0f && !yFlag)
  39. {
  40. vector2.y -= 360f;
  41. }
  42. else if (vector2.y < 0f && yFlag)
  43. {
  44. vector2.y += 360f;
  45. }
  46. if (vector2.z > 0f && !zFlag)
  47. {
  48. vector2.z -= 360f;
  49. }
  50. else if (vector2.z < 0f && zFlag)
  51. {
  52. vector2.z += 360f;
  53. }
  54. if (rate < 0f)
  55. {
  56. return rot1 - vector2 * Mathf.Abs(rate);
  57. }
  58. return rot3 + vector2 * Mathf.Abs(rate - 1f);
  59. }
  60. }
  61. }