| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class LockSoul : MonoBehaviour
- {
- public int maxLockSoul;
- private int nowLock;
- public List<Demonic> souls = new List<Demonic>();
- public void AddDenomic(Demonic d)
- {
- if (!d.isRecorded)
- {
- d.isInSoulTower = true;
- d.origSoulPos = d.transform.position;
- if (IsSoulsFull())
- {
- Demonic s = souls[0];
- s.isInSoulTower = false;
- souls.Remove(s);
- s.isRecorded = false;
- s.ChangeState(CharacterState.Idle);
- }
- souls.Add(d);
- d.isRecorded = true;
- nowLock++;
- d.ChangeState(CharacterState.LockSoul);
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.layer == 8 || other.gameObject.layer == 6)
- {
- Character c = other.GetComponentInParent<Character>();
- if (other.gameObject.layer == 6 && c.ls == null)
- {
- c.ls = this;
- }
- c.isInSoulTower = true;
- }
- }
- private bool IsSoulsFull()
- {
- bool isFull = false;
- List<Demonic> re = new List<Demonic>();
- foreach(Demonic d in souls)
- {
- if(d.isDie || !d.isInSoulTower)
- {
- re.Add(d);
- }
- }
- foreach(Demonic d in re)
- {
- souls.Remove(d);
- nowLock--;
- }
- if (nowLock >= maxLockSoul)
- {
- isFull = true;
- }
- return isFull;
- }
- private void OnTriggerExit(Collider other)
- {
- if (other.gameObject.layer == 8 || other.gameObject.layer == 6)
- {
- Character c = other.GetComponentInParent<Character>();
- c.isInSoulTower = false;
- }
- }
- public void ReleaseAllSouls()
- {
- foreach(Demonic d in souls)
- {
- if (!d.isDie)
- {
- d.isInSoulTower = false;
- d.ChangeState(CharacterState.Idle);
- }
- }
- }
- }
|