2025-02-24 23:02:43 +08:00
|
|
|
#if UNITY_5_3_OR_NEWER
|
2024-11-03 16:38:17 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
2025-03-09 13:38:23 +08:00
|
|
|
using BITKit.Entities;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2024-11-03 16:38:17 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BITKit.WorldNode
|
|
|
|
{
|
2025-03-09 13:38:23 +08:00
|
|
|
[RequireComponent(typeof(UnityEntity))]
|
|
|
|
public sealed class UnityNode : MonoBehaviour
|
2024-11-03 16:38:17 +08:00
|
|
|
{
|
|
|
|
[SerializeReference, SubclassSelector] private IWorldNode worldNode;
|
2025-02-24 23:02:43 +08:00
|
|
|
public IWorldNode WorldNode => worldNode;
|
|
|
|
|
2024-11-03 16:38:17 +08:00
|
|
|
private void Start()
|
|
|
|
{
|
2025-03-09 13:38:23 +08:00
|
|
|
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())
|
2024-12-08 21:02:39 +08:00
|
|
|
{
|
2025-03-09 13:38:23 +08:00
|
|
|
entity.ServiceCollection.AddSingleton(interfaceType, worldNode);
|
2024-12-08 21:02:39 +08:00
|
|
|
}
|
2024-11-03 16:38:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2025-02-24 23:02:43 +08:00
|
|
|
#endif
|