1
This commit is contained in:
53
Src/Core/WorldNode/WorldInfoNodeService.cs
Normal file
53
Src/Core/WorldNode/WorldInfoNodeService.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
using UnityEngine;
|
||||
#endif
|
||||
namespace BITKit.WorldNode
|
||||
{
|
||||
[Serializable]
|
||||
public struct WorldInfoNode : IWorldNode
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[SerializeReference,SubclassSelector]
|
||||
#endif
|
||||
private IReference name;
|
||||
// ReSharper disable once InconsistentNaming
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
[SerializeReference,SubclassSelector]
|
||||
#endif
|
||||
private IReference description;
|
||||
public int Id { get; set; }
|
||||
public object WorldObject { get; set; }
|
||||
public string Name => name?.Value;
|
||||
public string Description => description?.Value;
|
||||
}
|
||||
|
||||
public sealed class WorldInfoNodeService : IDisposable
|
||||
{
|
||||
public IReadOnlyDictionary<int, WorldInfoNode> WorldInfoNodes => _infoNodes;
|
||||
private readonly IWorldNodeService _worldNodeService;
|
||||
private readonly ConcurrentDictionary<int, WorldInfoNode> _infoNodes = new();
|
||||
|
||||
public WorldInfoNodeService(IWorldNodeService worldNodeService)
|
||||
{
|
||||
_worldNodeService = worldNodeService;
|
||||
|
||||
_worldNodeService.OnNodeRegistered += OnNodeRegistered;
|
||||
}
|
||||
|
||||
private void OnNodeRegistered(IWorldNode obj)
|
||||
{
|
||||
if (obj is not WorldInfoNode infoNode) return;
|
||||
_infoNodes.TryAdd(obj.Id, infoNode);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_infoNodes.Clear();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user