33 lines
915 B
C#
33 lines
915 B
C#
#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<IEntity>();
|
|
var type = worldNode.GetType();
|
|
GetComponent<IEntity>().ServiceCollection.AddSingleton(type,worldNode);
|
|
foreach (var interfaceType in type.GetInterfaces())
|
|
{
|
|
entity.ServiceCollection.AddSingleton(interfaceType, worldNode);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|