PoolableObject.cs 877 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEngine;
  2. using UnityEngine.Events;
  3. namespace HQFPSWeapons
  4. {
  5. public class PoolableObject : MonoBehaviour
  6. {
  7. public string PoolId { get => m_PoolId; }
  8. public UnityEvent OnReleasedEvent = new UnityEvent();
  9. public UnityEvent OnUseEvent = new UnityEvent();
  10. private bool m_Initialized;
  11. private string m_PoolId;
  12. public void Init(string poolId)
  13. {
  14. if(m_Initialized)
  15. {
  16. Debug.LogError("You are attempting to initialize a poolable object, but it's already initialized!!");
  17. return;
  18. }
  19. m_PoolId = poolId;
  20. m_Initialized = true;
  21. }
  22. public void OnUse()
  23. {
  24. OnUseEvent.Invoke();
  25. }
  26. public void OnReleased()
  27. {
  28. OnReleasedEvent.Invoke();
  29. }
  30. }
  31. }