CombatSencePath.cs 2.3 KB

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