Net.Like.Xue.Tokyo/Assets/BITKit/Core/WorldNode/UnityNode.cs

40 lines
1.3 KiB
C#
Raw Normal View History

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;
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; }
2025-02-24 23:03:39 +08:00
public IWorldNode WorldNode => worldNode;
2024-11-03 16:42:23 +08:00
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)
{
2024-12-08 20:51:29 +08:00
Debug.LogWarning("WorldNode is null");
2024-12-05 20:11:55 +08:00
return;
}
2024-11-03 16:42:23 +08:00
Id = gameObject.GetInstanceID();
worldNode.Id = Id;
worldNode.WorldObject = gameObject;
worldNode.Initialize();
2025-02-24 23:03:39 +08:00
worldNodeService.RegisterNode(worldNode);
2024-11-03 16:42:23 +08:00
Destroy(this);
}
}
}
2025-02-24 23:03:39 +08:00
#endif