MoveCharacter.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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. base.BeHit(damage);
  204. }
  205. //造成伤害附加其他效果,最好都用这个新版本的
  206. //damage 有传参的话会忽略attackinfo 中的damage值
  207. public override void BeHit(AttackInfo attackInfo, Character attackFrom, int damage = -1)
  208. {
  209. if (invincibleTime > 0)
  210. {
  211. //attributeStatus.AddSpecialState(attackInfo, attackFrom);
  212. return;
  213. }
  214. screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackInfo.attackValue - hitResistance);
  215. int damageData;
  216. if(damage == -1)
  217. {
  218. damageData = attackInfo.damage;
  219. }
  220. else
  221. {
  222. damageData = damage;
  223. }
  224. int armorRate = attributeStatus.resistances.armor;
  225. if (attackInfo.attackEffect != null && attackInfo.attackEffect.Length > 0)
  226. {
  227. foreach (AttackEffect ae in attackInfo.attackEffect)
  228. {
  229. switch (ae)
  230. {
  231. /*非控制*/
  232. //穿甲
  233. case AttackEffect.ArmorPiercing:
  234. armorRate = attributeStatus.AddArmorPiercing(attackInfo);
  235. break;
  236. //易伤
  237. case AttackEffect.Vulnerable:
  238. attributeStatus.AddVulnerable(attackInfo);
  239. break;
  240. }
  241. }
  242. }
  243. //计算护甲减免
  244. damageData = (int)(damageData * (100f / (100 + armorRate)) + 0.5f);
  245. //计算易伤
  246. damageData = attributeStatus.DamageCalculation(damageData);
  247. //伤害减免,先注释,用到的时候再改
  248. //if (isDamageReduction)
  249. //{
  250. // damage = (int)((1 - reductionDegree) * damage);
  251. //}
  252. hp -= damageData;
  253. //敌方士兵受起手式伤害/我方士兵受伤 闪白
  254. beHitTrigger.JudgeTurnWhite(attackInfo.isDemSummon, this);
  255. //伤害跳字
  256. if (showInjuryNum)
  257. {
  258. GameObject injuryNum;
  259. //是起手式
  260. if (isBeHitBySummonAttack)
  261. {
  262. injuryNum = PoolManager.Instantiate(injuryNumTextSummon);
  263. injuryNum.transform.position = new Vector3(
  264. transform.position.x + injuryNumPos_summon.x + Random.Range(-injuryNumRandom_summon.x / 2f, injuryNumRandom_summon.x / 2f),
  265. transform.position.y + injuryNumPos_summon.y + Random.Range(-injuryNumRandom_summon.y / 2f, injuryNumRandom_summon.y / 2f),
  266. transform.position.z);
  267. }
  268. //不是起手式
  269. else
  270. {
  271. injuryNum = PoolManager.Instantiate(injuryNumText);
  272. injuryNum.transform.position = injuryNum.transform.position = new Vector3(
  273. transform.position.x + injuryNumPos_march.x + Random.Range(-injuryNumRandom_march.x / 2f, injuryNumRandom_march.x / 2f),
  274. transform.position.y + injuryNumPos_march.y + Random.Range(-injuryNumRandom_march.y / 2f, injuryNumRandom_march.y / 2f),
  275. transform.position.z);
  276. }
  277. TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  278. text.text = damageData.ToString();
  279. }
  280. uiHp.Show(hp, totalHp);
  281. if (hp <= 0)
  282. {
  283. killer = attackFrom;
  284. hitFeedbackSystem.curCharacterState = CharacterState.Die;
  285. ChangeState(CharacterState.Die);
  286. return;
  287. }
  288. //顿帧
  289. if(damage == -1)
  290. {
  291. hitFeedbackSystem.FreezeFrame(attackInfo, attackFrom);
  292. }
  293. }
  294. //受到持续伤害
  295. public void SustainedInjury()
  296. {
  297. sustainedInjuryTime += Time.deltaTime;
  298. if(sustainedInjuryTime >= sustainedInjury_IntervalTime)
  299. {
  300. sustainedInjuryTime = 0;
  301. BeHit(sustainedInjury_damage);
  302. }
  303. }
  304. public override bool AdjustHeight()
  305. {
  306. if (canFly)
  307. {
  308. if (transform.position.y - flyHeight > 0.1f)
  309. {
  310. Vector3 pos = transform.position;
  311. pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
  312. transform.position = pos;
  313. return false;
  314. }
  315. else if (transform.position.y - flyHeight < -0.1f)
  316. {
  317. Vector3 pos = transform.position;
  318. pos.y = Mathf.SmoothDamp(pos.y, flyHeight+0.3f, ref refspeed, flyUpTime);
  319. transform.position = pos;
  320. return false;
  321. }
  322. else
  323. {
  324. Vector3 pos = transform.position;
  325. pos.y = flyHeight;
  326. transform.position = pos;
  327. }
  328. }
  329. isAdjustHeight = 2;
  330. return true;
  331. }
  332. }