LockSoul.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LockSoul : MonoBehaviour
  5. {
  6. public int maxLockSoul;
  7. private int nowLock;
  8. public List<Demonic> souls = new List<Demonic>();
  9. public PlayerController pc;
  10. public void AddDenomic(Demonic d)
  11. {
  12. if (!d.isRecorded)
  13. {
  14. d.isInSoulTower = true;
  15. d.origSoulPos = d.transform.position;
  16. if (IsSoulsFull())
  17. {
  18. Demonic s = souls[0];
  19. s.isInSoulTower = false;
  20. souls.Remove(s);
  21. s.isRecorded = false;
  22. s.ChangeState(CharacterState.Idle);
  23. }
  24. souls.Add(d);
  25. d.isRecorded = true;
  26. }
  27. }
  28. private void OnTriggerEnter(Collider other)
  29. {
  30. if (other.gameObject.layer == 6)
  31. {
  32. Character c = other.GetComponentInParent<Character>();
  33. if (c.ls == null)
  34. {
  35. c.ls = this;
  36. pc = other.GetComponentInParent<PlayerController>();
  37. }
  38. c.isInSoulTower = true;
  39. pc.curSoulTower = gameObject;
  40. }
  41. }
  42. private bool IsSoulsFull()
  43. {
  44. bool isFull = false;
  45. List<Demonic> re = new List<Demonic>();
  46. nowLock = 0;
  47. foreach(Demonic d in souls)
  48. {
  49. if(d.isDie || !d.isInSoulTower)
  50. {
  51. re.Add(d);
  52. }
  53. else
  54. {
  55. nowLock++;
  56. }
  57. }
  58. foreach(Demonic d in re)
  59. {
  60. souls.Remove(d);
  61. }
  62. if (nowLock >= maxLockSoul)
  63. {
  64. isFull = true;
  65. }
  66. return isFull;
  67. }
  68. private void OnTriggerExit(Collider other)
  69. {
  70. if (other.gameObject.layer == 6)
  71. {
  72. Character c = other.GetComponentInParent<Character>();
  73. c.isInSoulTower = false;
  74. }
  75. }
  76. public void ReleaseAllSouls()
  77. {
  78. if (pc.curSoulTower == gameObject && pc.isInSoulTower)
  79. {
  80. pc.isInSoulTower = false;
  81. }
  82. foreach(Demonic d in souls)
  83. {
  84. if (!d.isDie)
  85. {
  86. d.isInSoulTower = false;
  87. d.ChangeState(CharacterState.Idle);
  88. }
  89. }
  90. }
  91. }