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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Utils/Injector.cs.meta
Normal file
11
Assets/Scripts/Utils/Injector.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7eb2cd65a9697441890fa5f41706bf7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user