Fix player components injection. Add lobby reloading when clients change
This commit is contained in:
46
Assets/Scripts/Utils/Injector.cs
Normal file
46
Assets/Scripts/Utils/Injector.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using static Zenject.ZenAutoInjecter;
|
||||
using Zenject;
|
||||
using ModestTree;
|
||||
|
||||
public static class Injector
|
||||
{
|
||||
static DiContainer LookupContainer(GameObject go, ContainerSources container)
|
||||
{
|
||||
if (container == ContainerSources.ProjectContext)
|
||||
{
|
||||
return ProjectContext.Instance.Container;
|
||||
}
|
||||
|
||||
if (container == ContainerSources.SceneContext)
|
||||
{
|
||||
return GetContainerForCurrentScene(go);
|
||||
}
|
||||
|
||||
Assert.IsEqual(container, ContainerSources.SearchHierarchy);
|
||||
|
||||
var parentContext = go.transform.GetComponentInParent<Context>();
|
||||
|
||||
if (parentContext != null)
|
||||
{
|
||||
return parentContext.Container;
|
||||
}
|
||||
|
||||
return GetContainerForCurrentScene(go);
|
||||
}
|
||||
|
||||
static DiContainer GetContainerForCurrentScene(GameObject go)
|
||||
{
|
||||
return ProjectContext.Instance.Container
|
||||
.Resolve<SceneContextRegistry>()
|
||||
.GetContainerForScene(go.scene);
|
||||
}
|
||||
|
||||
public static void Inject(this GameObject go, ContainerSources container = ContainerSources.SceneContext)
|
||||
{
|
||||
LookupContainer(go, container).InjectGameObject(go);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user