MoveCharacter.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. [FoldoutGroup("组件")]
  11. public Foot foot;
  12. [HideInInspector] public AttributeStatus attributeStatus;
  13. private ScreenReflectPresets screenReflectPresets;
  14. private HitFeedbackSystem hitFeedbackSystem;
  15. [Header("角色抗击打值")]
  16. public int hitResistance;
  17. [Header("材质")]
  18. public float matState = 1;
  19. public GameObject spinee;
  20. public MeshRenderer mesh;
  21. public Material[] mats;
  22. public Material[] outlineMats;
  23. public Material[] outline1Mats;
  24. [Header("额外重力")]
  25. public float extraRiseGravity = 0; //上升时额外重力加速度
  26. public float extraFallGravity = -10; //下落时额外重力加速度
  27. [Header("属性")]
  28. public float moveSpeed = 5;
  29. public bool needToAdjustFlyHeight;
  30. [FoldoutGroup("回升")][DisplayOnly] public float flyHeight;
  31. [FoldoutGroup("回升")][LabelText("最大高度")] public float maxFlyHeight;
  32. [FoldoutGroup("回升")][LabelText("最低高度")] public float minFlyHeight;
  33. float refspeed = 1;
  34. [FoldoutGroup("回升")][LabelText("消耗时间")] public float flyUpTime;
  35. [HideInInspector]
  36. public int isAdjustHeight;
  37. [Header("减伤")]
  38. public bool isDamageReduction;
  39. public float reductionDegree;
  40. public GameObject reductionEffect;
  41. [Header("临时血量")]
  42. public GameObject effect;
  43. private int temptHP;
  44. private int curHP;
  45. private float continueTime;
  46. private bool isTempt;
  47. [Header("魂")]
  48. public GameObject soulPrefab;
  49. public float soulStartSpeed = 1f;
  50. [Header("隐身")]
  51. public bool isInvisible;
  52. public float invisibleTime;
  53. public float velocityAddition;
  54. [Header("传送门")]
  55. public bool haveTransmit;
  56. [HideInInspector]
  57. public float transmitTime;
  58. public PortalsController portalsController;
  59. [Header("受到持续伤害")]
  60. public bool isSustainedInjury; //是否正在受到持续伤害
  61. [HideInInspector] public float sustainedInjuryTime; //存储持续伤害经过的时间
  62. public float sustainedInjury_IntervalTime; //每次伤害的间隔时间
  63. public int sustainedInjury_damage; //每次造成的伤害
  64. [Header("受到重伤")]
  65. public float heavyDamage;
  66. public virtual void Awake()
  67. {
  68. spinee = bodyTrans.GetChild(0).gameObject;
  69. mesh = spinee.GetComponent<MeshRenderer>();
  70. mats = mesh.materials;
  71. attributeStatus = GetComponentInChildren<AttributeStatus>();
  72. screenReflectPresets = Camera.main.GetComponentInParent<ScreenReflectPresets>();
  73. }
  74. private void Start()
  75. {
  76. }
  77. //0:漂浮 1:正常 2:无敌
  78. public void ChangeMat(int state)
  79. {
  80. if((state == 0 && matState == 2) || (state == 2 && matState == 0))
  81. {
  82. return;
  83. }
  84. if (outline1Mats.Length == 0)
  85. {
  86. return;
  87. }
  88. if (spinee == null || mesh == null || mats == null)
  89. {
  90. spinee = transform.GetChild(0).GetChild(0).gameObject;
  91. mesh = spinee.GetComponent<MeshRenderer>();
  92. mats = mesh.materials;
  93. }
  94. switch (state)
  95. {
  96. case 0:
  97. mesh.materials = outlineMats;
  98. break;
  99. case 1:
  100. mesh.materials = mats;
  101. break;
  102. case 2:
  103. mesh.materials = outline1Mats;
  104. break;
  105. }
  106. matState = state;
  107. }
  108. public void GetTemptHP(int addTemptHP, float time)
  109. {
  110. isTempt = true;
  111. effect.SetActive(true);
  112. curHP = hp;
  113. totalHp += addTemptHP;
  114. hp += addTemptHP;
  115. temptHP = addTemptHP;
  116. continueTime = time;
  117. }
  118. private void LoseTemptHP()
  119. {
  120. isTempt = false;
  121. effect.SetActive(false);
  122. totalHp -= temptHP;
  123. if (hp > curHP)
  124. {
  125. hp = curHP;
  126. }
  127. }
  128. public virtual void Update()
  129. {
  130. if (isTempt)
  131. {
  132. continueTime -= Time.deltaTime;
  133. if (continueTime <= 0 || hp <= curHP)
  134. {
  135. LoseTemptHP();
  136. }
  137. }
  138. if (beLarger)
  139. {
  140. Enlarge();
  141. }/*
  142. if (isInvisible)
  143. {
  144. invisibleTime -= Time.deltaTime;
  145. if(invisibleTime <= 0)
  146. {
  147. isInvisible = false;
  148. ChangeMat(1);
  149. }
  150. }
  151. if (haveTransmit)
  152. {
  153. transmitTime -= Time.deltaTime;
  154. if(transmitTime <=0)
  155. {
  156. haveTransmit = false;
  157. portalsController.rbs.Remove(rb);
  158. }
  159. }*/
  160. //受到持续伤害
  161. if (isSustainedInjury)
  162. {
  163. SustainedInjury();
  164. }
  165. }
  166. //伤害减免状态开启(减免程度,减免时长)
  167. public void DamageReductionStateOn(float degree, GameObject effect)
  168. {
  169. if (reductionEffect == null)
  170. {
  171. reductionEffect = Instantiate(effect, transform.position, new Quaternion(0, 0, 0, 0), transform);
  172. }
  173. reductionEffect.SetActive(true);
  174. isDamageReduction = true;
  175. reductionDegree = degree;
  176. canNotChangeHurt = true;
  177. }
  178. public void DamageReductionStateToOff(float onTime)
  179. {
  180. Invoke("DamageReductionStateOff", onTime);
  181. }
  182. private void DamageReductionStateOff()
  183. {
  184. isDamageReduction = false;
  185. reductionEffect.SetActive(false);
  186. canNotChangeHurt = false;
  187. }
  188. //仅造成伤害
  189. public override void BeHit(int damage)
  190. {
  191. base.BeHit(damage);
  192. }
  193. //造成伤害附加其他效果
  194. public override void BeHit(AttackInfo attackInfo, Character attackFrom)
  195. {
  196. screenReflectPresets.ScreenReflect(hitFeedbackSystem, attackFrom.attackController.attackValue - hitResistance);
  197. base.BeHit(attackInfo, attackFrom);
  198. int damage = attackInfo.damage;
  199. if (attackInfo.attackEffect.Length > 0)
  200. {
  201. foreach (AttackEffect ae in attackInfo.attackEffect)
  202. {
  203. switch (ae)
  204. {
  205. /*控制*/
  206. //漂浮
  207. case AttackEffect.FloatState:
  208. attributeStatus.AddFloat(attackInfo.floatState);
  209. break;
  210. //击飞
  211. case AttackEffect.BlowUp:
  212. attributeStatus.AddBlowUp(attackInfo.blowUp, attackFrom.bodyTrans.localScale.x < 0 ? -1 : 1);
  213. break;
  214. //击落
  215. case AttackEffect.ShotDown:
  216. attributeStatus.AddShotDown(attackInfo.shotDown, attackFrom.bodyTrans.localScale.x < 0 ? -1 : 1);
  217. break;
  218. //击晕
  219. case AttackEffect.Weak:
  220. attributeStatus.AddWeak(attackInfo.weak);
  221. break;
  222. /*非控制*/
  223. //穿甲
  224. case AttackEffect.Armor:
  225. damage = attributeStatus.AddArmor(attackInfo.armor, damage);
  226. break;
  227. //易伤
  228. case AttackEffect.Vulnerable:
  229. attributeStatus.AddVulnerable(attackInfo.vulnerable);
  230. break;
  231. }
  232. }
  233. }
  234. damage = attributeStatus.DamageCalculation(damage);
  235. //伤害减免,先注释,用到的时候再改
  236. //if (isDamageReduction)
  237. //{
  238. // damage = (int)((1 - reductionDegree) * damage);
  239. //}
  240. hp -= damage;
  241. //伤害跳字
  242. if (showInjuryNum)
  243. {
  244. GameObject injuryNum = Instantiate(injuryNumText);
  245. injuryNum.transform.position = new Vector3(transform.position.x + Random.Range(-1f, 1f), transform.position.y + 1, transform.position.z);
  246. TextMeshProUGUI text = injuryNum.GetComponentInChildren<TextMeshProUGUI>();
  247. text.text = damage.ToString();
  248. if (gameObject.CompareTag("Player"))
  249. {
  250. text.color = Color.red;
  251. if (debugAttackFrom)
  252. {
  253. Debug.Log("主角受到" + damage.ToString() + "点伤害");
  254. }
  255. }
  256. }
  257. uiHp.Show(hp, totalHp);
  258. if (hp <= 0)
  259. {
  260. ChangeState(CharacterState.Die);
  261. return;
  262. }
  263. }
  264. //受到持续伤害
  265. public void SustainedInjury()
  266. {
  267. sustainedInjuryTime += Time.deltaTime;
  268. if(sustainedInjuryTime >= sustainedInjury_IntervalTime)
  269. {
  270. sustainedInjuryTime = 0;
  271. BeHit(sustainedInjury_damage);
  272. }
  273. }
  274. public override bool AdjustHeight()
  275. {
  276. if (canFly)
  277. {
  278. if (transform.position.y - flyHeight > 0.1f)
  279. {
  280. Vector3 pos = transform.position;
  281. pos.y = Mathf.SmoothDamp(pos.y, flyHeight, ref refspeed, flyUpTime);
  282. transform.position = pos;
  283. return false;
  284. }
  285. else if (transform.position.y - flyHeight < -0.1f)
  286. {
  287. Vector3 pos = transform.position;
  288. pos.y = Mathf.SmoothDamp(pos.y, flyHeight, ref refspeed, flyUpTime);
  289. transform.position = pos;
  290. return false;
  291. }
  292. else
  293. {
  294. Vector3 pos = transform.position;
  295. pos.y = flyHeight;
  296. transform.position = pos;
  297. isAdjustHeight = 2;
  298. }
  299. }
  300. return true;
  301. }
  302. }