ActionSkill.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using BehaviorDesigner.Runtime;
  5. using BehaviorDesigner.Runtime.Tasks;
  6. /// <summary>
  7. /// 行为 使用技能
  8. /// </summary>
  9. public class ActionSkill : Action
  10. {
  11. /// <summary>
  12. /// 技能索引
  13. /// </summary>
  14. public int skillIndex = 0;
  15. /// <summary>
  16. /// 攻击动作
  17. /// </summary>
  18. public string attackAnimation = "UniqueSkill";
  19. /// <summary>
  20. /// 角色
  21. /// </summary>
  22. private Role role = null;
  23. /// <summary>
  24. /// 目标
  25. /// </summary>
  26. private Role target = null;
  27. private float aniTime = 0;
  28. private bool getInfo = false;
  29. private float checkTime = 0.1f;
  30. public override void OnAwake()
  31. {
  32. role = GetComponent<Role>();
  33. }
  34. public override void OnStart()
  35. {
  36. Transform tran = role.mBehaviorTree.GetVariable("target").GetValue() as Transform;
  37. target = tran.GetComponent<Role>();
  38. role.mSkillEvent.PlayerSkill = SkillEvent;
  39. role.PlayAnimation(attackAnimation);
  40. checkTime = 0.1f;
  41. getInfo = false;
  42. }
  43. /// <summary>
  44. /// 攻击帧事件
  45. /// </summary>
  46. private void SkillEvent()
  47. {
  48. X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill(
  49. role.mData.UID, role.mData.GetSkillBisha(), false, X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT,target.mData.UID, false);
  50. }
  51. public override TaskStatus OnUpdate()
  52. {
  53. // 获取争取的信息
  54. if (getInfo == false)
  55. {
  56. checkTime -= Time.deltaTime;
  57. if (checkTime < 0)
  58. {
  59. return TaskStatus.Success;
  60. }
  61. // 获取动画层 0 指Base Layer.
  62. AnimatorStateInfo stateinfo = role.mAnimator.GetCurrentAnimatorStateInfo(0);
  63. if (stateinfo.IsName(attackAnimation) == false)
  64. {
  65. return TaskStatus.Running;
  66. }
  67. aniTime = role.mAnimator.GetCurrentAnimatorClipInfo(0)[0].clip.length;
  68. getInfo = true;
  69. }
  70. // 开始计时
  71. aniTime -= Time.deltaTime * role.mAnimator.speed;
  72. if (aniTime > 0)
  73. {
  74. return TaskStatus.Running;
  75. }
  76. return TaskStatus.Success;
  77. }
  78. }