Tower.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using static Spine.Unity.Examples.SpineboyFootplanter;
  5. using TMPro;
  6. public class Tower : Character
  7. {
  8. [Header("ËþÐÅÏ¢")]
  9. public string name;
  10. public bool isLockSoul;
  11. public float height = 8;
  12. private void Awake()
  13. {
  14. TowerMap.myTowers.Add(gameObject);
  15. Init();
  16. //attackController.ChooseAttack(0);
  17. attackController.curAttackMethod = attackController.attackMethod_march[0];
  18. }
  19. public bool GetAttack()
  20. {
  21. if (targetCharacter != null)
  22. {
  23. return true;
  24. }
  25. return false;
  26. }
  27. public void SearchTarget()
  28. {
  29. targetCharacter = searchTrigger.GetMinDisTarget(attackController.targetTypes, true, attackController.curAttackMethod.searchMode);
  30. }
  31. public void Attack_March()
  32. {
  33. GameObject bulletObj = PoolManager.Instantiate(attackController.curAttackMethod.bulletPrefab);
  34. attackController.attackTime = attackController.attackKeys[0].totalTime;
  35. Bullet bullet = bulletObj.GetComponent<Bullet>();
  36. AttackInfo attackInfo = attackController.curAttackMethod.attackInfo;
  37. Vector3 attackDir = attackInfo.attackDir.normalized;
  38. if (bodyTrans.localScale.x < 0)
  39. {
  40. attackDir.x = -attackDir.x;
  41. }
  42. bullet.BeShoot(this, attackController.curAttackMethod.shootPos[0].position, attackDir, attackController.curAttackMethod.shootTrack,
  43. attackController.curAttackMethod.shootAlwaysTrack, attackTarget ? attackTarget : null);
  44. }
  45. public override void OnState()
  46. {
  47. base.OnState();
  48. SearchTarget();
  49. attackController.attackTime -= Time.deltaTime;
  50. dieKeepTime -= Time.deltaTime;
  51. bool isAttack = GetAttack();
  52. switch (state)
  53. {
  54. case CharacterState.Idle:
  55. if (isAttack)
  56. {
  57. ChangeState(CharacterState.Attack);
  58. break;
  59. }
  60. break;
  61. case CharacterState.Attack:
  62. if (attackController.attackTime <= 0)
  63. {
  64. ChangeState(CharacterState.Idle);
  65. break;
  66. }
  67. break;
  68. case CharacterState.Die:
  69. if (dieKeepTime <= 0)
  70. {
  71. gameObject.SetActive(false);
  72. break;
  73. }
  74. break;
  75. default:
  76. break;
  77. }
  78. }
  79. public override void ChangeState(CharacterState newState)
  80. {
  81. switch (state)
  82. {
  83. case CharacterState.Idle:
  84. break;
  85. case CharacterState.Attack:
  86. attackTarget = null;
  87. break;
  88. case CharacterState.Die:
  89. isDie = false;
  90. break;
  91. default:
  92. break;
  93. }
  94. CharacterState oldState = state;
  95. state = newState;
  96. switch (newState)
  97. {
  98. case CharacterState.Idle:
  99. rb.velocity = Vector3.zero;
  100. break;
  101. case CharacterState.Attack:
  102. attackTarget = targetCharacter;
  103. Attack_March();
  104. break;
  105. case CharacterState.Die:
  106. if (isLockSoul)
  107. {
  108. GetComponentInChildren<LockSoul>().ReleaseAllSouls();
  109. }
  110. isDie = true;
  111. dieKeepTime = totalDieKeepTime;
  112. TowerMap.myTowers.Remove(gameObject);
  113. break;
  114. default:
  115. break;
  116. }
  117. }
  118. public override void BeHit(int damage)
  119. {
  120. base.BeHit(damage);
  121. }
  122. public override void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom, int damage = -1)
  123. {
  124. base.BeHit(attackMethod.attackInfo.damage);
  125. }
  126. }