LockSoul.cs 2.1 KB

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