Character.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. using Spine.Unity;
  2. using Spine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using TMPro;
  7. //角色状态
  8. public enum CharacterState
  9. {
  10. None = 0,
  11. Idle = 1,
  12. Run = 2,
  13. Rise = 3, //空中上升
  14. Fall = 4, //空中下落
  15. Attack = 6,
  16. KeepAttack = 7,
  17. Summon = 8,
  18. Rush = 9,
  19. Sprint = 10,
  20. Die = 11,
  21. SpecialStatus = 12,
  22. Float = 15, //空中漂浮
  23. LockSoul = 25, //在锁魂塔中
  24. Conduct = 26, //在指挥中
  25. }
  26. public class Character : MonoBehaviour
  27. {
  28. [Header("骨骼")]
  29. public SkeletonMecanim mecanim;
  30. public Skeleton skeleton;
  31. [HideInInspector]
  32. public MeshRenderer meshRenderer;
  33. [Header("动画控制器")]
  34. public Animator ani;
  35. [Header("重要动画时间")]
  36. public float totalDieKeepTime = 2f;
  37. public float totalAttack_summonTime = 0.5f;
  38. public float totalAttack_marchTime = 0.5f;
  39. [Header("死亡后多久尸体消失")]
  40. [HideInInspector]
  41. public float dieKeepTime;
  42. [Header("组件")]
  43. public Rigidbody rb;
  44. public Transform bodyTrans;
  45. public BeSearchTrigger beSearchTrigger;
  46. public SearchTrigger searchTrigger;
  47. public GameObject bodyCollider;
  48. public UIHP uiHp;
  49. public BeHitTrigger beHitTrigger;
  50. public AttackController attackController;
  51. [DisplayOnly]
  52. public Character targetCharacter;
  53. [HideInInspector]
  54. public Character attackTarget;
  55. [Header("角色状态")]
  56. [DisplayOnly]
  57. public CharacterState state;
  58. public int totalHp = 100;
  59. public int hp;
  60. [DisplayOnly]
  61. public bool isDie = false; //已死亡
  62. [DisplayOnly]
  63. public bool isRevive; //从虚弱状态恢复中
  64. public bool canNotAddForce; //不会被打飞
  65. public bool canNotChangeHurt; //不会被打虚弱
  66. [HideInInspector]
  67. public float invincibleTime; //无敌时间
  68. public GameObject injuryNumText;//伤害跳字
  69. public bool showInjuryNum; //伤害跳字开关
  70. public bool canFly = false;
  71. [Header("护甲")]
  72. public int armor;
  73. [Header("锁魂塔")]
  74. public LockSoul ls;
  75. public bool isInSoulTower; //在锁魂塔范围内
  76. [Header("体型增大")]
  77. [HideInInspector]
  78. public bool beLarger = false;
  79. public float toLargeSize = 0; //变大程度
  80. private Vector3 speed = new Vector3(1, 1, 0); //变大速度
  81. [Header("特效")]
  82. public GameObject cookEffect; //吃串加血
  83. [Header("传送门")]
  84. public bool Attack_summonShootCanTransmit; //普攻1弓箭可以被传送
  85. //调试开关
  86. [Header("debug攻击者")] public bool debugAttackFrom;
  87. public virtual void Init()
  88. {
  89. //确保组件不丢失
  90. if (!mecanim)
  91. {
  92. mecanim = GetComponentInChildren<SkeletonMecanim>();
  93. }
  94. if (mecanim && skeleton == null)
  95. {
  96. skeleton = mecanim.skeleton;
  97. }
  98. if (!meshRenderer)
  99. {
  100. meshRenderer = mecanim.GetComponent<MeshRenderer>();
  101. }
  102. if (!ani)
  103. {
  104. ani = GetComponentInChildren<Animator>();
  105. }
  106. //血量重置
  107. hp = totalHp;
  108. uiHp.Show(hp, totalHp);
  109. ChangeState(CharacterState.Idle);
  110. if (attackController != null)
  111. {
  112. attackController.Init();
  113. }
  114. }
  115. public virtual void FixedUpdate()
  116. {
  117. OnState();
  118. }
  119. public void Turn()
  120. {
  121. bodyTrans.localScale = new Vector3(-bodyTrans.localScale.x, bodyTrans.localScale.y, bodyTrans.localScale.z);
  122. }
  123. public virtual void OnState()
  124. {
  125. }
  126. public virtual void ChangeState(CharacterState newState)
  127. {
  128. }
  129. public void DebugAttackFrom(string attackFrom, int damage)
  130. {
  131. Debug.Log(attackFrom + "对" + gameObject.name + "使用了" + damage.ToString() + "点伤害的攻击");
  132. }
  133. //仅造成伤害
  134. public virtual void BeHit(int damage)
  135. {
  136. }
  137. //造成伤害附加其他效果
  138. public virtual void BeHit(AttackInfo attackInfo, float dir)
  139. {
  140. }
  141. public virtual Vector3 GetMoveDir()
  142. {
  143. Vector3 moveDir = Vector3.zero;
  144. return moveDir;
  145. }
  146. public virtual void SetSortingOrder(int order)
  147. {
  148. meshRenderer.sortingOrder = order;
  149. }
  150. //吃串增加血量上限
  151. public void HpUp(float value, float larger)
  152. {
  153. cookEffect.transform.GetChild(0).gameObject.SetActive(true);
  154. int add = 0;
  155. value = value / 100;
  156. add = (int)(totalHp * value);
  157. totalHp += add;
  158. hp += add;
  159. uiHp.Show(hp, totalHp);
  160. float cur = transform.localScale.x;
  161. toLargeSize = cur * larger;
  162. beLarger = true;
  163. }
  164. //体型变大
  165. public void Enlarge()
  166. {
  167. transform.localScale = Vector3.SmoothDamp(transform.localScale, new Vector3(1, 1, 1) * (toLargeSize + 0.1f), ref speed, 0.6f);
  168. if (transform.localScale.x >= toLargeSize - 0.1f)
  169. {
  170. beLarger = false;
  171. transform.localScale = new Vector3(toLargeSize, toLargeSize, toLargeSize);
  172. toLargeSize = 0;
  173. }
  174. }
  175. public virtual bool AdjustHeight()
  176. {
  177. return true;
  178. }
  179. }