Fix zenject reparenting issue

This commit is contained in:
2024-08-30 19:30:08 +02:00
parent 63ab18a04a
commit c4ee93c296
4 changed files with 44 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
using HurricaneVR.Framework.Core;
using HurricaneVR.Framework.Core.Player;
using HurricaneVR.Framework.Core.Utils;
using System.Collections;
using Unity.Netcode;
using UnityEngine;
using Zenject;
@@ -69,22 +70,18 @@ public class GlobalInstaller : MonoInstaller
})
.NonLazy();
Container.Bind<NetworkManager>()
.FromComponentInNewPrefab(networkManagerPrefab)
.AsSingle()
.OnInstantiated<NetworkManager>((ctx, obj) =>
{
obj.name = networkManagerPrefab.name;
})
.NonLazy();
var go = Instantiate(networkManagerPrefab);
go.name = networkManagerPrefab.name;
var networkManager = go.GetComponent<NetworkManager>();
Container.Bind<PlayerComponent>()
.FromComponentInNewPrefab(playerPrefab)
.AsSingle()
.OnInstantiated<PlayerComponent>((ctx, obj) =>
{
obj.name = playerPrefab.name;
})
.NonLazy();
Container.BindInstance(networkManager)
.AsSingle();
var playerGO = Instantiate(playerPrefab);
playerGO.name = playerPrefab.name;
var playerComponent = playerGO.GetComponent<PlayerComponent>();
Container.BindInstance(playerComponent)
.AsSingle();
}
}