Fix player components injection. Add lobby reloading when clients change

This commit is contained in:
2024-09-11 21:03:47 +02:00
parent 9250b7b5dd
commit e428d3a9f9
10 changed files with 284 additions and 86 deletions

View 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);
}
}