From 4e9d34f5d5dc8f98a6bc0c1606f0e8c9ff3bff99 Mon Sep 17 00:00:00 2001 From: Keijiro Takahashi Date: Sun, 22 Jul 2018 18:25:16 +0900 Subject: [PATCH] Make OscMaster class public --- .../Runtime/Base/{Internal => }/OscMaster.cs | 52 +++++++++---------- .../Base/{Internal => }/OscMaster.cs.meta | 0 .../OscJack/Runtime/Unity/OscEventReceiver.cs | 4 +- .../Runtime/Unity/OscPropertySender.cs | 2 +- 4 files changed, 29 insertions(+), 29 deletions(-) rename Assets/OscJack/Runtime/Base/{Internal => }/OscMaster.cs (85%) rename Assets/OscJack/Runtime/Base/{Internal => }/OscMaster.cs.meta (100%) diff --git a/Assets/OscJack/Runtime/Base/Internal/OscMaster.cs b/Assets/OscJack/Runtime/Base/OscMaster.cs similarity index 85% rename from Assets/OscJack/Runtime/Base/Internal/OscMaster.cs rename to Assets/OscJack/Runtime/Base/OscMaster.cs index 1ba4c83..4787f83 100644 --- a/Assets/OscJack/Runtime/Base/Internal/OscMaster.cs +++ b/Assets/OscJack/Runtime/Base/OscMaster.cs @@ -6,34 +6,11 @@ namespace OscJack { - internal static class OscMaster + public static class OscMaster { - #region Mapping objects - - // OSC server map (key = port number) - static Dictionary _servers = new Dictionary(); - - // OSC client map (key = IP address + port number) - static Dictionary _clients = new Dictionary(); - - #endregion - - #region Client key generator - - static StringBuilder _stringBuilder = new StringBuilder(); - - static string GetClientKey(string ipAddress, int port) - { - _stringBuilder.Length = 0; - _stringBuilder.Append(ipAddress).Append(port); - return _stringBuilder.ToString(); - } - - #endregion - #region Public methods - public static OscServer GetServer(int port) + public static OscServer GetSharedServer(int port) { OscServer server; if (!_servers.TryGetValue(port, out server)) @@ -44,7 +21,7 @@ public static OscServer GetServer(int port) return server; } - public static OscClient GetClient(string ipAddress, int port) + public static OscClient GetSharedClient(string ipAddress, int port) { var key = GetClientKey(ipAddress, port); OscClient client; @@ -57,5 +34,28 @@ public static OscClient GetClient(string ipAddress, int port) } #endregion + + #region Mapping objects + + // OSC server map (key = port number) + static Dictionary _servers = new Dictionary(); + + // OSC client map (key = IP address + port number) + static Dictionary _clients = new Dictionary(); + + #endregion + + #region Client key generator + + static StringBuilder _stringBuilder = new StringBuilder(); + + static string GetClientKey(string ipAddress, int port) + { + _stringBuilder.Length = 0; + _stringBuilder.Append(ipAddress).Append(':').Append(port); + return _stringBuilder.ToString(); + } + + #endregion } } diff --git a/Assets/OscJack/Runtime/Base/Internal/OscMaster.cs.meta b/Assets/OscJack/Runtime/Base/OscMaster.cs.meta similarity index 100% rename from Assets/OscJack/Runtime/Base/Internal/OscMaster.cs.meta rename to Assets/OscJack/Runtime/Base/OscMaster.cs.meta diff --git a/Assets/OscJack/Runtime/Unity/OscEventReceiver.cs b/Assets/OscJack/Runtime/Unity/OscEventReceiver.cs index 89df90d..f1c9af8 100644 --- a/Assets/OscJack/Runtime/Unity/OscEventReceiver.cs +++ b/Assets/OscJack/Runtime/Unity/OscEventReceiver.cs @@ -135,7 +135,7 @@ void OnEnable() return; } - var server = OscMaster.GetServer(_udpPort); + var server = OscMaster.GetSharedServer(_udpPort); server.MessageDispatcher.AddCallback(_oscAddress, OnDataReceive); _currentPort = _udpPort; @@ -166,7 +166,7 @@ void OnDisable() { if (string.IsNullOrEmpty(_currentAddress)) return; - var server = OscMaster.GetServer(_currentPort); + var server = OscMaster.GetSharedServer(_currentPort); server.MessageDispatcher.RemoveCallback(_currentAddress, OnDataReceive); _currentAddress = null; diff --git a/Assets/OscJack/Runtime/Unity/OscPropertySender.cs b/Assets/OscJack/Runtime/Unity/OscPropertySender.cs index 2de10f5..5c317dc 100644 --- a/Assets/OscJack/Runtime/Unity/OscPropertySender.cs +++ b/Assets/OscJack/Runtime/Unity/OscPropertySender.cs @@ -28,7 +28,7 @@ public sealed class OscPropertySender : MonoBehaviour void UpdateSettings() { - _client = OscMaster.GetClient(_ipAddress, _udpPort); + _client = OscMaster.GetSharedClient(_ipAddress, _udpPort); if (_dataSource != null && !string.IsNullOrEmpty(_propertyName)) _propertyInfo = _dataSource.GetType().GetProperty(_propertyName);