StraightLineShow.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Common.Utility.CombatEvent;
  2. using Core.Utility;
  3. using Fort23.Core;
  4. using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
  5. using UnityEngine;
  6. using Utility.CTween;
  7. namespace GameLogic.Combat.Skill.MagicSkill
  8. {
  9. public class StraightLineShow : MagicAttShowBasic
  10. {
  11. private CombatHeroEntity target;
  12. private BesselPath _besselPath;
  13. private float allTime;
  14. private float speed = 15;
  15. private float addTime;
  16. private System.Action callBack;
  17. public void SetTarget(CombatHeroEntity target, System.Action callBack)
  18. {
  19. this.callBack = callBack;
  20. this.target = target;
  21. _besselPath = CObjectPool.Instance.Fetch<BesselPath>();
  22. _skillBasic.CombatHeroEntity.GameObject.transform.eulerAngles = Vector3.zero;
  23. Vector3 p1 =
  24. _skillBasic.CombatHeroEntity.GameObject.transform.TransformPoint(new Vector3(-5f, 5f, 5f));
  25. Vector3 p2 = SetTargetPos2();
  26. _besselPath.controlPoints.Add(_skillBasic.CombatHeroEntity.GameObject.transform.position);
  27. _besselPath.controlPoints.Add(p1);
  28. _besselPath.controlPoints.Add(p2);
  29. _besselPath.controlPoints.Add(target.dotPos);
  30. float d = _besselPath.GetLengthAtT(allTime);
  31. addTime = 1.0f / (d / speed);
  32. allTime = 0;
  33. }
  34. protected Vector3 SetTargetPos2()
  35. {
  36. Vector3 p2 = target.GameObject.transform.TransformPoint(new Vector3(-5f, 1f, 5f));
  37. return p2;
  38. }
  39. protected override void ProUpdate(float t)
  40. {
  41. Vector3 p2 = SetTargetPos2();
  42. _besselPath.controlPoints[2] = p2;
  43. _besselPath.controlPoints[3] = target.dotPos;
  44. allTime += t * addTime;
  45. float v = CustomTweenManager.AnimationCurveLibrary.fabaoAtt.Evaluate(allTime);
  46. Vector3 lasetPos = _besselPath.CalculatePoint(v - 0.01f);
  47. Vector3 p = _besselPath.CalculatePoint(v);
  48. _skillBasic.CombatHeroEntity.combatHeroGameObject.SetPosition(p);
  49. Quaternion quaternion = Quaternion.LookRotation((p - lasetPos).normalized);
  50. _skillBasic.CombatHeroEntity.GameObject.transform.rotation =
  51. Quaternion.Lerp(_skillBasic.CombatHeroEntity.GameObject.transform.rotation, quaternion, 0.5f);
  52. if (allTime >= 1)
  53. {
  54. isUpdate = false;
  55. callBack?.Invoke();
  56. }
  57. }
  58. }
  59. }