1
This commit is contained in:
@@ -10,7 +10,7 @@ namespace BITKit.WorldNode
|
||||
/// </summary>
|
||||
public interface IWorldNodeService
|
||||
{
|
||||
public IReadOnlyDictionary<int, IWorldNode> WorldNodes { get; }
|
||||
public IReadOnlyDictionary<int, HashSet<IWorldNode>> WorldNodes { get; }
|
||||
public void RegisterNode(IWorldNode node);
|
||||
public event Action<IWorldNode> OnNodeRegistered;
|
||||
}
|
||||
@@ -21,12 +21,12 @@ namespace BITKit.WorldNode
|
||||
public class WorldNodeService : IWorldNodeService,IDisposable
|
||||
{
|
||||
public static event Action<IWorldNode> OnNodeRegistered;
|
||||
IReadOnlyDictionary<int, IWorldNode> IWorldNodeService.WorldNodes => WorldNodes;
|
||||
private static readonly ConcurrentDictionary<int, IWorldNode> WorldNodes = new();
|
||||
IReadOnlyDictionary<int, HashSet<IWorldNode>> IWorldNodeService.WorldNodes => WorldNodes;
|
||||
private static readonly ConcurrentDictionary<int, HashSet<IWorldNode>> WorldNodes = new();
|
||||
public void RegisterNode(IWorldNode node)
|
||||
{
|
||||
OnNodeRegistered?.Invoke(node);
|
||||
WorldNodes.TryAdd(node.Id, node);
|
||||
WorldNodes.GetOrCreate(node.Id).Add(node);
|
||||
}
|
||||
event Action<IWorldNode> IWorldNodeService.OnNodeRegistered
|
||||
{
|
||||
|
39
Src/Core/WorldNode/UnityNode.cs
Normal file
39
Src/Core/WorldNode/UnityNode.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
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 IWorldNode WorldNode => worldNode;
|
||||
|
||||
public object WorldObject
|
||||
{
|
||||
get => gameObject;
|
||||
set=>throw new InvalidOperationException("Cannot set WorldObject");
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
if (worldNode is null)
|
||||
{
|
||||
Debug.LogWarning("WorldNode is null");
|
||||
return;
|
||||
}
|
||||
Id = gameObject.GetInstanceID();
|
||||
worldNode.Id = Id;
|
||||
worldNode.WorldObject = gameObject;
|
||||
worldNode.Initialize();
|
||||
worldNodeService.RegisterNode(worldNode);
|
||||
Destroy(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
11
Src/Core/WorldNode/UnityNode.cs.meta
Normal file
11
Src/Core/WorldNode/UnityNode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 054d7fc7589c04d4a8412a6f82b32d6c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -20,17 +20,24 @@ namespace BITKit.WorldNode
|
||||
[SerializeReference,SubclassSelector]
|
||||
#endif
|
||||
private IReference description;
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
public void Initialize()
|
||||
{
|
||||
Name = name?.Value;
|
||||
Description = description?.Value;
|
||||
}
|
||||
#endif
|
||||
public int Id { get; set; }
|
||||
public object WorldObject { get; set; }
|
||||
public string Name => name?.Value;
|
||||
public string Description => description?.Value;
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
}
|
||||
|
||||
public sealed class WorldInfoNodeService : IDisposable
|
||||
{
|
||||
public IReadOnlyDictionary<int, WorldInfoNode> WorldInfoNodes => _infoNodes;
|
||||
public IReadOnlyDictionary<int, WorldInfoNode> WorldInfoNodes => InfoNodes;
|
||||
private readonly IWorldNodeService _worldNodeService;
|
||||
private readonly ConcurrentDictionary<int, WorldInfoNode> _infoNodes = new();
|
||||
private static readonly ConcurrentDictionary<int, WorldInfoNode> InfoNodes = new();
|
||||
|
||||
public WorldInfoNodeService(IWorldNodeService worldNodeService)
|
||||
{
|
||||
@@ -42,12 +49,12 @@ namespace BITKit.WorldNode
|
||||
private void OnNodeRegistered(IWorldNode obj)
|
||||
{
|
||||
if (obj is not WorldInfoNode infoNode) return;
|
||||
_infoNodes.TryAdd(obj.Id, infoNode);
|
||||
InfoNodes.TryAdd(obj.Id, infoNode);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_infoNodes.Clear();
|
||||
InfoNodes.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
Src/Core/WorldNode/WorldInfoNpcStartNode.cs
Normal file
17
Src/Core/WorldNode/WorldInfoNpcStartNode.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BITKit.WorldNode
|
||||
{
|
||||
[Serializable]
|
||||
public struct WorldInfoNpcStartNode:IWorldNode
|
||||
{
|
||||
public string Address;
|
||||
public int Id { get; set; }
|
||||
public object WorldObject { get; set; }
|
||||
public void Initialize()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
11
Src/Core/WorldNode/WorldInfoNpcStartNode.cs.meta
Normal file
11
Src/Core/WorldNode/WorldInfoNpcStartNode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2fba06a66e155a4580df30630f030fc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user