CombatSencePath.cs 2.0 KB

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