#if UNITY_5_3_OR_NEWER using System; using System.Collections; using System.Collections.Generic; using BITKit.Entities; using Microsoft.Extensions.DependencyInjection; using UnityEngine; namespace BITKit.WorldNode { [RequireComponent(typeof(UnityEntity))] public sealed class UnityNode : MonoBehaviour { [SerializeReference, SubclassSelector] private IWorldNode worldNode; public IWorldNode WorldNode => worldNode; private void Start() { if(worldNode is null)return; var entity = GetComponent(); var type = worldNode.GetType(); GetComponent().ServiceCollection.AddSingleton(type,worldNode); foreach (var interfaceType in type.GetInterfaces()) { entity.ServiceCollection.AddSingleton(interfaceType, worldNode); } } } } #endif