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