This commit is contained in:
CortexCore
2024-11-03 16:42:23 +08:00
commit b125894cc3
5904 changed files with 1070129 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.GameSocket
{
public interface ISocketComponent
{
public string Name { get; }
public object Object { get; }
}
public interface ISocketService:IReadOnlyDictionary<string,ISocketComponent>
{
void Initialize();
}
}

View File

@@ -0,0 +1,14 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace BITKit.GameSocket
{
public class UnitySocketComponent : MonoBehaviour,ISocketComponent
{
[SerializeReference,SubclassSelector] private IReference nameReference;
public string Name => nameReference.Value;
public object Object => transform;
}
}

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using AYellowpaper.SerializedCollections;
using UnityEngine;
namespace BITKit.GameSocket
{
public class UnitySocketService : MonoBehaviour,ISocketService
{
private readonly Dictionary<string, ISocketComponent> _sockets=new();
public void Initialize()
{
_sockets.Clear();
foreach (var x in GetComponentsInChildren<ISocketComponent>())
{
_sockets.Add(x.Name, x);
}
}
public IEnumerator<KeyValuePair<string, ISocketComponent>> GetEnumerator()
{
return _sockets.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return _sockets.GetEnumerator();
}
public int Count => _sockets.Count;
public bool ContainsKey(string key)
{
return _sockets.ContainsKey(key);
}
public bool TryGetValue(string key, out ISocketComponent value)
{
return _sockets.TryGetValue(key, out value);
}
public ISocketComponent this[string key] => _sockets[key];
public IEnumerable<string> Keys => _sockets.Keys;
public IEnumerable<ISocketComponent> Values => _sockets.Values;
}
}