Files
Net.Like.Xue.Tokyo/Assets/BITKit/Core/WorldNode/UnityNode.cs
CortexCore c29bf0d12f 1
2025-03-03 18:44:00 +08:00

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