| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- using Spine.Unity;
- using Spine;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using TMPro;
- public enum AttackState
- {
- Idle = 0, //待机
- Attack = 1, //攻击
- Die = 2, //死亡
- Weak = 3, //虚弱
- }
- public enum AttackCategories
- {
- A = 0,
- B = 1,
- }
- public class Boss : MoveCharacter
- {
- [Space(30)]
- [Header("Boss属性")]
- [Header("当前索敌是对塔还是对玩家")]
- public TargetType curTarget;
- public PlayerController pc;
- [Header("Boss攻击规律")]
- public string circulate; //循环配置
- private int len;
- public AttackCategories[] categories; //循环大类
- private AttackCategories curCategory; //当前攻击大类
- public int curCategoryID;
- public float minInterval, maxInterval; //间隔时间
- private float curInterval;
- public override void Init()
- {
- //确保组件不丢失
- if (!ani)
- {
- ani = GetComponentInChildren<Animator>();
- }
- //血量重置
- hp = totalHp;
- uiHp.Show(hp, totalHp);
- ChangeState(CharacterState.Idle);
- curInterval = Random.Range(minInterval, maxInterval);
- //玩家
- pc = PlayersInput.instance[0];
- }
- public virtual void Start()
- {
- len = circulate.Length;
- Init();
- int cur = 0;
- categories = new AttackCategories[len];
- foreach(char c in circulate)
- {
- switch (c)
- {
- case 'A':
- categories[cur] = AttackCategories.A;
- break;
- case 'B':
- categories[cur] = AttackCategories.B;
- break;
- default:
- break;
- }
- cur++;
- }
- curCategory = categories[0];
- }
- public override void BeHit(int damage)
- {
- hp -= damage;
- //伤害跳字
- if (showInjuryNum)
- {
- GameObject injuryNum = Instantiate(injuryNumText);
- injuryNum.transform.position = new Vector3(transform.position.x + Random.Range(-1f, 1f), transform.position.y + 1, transform.position.z);
- TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
- text.text = damage.ToString();
- if (gameObject.CompareTag("Player"))
- {
- text.color = Color.red;
- }
- }
- uiHp.Show(hp, totalHp);
- if (hp <= 0)
- {
- ChangeState(CharacterState.Die);
- }
- }
- public virtual void Attack()
- {
- }
- public override void ChangeState(CharacterState newState)
- {
- if (newState == state)
- {
- return;
- }
- switch (state)
- {
- case CharacterState.Run:
- rb.velocity = Vector3.zero;
- break;
- default:
- break;
- }
- state = newState;
- switch (newState)
- {
- case CharacterState.Idle:
- ani.Play("idle", 0, 0);
- break;
- case CharacterState.Run:
- ToMove();
- break;
- case CharacterState.Die:
- ani.Play("die", 0, 0);
- gameObject.SetActive(false);
- break;
- case CharacterState.Attack:
- Attack();
- break;
- default:
- break;
- }
- }
- public override void OnState()
- {
- switch (state)
- {
- case CharacterState.Idle:
- curInterval -= Time.deltaTime;
- if (curInterval <= 0)
- {
- RandomAttackState();
- }
- break;
- case CharacterState.Run:
- OnMove();
- break;
- default:
- break;
- }
- }
- public virtual void ToMove()
- {
- }
- public virtual void OnMove()
- {
- }
- public void CheckTarget()
- {
- Character curTar = null;
- switch (curTarget)
- {
- case TargetType.Tower:
- float minDis = -1;
- foreach(GameObject g in TowerMap.myTowers)
- {
- float dis = Vector2.Distance(g.transform.position, transform.position);
- if (minDis == -1 || dis < minDis)
- {
- minDis = dis;
- curTar = g.GetComponent<Character>();
- }
- }
- break;
- case TargetType.Player:
- PlayerController p1 = PlayersInput.instance[0];
- bool p1Alive = (p1 != null && !p1.isRevive);
- float dis1 = Vector2.Distance(transform.position, p1.transform.position);
- curTar = p1;
- break;
- default:
- break;
- }
- targetCharacter = curTar;
- }
- public virtual void RandomAttackType(AttackCategories cate)
- {
- }
- public void RandomAttackState()
- {
- switch (curCategory)
- {
- case AttackCategories.A:
- RandomAttackType(AttackCategories.A);
- break;
- case AttackCategories.B:
- RandomAttackType(AttackCategories.B);
- break;
- default:
- break;
- }
- curCategoryID++;
- if (curCategoryID == len)
- {
- curCategoryID = 0;
- }
- curCategory = categories[curCategoryID];
- ChangeState(CharacterState.Attack);
- }
- public void EndCurAttackState(bool hasIntervalTime)
- {
- //和下一个动作有没有间隔
- if (hasIntervalTime)
- {
- curInterval = Random.Range(minInterval, maxInterval);
- }
- ChangeState(CharacterState.Idle);
- }
- }
|