| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class AttackController : MonoBehaviour
- {
- //攻击类型
- public enum AttackType
- {
- Melee = 0, //近战
- Shoot = 1, //射击
- Dash = 2, //英灵刺客
- }
- [System.Serializable]
- public struct SpineAniKey
- {
- public string aniName;
- public List<AttackKeyType> keys;
- }
- public enum KeyType
- {
- AttackStart,
- AttackEnd,
- }
- [System.Serializable]
- public struct AttackKeyType
- {
- public KeyType attackType;
- public string startKeyName;
- public float startKeyTime;
- public KeyType endType;
- public string endKeyName;
- public float endKeyTime;
- }
- private Character owner;
- [Header("所有攻击帧事件及时间")]
- public List<SpineAniKey> attackKeys;
- [Header("攻击类型")]
- public AttackType attackType;
- [Header("攻击参数")]
- public bool canHitFly;
- public int armorPiercing; //穿甲率
- public List<AttackInfo> Attack_summonInfos;
- public List<AttackInfo> Attack_marchInfos;
- //以下信息不在面板显示
- [HideInInspector]
- public bool isNonAttack = false; //无普攻
- [HideInInspector]
- public GameObject addAttackEffect;
- [DisplayOnly]
- public int[] curDamage1;
- [DisplayOnly]
- public int[] curDamage2;
- [Header("攻击动画")]
- public AttackTrigger attackTrigger;
- public List<float> keyTimes; //所有的帧事件时间
- [DisplayOnly]
- public float attackTime; //攻击剩余时间
- //以下信息不在面板显示
- [HideInInspector]
- public float attackKeyCount; //攻击进行时间
- [HideInInspector]
- public float nextStartKeyTime, nextEndKeyTime;
- [HideInInspector]
- public int curKeyNum; //当前锁定到第几个帧事件
- [HideInInspector]
- public bool isAttackTriggerOn = false; //当前Attack Trigger是否开启
- [Header("远程单位")]
- public GameObject bulletPrefab; //子弹
- public List<Transform> shootPos; //子弹发射位置
- public bool shootTrack = false; //是否初始时瞄准目标
- public bool shootAlwaysTrack = false; //是否始终追踪
- [Header("目标")]
- public List<TargetType> targetTypes;
- [DisplayOnly]
- public List<Character> beTargetCharacter = new List<Character>(); //被哪些锁定
- public float getDistanceOffset = 0f;
- public void Init()
- {
- owner = GetComponent<Character>();
- curDamage1 = new int[Attack_summonInfos.Count];
- for (int i = 0; i < Attack_summonInfos.Count; i++)
- {
- curDamage1[i] = Attack_summonInfos[i].damage;
- }
- curDamage2 = new int[Attack_marchInfos.Count];
- for (int i = 0; i < Attack_marchInfos.Count; i++)
- {
- curDamage2[i] = Attack_marchInfos[i].damage;
- }
- }
- private void OnEnable()
- {
- if (attackTrigger != null)
- {
- attackTrigger.gameObject.SetActive(false);
- }
- }
- public void ChooseAttack()
- {
- }
- public void SetNextKeyTimes()
- {
- if (curKeyNum < keyTimes.Count)
- {
- nextStartKeyTime = keyTimes[curKeyNum];
- nextEndKeyTime = keyTimes[curKeyNum + 1];
- curKeyNum += 2;
- }
- }
- public virtual void Attack_summon()
- {
- owner.ani.Play("attack_summon", 0, 0);
- if (!isNonAttack)
- {
- if (attackType == AttackType.Shoot)
- {
- attackTrigger.isShoot = true;
- attackTrigger.GetComponent<Collider>().enabled = false;
- attackTrigger.type = AttackTrigger.attackTpye.summon;
- }
- attackTime = owner.totalAttack_summonTime;
- attackKeyCount = 0;
- keyTimes = new List<float>();
- foreach (SpineAniKey sak in attackKeys)
- {
- if (sak.aniName == "attack_summon")
- {
- foreach (AttackKeyType akt in sak.keys)
- {
- keyTimes.Add(akt.startKeyTime);
- keyTimes.Add(akt.endKeyTime);
- }
- }
- }
- curKeyNum = 0;
- SetNextKeyTimes();
- switch (attackType)
- {
- case AttackType.Melee:
- attackTrigger.damage = curDamage1[0];
- attackTrigger.changeHurt = Attack_summonInfos[0].changeHurt;
- attackTrigger.repelValue = Attack_summonInfos[0].repelValue;
- Vector3 attackDir = Attack_summonInfos[0].attackDir.normalized;
- if (owner.bodyTrans.localScale.x < 0)
- {
- attackDir.x = -attackDir.x;
- }
- attackTrigger.force = attackDir * Attack_summonInfos[0].force;
- break;
- default:
- break;
- }
- owner.ChangeState(CharacterState.Attack);
- }
- }
- public virtual void Attack_march()
- {
- Vector3 leftDir = owner.GetMoveDir();
- if (leftDir.x > 0.3f)
- {
- if (owner.bodyTrans.localScale.x > 0)
- {
- owner.Turn();
- }
- }
- else if (leftDir.x < -0.3f)
- {
- if (owner.bodyTrans.localScale.x < 0)
- {
- owner.Turn();
- }
- }
- owner.ani.Play("attack_march", 0, 0);
- if (attackType == AttackType.Shoot)
- {
- attackTrigger.isShoot = true;
- attackTrigger.GetComponent<Collider>().enabled = false;
- attackTrigger.type = AttackTrigger.attackTpye.march;
- }
- attackTime = owner.totalAttack_marchTime;
- attackKeyCount = 0;
- keyTimes = new List<float>();
- foreach (SpineAniKey sak in attackKeys)
- {
- if (sak.aniName == "attack_march")
- {
- foreach (AttackKeyType akt in sak.keys)
- {
- keyTimes.Add(akt.startKeyTime);
- keyTimes.Add(akt.endKeyTime);
- }
- }
- }
- curKeyNum = 0;
- SetNextKeyTimes();
- attackTrigger.damage = curDamage2[0];
- attackTrigger.changeHurt = Attack_marchInfos[0].changeHurt;
- attackTrigger.repelValue = Attack_marchInfos[0].repelValue;
- Vector3 attackDir = Attack_marchInfos[0].attackDir.normalized;
- if (owner.bodyTrans.localScale.x < 0)
- {
- attackDir.x = -attackDir.x;
- }
- attackTrigger.force = attackDir * Attack_marchInfos[0].force;
- owner.ChangeState(CharacterState.Attack);
- }
- public virtual void AttackShootEvent(int attackId, int shootId)
- {
- AttackInfo attackInfo;
- if (attackId == 1)
- {
- attackInfo = Attack_summonInfos[shootId];
- }
- else
- {
- attackInfo = Attack_marchInfos[shootId];
- attackInfo.damage = curDamage2[0];
- }
- GameObject bulletObj = PoolManager.Instantiate(bulletPrefab);
- Bullet bullet = bulletObj.GetComponent<Bullet>();
- Vector3 attackDir = attackInfo.attackDir.normalized;
- if (owner.bodyTrans.localScale.x < 0)
- {
- attackDir.x = -attackDir.x;
- }
- if (attackId == 1 && owner.Attack_summonShootCanTransmit)
- {
- bullet.canTransmit = true;
- }
- bullet.BeShoot(owner, shootPos[shootId].position, attackDir, attackInfo.damage,
- attackInfo.force, attackInfo.changeHurt, attackInfo.repelValue, shootTrack,
- shootAlwaysTrack, owner.attackTarget ? owner.attackTarget : null);
- }
- }
|