MoveCharacter.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using Spine.Unity;
  2. using Spine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using TMPro;
  7. using Sirenix.OdinInspector;
  8. public class MoveCharacter : Character
  9. {
  10. [Space(30)]
  11. [Header("MoveCharacter属性")]
  12. [Header("角色抗击打值")]
  13. public int hitResistance;
  14. [FoldoutGroup("组件")] public Foot foot;
  15. [HideInInspector] public AttributeStatus attributeStatus;
  16. private ScreenReflectPresets screenReflectPresets;
  17. [HideInInspector] public HitFeedbackSystem hitFeedbackSystem;
  18. [HideInInspector] public SpineEvent spineEvent;
  19. [FoldoutGroup("额外重力",order:-1)] [LabelText("上升")] public float extraRiseGravity = -28.8f; //上升时额外重力加速度
  20. [FoldoutGroup("额外重力")] [LabelText("下落")] public float extraFallGravity = -14.4f; //下落时额外重力加速度
  21. [FoldoutGroup("额外重力")] [LabelText("近地")] public float extraGroundGravity = -28.8f;
  22. [FoldoutGroup("平台", order: -1)] [LabelText("移速增量")]public float velocityAddition;
  23. [FoldoutGroup("平台")] [DisplayOnly] public float platformPosY;
  24. [FoldoutGroup("平台")] [DisplayOnly] public float platformRotZ;
  25. [FoldoutGroup("平台")] public float RotLerpSpeed = 0.6f;
  26. [FoldoutGroup("平台")] [DisplayOnly] public float RotLerpTime;
  27. [Header("材质")]
  28. public float matState = 1;
  29. public GameObject spinee;
  30. public MeshRenderer mesh;
  31. public Material[] mats;
  32. public Material[] outlineMats;
  33. public Material[] outline1Mats;
  34. [Header("属性")]
  35. public float moveSpeed = 5;
  36. [FoldoutGroup("飞行兵落地后回升")][LabelText("是否需要判定回升")]
  37. public bool needToAdjustFlyHeight;
  38. [FoldoutGroup("飞行兵落地后回升", order:-1)][DisplayOnly] public float flyHeight;
  39. [FoldoutGroup("飞行兵落地后回升")][LabelText("最大高度")] public float maxFlyHeight;
  40. [FoldoutGroup("飞行兵落地后回升")][LabelText("最低高度")] public float minFlyHeight;
  41. float refspeed = 1;
  42. [FoldoutGroup("飞行兵落地后回升")][LabelText("速度")][Range(0, 1)] public float flyUpTime;
  43. [HideInInspector]
  44. public int isAdjustHeight;
  45. [Header("减伤")]
  46. public bool isDamageReduction;
  47. public float reductionDegree;
  48. public GameObject reductionEffect;
  49. //技能类,后面移到其他脚本
  50. [Header("临时血量")]
  51. public GameObject effect;
  52. private int temptHP;
  53. private int curHP;
  54. private float continueTime;
  55. private bool isTempt;
  56. [Header("魂")]
  57. public GameObject soulPrefab;
  58. public float soulStartSpeed = 1f;
  59. [Header("隐身")]
  60. public bool isInvisible;
  61. public float invisibleTime;
  62. [Header("传送门")]
  63. public bool haveTransmit;
  64. [HideInInspector]
  65. public float transmitTime;
  66. public PortalsController portalsController;
  67. [Header("受到持续伤害")]
  68. public bool isSustainedInjury; //是否正在受到持续伤害
  69. [HideInInspector] public float sustainedInjuryTime; //存储持续伤害经过的时间
  70. public float sustainedInjury_IntervalTime; //每次伤害的间隔时间
  71. public int sustainedInjury_damage; //每次造成的伤害
  72. [Header("受到重伤")]
  73. public float heavyDamage;
  74. [Header("被谁击杀")]
  75. [DisplayOnly]
  76. public Character killer;
  77. public virtual void Awake()
  78. {
  79. spinee = bodyTrans.GetChild(0).gameObject;
  80. mesh = spinee.GetComponent<MeshRenderer>();
  81. mats = mesh.materials;
  82. attributeStatus = GetComponentInChildren<AttributeStatus>();
  83. screenReflectPresets = Camera.main.GetComponentInParent<ScreenReflectPresets>();
  84. hitFeedbackSystem = beHitTrigger.GetComponent<HitFeedbackSystem>();
  85. }
  86. private void Start()
  87. {
  88. }
  89. //0:漂浮 1:正常 2:无敌
  90. public void ChangeMat(int state)
  91. {
  92. if((state == 0 && matState == 2) || (state == 2 && matState == 0))
  93. {
  94. return;
  95. }
  96. if (outline1Mats.Length == 0)
  97. {
  98. return;
  99. }
  100. if (spinee == null || mesh == null || mats == null)
  101. {
  102. spinee = transform.GetChild(0).GetChild(0).gameObject;
  103. mesh = spinee.GetComponent<MeshRenderer>();
  104. mats = mesh.materials;
  105. }
  106. switch (state)
  107. {
  108. case 0:
  109. mesh.materials = outlineMats;
  110. break;
  111. case 1:
  112. mesh.materials = mats;
  113. break;
  114. case 2:
  115. mesh.materials = outline1Mats;
  116. break;
  117. }
  118. matState = state;
  119. }
  120. public void GetTemptHP(int addTemptHP, float time)
  121. {
  122. isTempt = true;
  123. effect.SetActive(true);
  124. curHP = hp;
  125. totalHp += addTemptHP;
  126. hp += addTemptHP;
  127. temptHP = addTemptHP;
  128. continueTime = time;
  129. }
  130. private void LoseTemptHP()
  131. {
  132. isTempt = false;
  133. effect.SetActive(false);
  134. totalHp -= temptHP;
  135. if (hp > curHP)
  136. {
  137. hp = curHP;
  138. }
  139. }
  140. public virtual void Update()
  141. {
  142. if (isTempt)
  143. {
  144. continueTime -= Time.deltaTime;
  145. if (continueTime <= 0 || hp <= curHP)
  146. {
  147. LoseTemptHP();
  148. }
  149. }
  150. if (beLarger)
  151. {
  152. Enlarge();
  153. }/*
  154. if (isInvisible)
  155. {
  156. invisibleTime -= Time.deltaTime;
  157. if(invisibleTime <= 0)
  158. {
  159. isInvisible = false;
  160. ChangeMat(1);
  161. }
  162. }
  163. if (haveTransmit)
  164. {
  165. transmitTime -= Time.deltaTime;
  166. if(transmitTime <=0)
  167. {
  168. haveTransmit = false;
  169. portalsController.rbs.Remove(rb);
  170. }
  171. }*/
  172. //受到持续伤害
  173. if (isSustainedInjury)
  174. {
  175. SustainedInjury();
  176. }
  177. }
  178. //伤害减免状态开启(减免程度,减免时长)
  179. public void DamageReductionStateOn(float degree, GameObject effect)
  180. {
  181. if (reductionEffect == null)
  182. {
  183. reductionEffect = PoolManager.Instantiate(effect, transform.position, new Quaternion(0, 0, 0, 0), transform);
  184. }
  185. reductionEffect.SetActive(true);
  186. isDamageReduction = true;
  187. reductionDegree = degree;
  188. canNotChangeHurt = true;
  189. }
  190. public void DamageReductionStateToOff(float onTime)
  191. {
  192. Invoke("DamageReductionStateOff", onTime);
  193. }
  194. private void DamageReductionStateOff()
  195. {
  196. isDamageReduction = false;
  197. reductionEffect.SetActive(false);
  198. canNotChangeHurt = false;
  199. }
  200. //仅造成伤害
  201. public override void BeHit(int damage)
  202. {
  203. if (invincibleTime > 0)
  204. {
  205. return;
  206. }
  207. base.BeHit(damage);
  208. }
  209. //比BeHit(int damage)多传一个attackFrom
  210. public void BeHit(int damage, Character attackFrom)
  211. {
  212. if (invincibleTime > 0)
  213. {
  214. return;
  215. }
  216. BeHit(damage);
  217. beHitTrigger.JudgeTurnWhite(isBeHitBySummonAttack, attackFrom);
  218. if (hp <= 0)
  219. {
  220. killer = attackFrom;
  221. hitFeedbackSystem.curCharacterState = CharacterState.Die;
  222. return;
  223. }
  224. }
  225. //造成伤害附加其他效果
  226. public override void BeHit(AttackInfo attackInfo, Character attackFrom)
  227. {
  228. if (invincibleTime > 0)
  229. {
  230. //attributeStatus.AddSpecialState(attackInfo, attackFrom);
  231. return;
  232. }
  233. screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackInfo.attackValue - hitResistance);
  234. int damage = attackInfo.damage;
  235. int armorRate = attributeStatus.resistances.armor;
  236. if (attackInfo.attackEffect != null && attackInfo.attackEffect.Length > 0)
  237. {
  238. foreach (AttackEffect ae in attackInfo.attackEffect)
  239. {
  240. switch (ae)
  241. {
  242. /*非控制*/
  243. //穿甲
  244. case AttackEffect.ArmorPiercing:
  245. armorRate = attributeStatus.AddArmorPiercing(attackInfo.armorPiercing, damage);
  246. break;
  247. //易伤
  248. case AttackEffect.Vulnerable:
  249. attributeStatus.AddVulnerable(attackInfo.vulnerable);
  250. break;
  251. }
  252. }
  253. }
  254. //计算护甲减免
  255. damage = (int)(damage * (100f / (100 + armorRate)) + 0.5f);
  256. //计算易伤
  257. damage = attributeStatus.DamageCalculation(damage);
  258. //伤害减免,先注释,用到的时候再改
  259. //if (isDamageReduction)
  260. //{
  261. // damage = (int)((1 - reductionDegree) * damage);
  262. //}
  263. hp -= damage;
  264. //敌方士兵受起手式伤害/我方士兵受伤 闪白
  265. beHitTrigger.JudgeTurnWhite(attackInfo.isDemSummon, this);
  266. //伤害跳字
  267. if (showInjuryNum)
  268. {
  269. GameObject injuryNum;
  270. //是起手式
  271. if (isBeHitBySummonAttack)
  272. {
  273. injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
  274. injuryNum.transform.position = new Vector3(
  275. transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
  276. transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
  277. transform.position.z);
  278. }
  279. //不是起手式
  280. else
  281. {
  282. injuryNum = PoolManager.Instantiate(injuryNumText);
  283. injuryNum.transform.position = injuryNum.transform.position = new Vector3(
  284. transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
  285. transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
  286. transform.position.z);
  287. }
  288. TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  289. text.text = damage.ToString();
  290. }
  291. uiHp.Show(hp, totalHp);
  292. if (hp <= 0)
  293. {
  294. killer = attackFrom;
  295. hitFeedbackSystem.curCharacterState = CharacterState.Die;
  296. ChangeState(CharacterState.Die);
  297. return;
  298. }
  299. //顿帧
  300. hitFeedbackSystem.FreezeFrame(attackInfo, attackFrom);
  301. }
  302. //受到持续伤害
  303. public void SustainedInjury()
  304. {
  305. sustainedInjuryTime += Time.deltaTime;
  306. if(sustainedInjuryTime >= sustainedInjury_IntervalTime)
  307. {
  308. sustainedInjuryTime = 0;
  309. BeHit(sustainedInjury_damage);
  310. }
  311. }
  312. public override bool AdjustHeight()
  313. {
  314. if (canFly)
  315. {
  316. if (transform.position.y - flyHeight > 0.1f)
  317. {
  318. Vector3 pos = transform.position;
  319. pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
  320. transform.position = pos;
  321. return false;
  322. }
  323. else if (transform.position.y - flyHeight < -0.1f)
  324. {
  325. Vector3 pos = transform.position;
  326. pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
  327. transform.position = pos;
  328. return false;
  329. }
  330. else
  331. {
  332. Vector3 pos = transform.position;
  333. pos.y = flyHeight;
  334. transform.position = pos;
  335. }
  336. }
  337. isAdjustHeight = 2;
  338. return true;
  339. }
  340. }