1
This commit is contained in:
16
Src/Unity/Socket/ISocketComponent.cs
Normal file
16
Src/Unity/Socket/ISocketComponent.cs
Normal 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();
|
||||
}
|
||||
}
|
11
Src/Unity/Socket/ISocketComponent.cs.meta
Normal file
11
Src/Unity/Socket/ISocketComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d0be10870bf27f4b8b1c97ed8809308
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
14
Src/Unity/Socket/UnitySocketComponent.cs
Normal file
14
Src/Unity/Socket/UnitySocketComponent.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Socket/UnitySocketComponent.cs.meta
Normal file
11
Src/Unity/Socket/UnitySocketComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7ba6497a10fb8e14dab1acb39b2ec8aa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
50
Src/Unity/Socket/UnitySocketService.cs
Normal file
50
Src/Unity/Socket/UnitySocketService.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
11
Src/Unity/Socket/UnitySocketService.cs.meta
Normal file
11
Src/Unity/Socket/UnitySocketService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8284a08494909e147b79d71c7142ed12
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user