BeHitTrigger.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.U2D;
  5. public class BeHitTrigger : MonoBehaviour
  6. {
  7. public Character owner;
  8. public int attackerID; //攻击方
  9. [Header("当前X值(攻击值-抗击打值)")]
  10. [DisplayOnly]
  11. public int curX;
  12. //闪白参数
  13. private bool isWhite;
  14. private float white;
  15. public List<Material> mats;
  16. private void Awake()
  17. {
  18. owner = GetComponentInParent<Character>();
  19. mats = new List<Material>();
  20. }
  21. private void CountTurnWhiteMaterials()
  22. {
  23. foreach (Material m in owner.meshRenderer.materials)
  24. {
  25. if (m.shader.name.Contains("Fill"))
  26. {
  27. mats.Add(m);
  28. }
  29. }
  30. }
  31. public void BeHit(int damage)
  32. {
  33. owner.BeHit(damage);
  34. }
  35. public void BeHit(AttackController.AttackMethod attackMethod, Character attackFrom)
  36. {
  37. owner.BeHit(attackMethod,attackFrom);
  38. //Debug.Log(attackInfo.damage + "" + attackFrom.name);
  39. }
  40. public void JudgeTurnWhite(bool isDemSummon, Character owner)
  41. {
  42. //敌方士兵受到起手式伤害/我方士兵受到伤害
  43. if (isDemSummon || owner.GetComponent<Demonic>())
  44. {
  45. TurnWhite();
  46. }
  47. }
  48. private void TurnWhite()
  49. {
  50. if (mats.Count == 0)
  51. {
  52. CountTurnWhiteMaterials();
  53. }
  54. foreach(Material m in mats)
  55. {
  56. m.SetFloat("_FillPhase", 0.6f);
  57. Invoke("TurnOrigColor", 0.1f);
  58. }
  59. }
  60. private void OnEnable()
  61. {
  62. isWhite = false;
  63. mats = new List<Material>();
  64. }
  65. private void OnDisable()
  66. {
  67. foreach (Material m in mats)
  68. {
  69. m.SetFloat("_FillPhase", 0);
  70. }
  71. }
  72. private void TurnOrigColor()
  73. {
  74. isWhite = true;
  75. white = 0.6f;
  76. }
  77. private void Update()
  78. {
  79. if (isWhite)
  80. {
  81. white -= 4f * Time.deltaTime;
  82. foreach(Material m in mats)
  83. {
  84. m.SetFloat("_FillPhase", white);
  85. }
  86. if (white <= 0)
  87. {
  88. isWhite = false;
  89. }
  90. }
  91. }
  92. }