Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
801B

  1. using Svelto.DataStructures;
  2. using UnityEngine;
  3. namespace Svelto.Context.Legacy
  4. {
  5. public class NotifyComponentsRemoved : MonoBehaviour
  6. {
  7. public WeakReference<IUnityContextHierarchyChangedListener> unityContext { private get; set; }
  8. void Start()
  9. {
  10. if (unityContext == null)
  11. {
  12. Destroy(this);
  13. }
  14. }
  15. void OnDestroy()
  16. {
  17. if (unityContext == null || unityContext.IsAlive == false)
  18. return;
  19. MonoBehaviour[] components = gameObject.GetComponents<MonoBehaviour>();
  20. for (int i = 0; i < components.Length; ++i)
  21. if (components[i] != null)
  22. unityContext.Target.OnMonobehaviourRemoved(components[i]);
  23. }
  24. }
  25. }