This commit is contained in:
CortexCore
2025-03-09 13:38:23 +08:00
parent 8261a458e2
commit 18239a5ae4
67 changed files with 8573 additions and 831 deletions

View File

@@ -2,37 +2,30 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit.Entities;
using Microsoft.Extensions.DependencyInjection;
using UnityEngine;
namespace BITKit.WorldNode
{
public sealed class UnityNode : MonoBehaviour,IWorldNode
[RequireComponent(typeof(UnityEntity))]
public sealed class UnityNode : MonoBehaviour
{
[SerializeReference, SubclassSelector] private IWorldNodeService worldNodeService = new WorldNodeService();
[SerializeReference, SubclassSelector] private IWorldNode worldNode;
public int Id { get; set; }
public IWorldNode WorldNode => worldNode;
public object WorldObject
{
get => gameObject;
set=>throw new InvalidOperationException("Cannot set WorldObject");
}
private void Start()
{
if (worldNode is null)
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())
{
Debug.LogWarning("WorldNode is null");
return;
entity.ServiceCollection.AddSingleton(interfaceType, worldNode);
}
Id = gameObject.GetInstanceID();
worldNode.Id = Id;
worldNode.WorldObject = gameObject;
worldNode.Initialize();
worldNodeService.RegisterNode(worldNode);
Destroy(this);
}
}
}