Skip to content

Commit

Permalink
Exposed the ServiceLocator of the MonoService as a protected member.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulNonatomic committed Aug 28, 2024
1 parent 9296807 commit b221122
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Runtime/MonoService.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;

namespace Nonatomic.ServiceLocator
{
public abstract class MonoService<T> : MonoBehaviour where T : class
{
[SerializeField] private ServiceLocator _serviceLocator;
[FormerlySerializedAs("_serviceLocator")]
[SerializeField] protected ServiceLocator ServiceLocator;

protected virtual void Awake()
{
Expand All @@ -14,12 +16,12 @@ protected virtual void Awake()
throw new InvalidOperationException($"{GetType().Name} must implement the {typeof(T).Name} interface.");
}

_serviceLocator.Register<T>(this as T);
ServiceLocator.Register<T>(this as T);
}

protected virtual void OnDestroy()
{
_serviceLocator.Unregister<T>();
ServiceLocator.Unregister<T>();
}
}
}

0 comments on commit b221122

Please sign in to comment.