SliderMath.cs 1.9 KB

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