Net.Like.Xue.Tokyo/Assets/BITKit/Unity/Scripts/WorldNode/UnityNode.cs

37 lines
1.0 KiB
C#
Raw Normal View History

2024-11-03 16:42:23 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.WorldNode
{
public sealed class UnityNode : MonoBehaviour,IWorldNode
{
[SerializeReference, SubclassSelector] private IWorldNodeService worldNodeService = new WorldNodeService();
[SerializeReference, SubclassSelector] private IWorldNode worldNode;
public int Id { get; set; }
public object WorldObject
{
get => gameObject;
set=>throw new InvalidOperationException("Cannot set WorldObject");
}
private void Start()
{
2024-12-05 20:11:55 +08:00
if (worldNode is null)
{
Debug.LogWarning("WorldNode is null");
return;
}
2024-11-03 16:42:23 +08:00
Id = gameObject.GetInstanceID();
worldNode.Id = Id;
worldNode.WorldObject = gameObject;
worldNodeService.RegisterNode(worldNode);
worldNode.Initialize();
Destroy(this);
}
}
}