CombatSencePath.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using UnityEngine;
  3. namespace GameLogic.Combat.CombatTool
  4. {
  5. [Serializable]
  6. public class CombatSencePath
  7. {
  8. public Vector3 a;
  9. public Vector3 b;
  10. private Vector3 Centre;
  11. private bool isCentre;
  12. public void SetPos(Vector3 startPos, Vector3 target)
  13. {
  14. a = startPos;
  15. b = target;
  16. isCentre = false;
  17. }
  18. public void SetPos(Vector3 startPos, Vector3 centre, Vector3 target)
  19. {
  20. a = startPos;
  21. Centre = centre;
  22. b = target;
  23. isCentre = true;
  24. }
  25. // private float GetPathCount(Vector3 p1, Vector3 p2, Vector3 p3, int count)
  26. // {
  27. // float step = 1f / count;
  28. // Vector3 startPos = p1;
  29. // float d = 0;
  30. // for (int i = 1; i < count; i++)
  31. // {
  32. // float t = i * count;
  33. // Vector3 a = Vector3.Lerp(p1, p2, t);
  34. // Vector3 b = Vector3.Lerp(a, p3, t);
  35. // d += Vector3.Distance(startPos, b);
  36. // startPos = b;
  37. // }
  38. //
  39. //
  40. // return d;
  41. // }
  42. // public float GetPathCount(int count)
  43. // {
  44. // float step = 1f / count;
  45. // Vector3 startPos = GetValue(0);
  46. // float d = 0;
  47. // for (int i = 1; i < count; i++)
  48. // {
  49. // Vector3 currPos = GetValue(step * i);
  50. // d += Vector3.Distance(startPos, currPos);
  51. // }
  52. //
  53. // return d;
  54. // }
  55. public Vector3 GetValue(float t)
  56. {
  57. float t1 = t;
  58. if (t1 > 1)
  59. {
  60. t1 = 1;
  61. }
  62. if (t1 < 0)
  63. {
  64. t1 = 0;
  65. }
  66. if (isCentre)
  67. {
  68. Vector3 p1 = Vector3.Lerp(a, Centre, t1);
  69. Vector3 p2 = Vector3.Lerp(p1, b, t1);
  70. return p2;
  71. }
  72. else
  73. {
  74. return Vector3.Lerp(a, b, t1);
  75. }
  76. }
  77. }
  78. }