com.alicizax.unity.framework/Runtime/ABase/Service/Core/ServiceContext.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2026-03-26 10:49:41 +08:00
namespace AlicizaX
{
public readonly struct ServiceContext
{
2026-04-20 13:46:44 +08:00
internal ServiceContext(ServiceWorld world, ServiceScope scope)
2026-03-26 10:49:41 +08:00
{
World = world;
Scope = scope;
}
2026-04-20 13:46:44 +08:00
internal ServiceWorld World { get; }
2026-03-26 10:49:41 +08:00
2026-04-20 13:46:44 +08:00
internal ServiceScope Scope { get; }
2026-03-26 10:49:41 +08:00
public T Require<T>() where T : class, IService
=> World.Require<T>(Scope);
public bool TryGet<T>(out T service) where T : class, IService
=> World.TryGet(Scope, out service);
2026-04-20 13:46:44 +08:00
internal ServiceScope EnsureScene(int order = ServiceDomainOrder.Scene)
=> World.EnsureScene(order);
2026-04-20 13:46:44 +08:00
internal bool TryGetScene(out ServiceScope scope)
=> World.TryGetScene(out scope);
2026-04-20 13:46:44 +08:00
internal ServiceScope ResetScene(int order = ServiceDomainOrder.Scene)
=> World.ResetScene(order);
2026-04-20 13:46:44 +08:00
internal ServiceScope EnsureGameplay(int order = ServiceDomainOrder.Gameplay)
=> World.EnsureGameplay(order);
2026-04-20 13:46:44 +08:00
internal bool TryGetGameplay(out ServiceScope scope)
=> World.TryGetGameplay(out scope);
public T RequireApp<T>() where T : class, IService
2026-04-20 13:46:44 +08:00
=> World.App.Require<T>();
2026-03-26 10:49:41 +08:00
public T RequireScene<T>() where T : class, IService
2026-04-20 13:46:44 +08:00
=> World.Scene.Require<T>();
2026-03-26 10:49:41 +08:00
public T RequireGameplay<T>() where T : class, IService
2026-04-20 13:46:44 +08:00
=> World.Gameplay.Require<T>();
2026-03-26 10:49:41 +08:00
}
}