using System.Collections; using System.Collections.Generic; using UnityEngine; using BehaviorDesigner.Runtime; using BehaviorDesigner.Runtime.Tasks; /// /// 行为 使用技能 /// public class ActionSkill : Action { /// /// 技能索引 /// public int skillIndex = 0; /// /// 攻击动作 /// public string attackAnimation = "UniqueSkill"; /// /// 角色 /// private Role role = null; /// /// 目标 /// private Role target = null; private float aniTime = 0; private bool getInfo = false; private float checkTime = 0.1f; public override void OnAwake() { role = GetComponent(); } public override void OnStart() { Transform tran = role.mBehaviorTree.GetVariable("target").GetValue() as Transform; target = tran.GetComponent(); role.mSkillEvent.PlayerSkill = SkillEvent; role.PlayAnimation(attackAnimation); checkTime = 0.1f; getInfo = false; } /// /// 攻击帧事件 /// private void SkillEvent() { X2Battle.X2BattleManager.Instance.mBulletModel.OnCastSkill( role.mData.UID, role.mData.GetSkillBisha(), false, X2Battle.EBulletCastPoint.ECAST_POINT_DEFLUAT,target.mData.UID, false); } public override TaskStatus OnUpdate() { // 获取争取的信息 if (getInfo == false) { checkTime -= Time.deltaTime; if (checkTime < 0) { return TaskStatus.Success; } // 获取动画层 0 指Base Layer. AnimatorStateInfo stateinfo = role.mAnimator.GetCurrentAnimatorStateInfo(0); if (stateinfo.IsName(attackAnimation) == false) { return TaskStatus.Running; } aniTime = role.mAnimator.GetCurrentAnimatorClipInfo(0)[0].clip.length; getInfo = true; } // 开始计时 aniTime -= Time.deltaTime * role.mAnimator.speed; if (aniTime > 0) { return TaskStatus.Running; } return TaskStatus.Success; } }