diff --git a/Assets/extOSC/Scripts/Core/Network/OSCReceiverBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCReceiverBackend.cs index 747796f..686d81b 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCReceiverBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCReceiverBackend.cs @@ -2,43 +2,43 @@ namespace extOSC.Core.Network { - public abstract class OSCReceiverBackend - { - #region Extensions + public abstract class OSCReceiverBackend + { + #region Extensions - public delegate void OSCReceivedCallback(IOSCPacket packet); + public delegate void OSCReceivedCallback(IOSCPacket packet); - #endregion + #endregion - #region Public Methods + #region Public Methods - public static OSCReceiverBackend Create() - { -#if NETFX_CORE + public static OSCReceiverBackend Create() + { +#if UNITY_WSA && !UNITY_EDITOR return new OSCReceiverWindowsStoreBackend(); #else - return new OSCReceiverStandaloneBackend(); + return new OSCReceiverStandaloneBackend(); #endif - } + } - #endregion + #endregion - #region Public Vars + #region Public Vars - public abstract OSCReceivedCallback ReceivedCallback { get; set; } + public abstract OSCReceivedCallback ReceivedCallback { get; set; } - public abstract bool IsAvailable { get; } + public abstract bool IsAvailable { get; } - public abstract bool IsRunning { get; } + public abstract bool IsRunning { get; } - #endregion + #endregion - #region Public Methods + #region Public Methods - public abstract void Connect(string localHost, int localPort); + public abstract void Connect(string localHost, int localPort); - public abstract void Close(); + public abstract void Close(); - #endregion - } + #endregion + } } \ No newline at end of file diff --git a/Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs index 02fcd5f..b41f418 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCReceiverStandaloneBackend.cs @@ -1,6 +1,6 @@ /* Copyright (c) 2020 ExT (V.Sigalkin) */ -#if !NETFX_CORE +#if !UNITY_WSA || UNITY_EDITOR using UnityEngine; diff --git a/Assets/extOSC/Scripts/Core/Network/OSCReceiverWindowsStoreBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCReceiverWindowsStoreBackend.cs index 39cc2b9..7a7098f 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCReceiverWindowsStoreBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCReceiverWindowsStoreBackend.cs @@ -1,6 +1,6 @@ /* Copyright (c) 2020 ExT (V.Sigalkin) */ -#if NETFX_CORE +#if UNITY_WSA && !UNITY_EDITOR using UnityEngine; @@ -17,27 +17,21 @@ namespace extOSC.Core.Network { internal class OSCReceiverWindowsStoreBackend : OSCReceiverBackend { -#region Public Vars + #region Public Vars - public override OSCReceivedCallback ReceivedCallback + public override OSCReceivedCallback ReceivedCallback { - get { return _receivedCallback; } - set { _receivedCallback = value; } + get => _receivedCallback; + set => _receivedCallback = value; } - public override bool IsStarted - { - get { return _datagramSocket != null; } - } + public override bool IsAvailable => _datagramSocket != null; - public override bool IsRunning - { - get { return _isRunning; } - } + public override bool IsRunning => _isRunning; -#endregion + #endregion -#region Private Vars + #region Private Vars private bool _isRunning; @@ -49,9 +43,9 @@ public override bool IsRunning private OSCReceivedCallback _receivedCallback; -#endregion + #endregion -#region Public Methods + #region Public Methods public override void Connect(string localHost, int localPort) { @@ -70,9 +64,9 @@ public override void Close() _isRunning = false; } -#endregion + #endregion -#region Private Methods + #region Private Methods private async void ConnectAsync(int localPort) { @@ -80,16 +74,16 @@ private async void ConnectAsync(int localPort) Close(); _localPort = localPort.ToString(); - - try - { + + try + { _datagramSocket = new DatagramSocket(); - _datagramSocket.MessageReceived += Receive; + _datagramSocket.MessageReceived += Receive; _datagramSocket.Control.DontFragment = true; - await _datagramSocket.BindEndpointAsync(null, _localPort); + await _datagramSocket.BindEndpointAsync(null, _localPort); InitMessage(); - } + } catch (ArgumentOutOfRangeException) { Debug.LogErrorFormat("[OSCReceiver] Invalid port: {0}", localPort); @@ -106,14 +100,15 @@ private async void ConnectAsync(int localPort) private async void InitMessage() { - using (var dataWriter = new DataWriter(await _datagramSocket.GetOutputStreamAsync(new HostName("255.255.255.255"), _localPort))) + using (var dataWriter = + new DataWriter(await _datagramSocket.GetOutputStreamAsync(new HostName("255.255.255.255"), _localPort))) { try { var length = 0; - var buffer = OSCConverter.Pack(new OSCMessage("/wsainit"), out length); + var buffer = OSCConverter.Pack(new OSCMessage("/wsainit")); - dataWriter.WriteBuffer(buffer.AsBuffer(0, length)); + dataWriter.WriteBuffer(buffer.AsBuffer(0, buffer.Length)); await dataWriter.StoreAsync(); } catch (Exception exception) @@ -124,7 +119,7 @@ private async void InitMessage() } private void Receive(DatagramSocket sender, DatagramSocketMessageReceivedEventArgs args) - { + { try { using (var dataReader = args.GetDataReader()) @@ -144,9 +139,9 @@ private void Receive(DatagramSocket sender, DatagramSocketMessageReceivedEventAr { Debug.LogErrorFormat("[OSCReceiver] Receive error: " + e); } - } + } -#endregion + #endregion } } diff --git a/Assets/extOSC/Scripts/Core/Network/OSCStandaloneManager.cs b/Assets/extOSC/Scripts/Core/Network/OSCStandaloneManager.cs index 669ce0e..fffd090 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCStandaloneManager.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCStandaloneManager.cs @@ -1,6 +1,6 @@ /* Copyright (c) 2020 ExT (V.Sigalkin) */ -#if !NETFX_CORE +#if !UNITY_WSA || UNITY_EDITOR using System; using System.Net; diff --git a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterBackend.cs index c763aa3..946befb 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterBackend.cs @@ -2,37 +2,37 @@ namespace extOSC.Core.Network { - public abstract class OSCTransmitterBackend - { - #region Static Public Methods + public abstract class OSCTransmitterBackend + { + #region Static Public Methods - public static OSCTransmitterBackend Create() - { -#if NETFX_CORE + public static OSCTransmitterBackend Create() + { +#if UNITY_WSA && !UNITY_EDITOR return new OSCTransmitterWindowsStoreBackend(); #else - return new OSCTransmitterStandaloneBackend(); + return new OSCTransmitterStandaloneBackend(); #endif - } + } - #endregion + #endregion - #region Public Vars + #region Public Vars - public abstract bool IsAvailable { get; } + public abstract bool IsAvailable { get; } - #endregion + #endregion - #region Public Methods + #region Public Methods - public abstract void Connect(string localHost, int localPort); + public abstract void Connect(string localHost, int localPort); - public abstract void RefreshRemote(string remoteHost, int remotePort); + public abstract void RefreshRemote(string remoteHost, int remotePort); - public abstract void Close(); + public abstract void Close(); - public abstract void Send(byte[] data, int length); + public abstract void Send(byte[] data, int length); - #endregion - } + #endregion + } } \ No newline at end of file diff --git a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterStandaloneBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterStandaloneBackend.cs index ac8b870..68213ae 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterStandaloneBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterStandaloneBackend.cs @@ -1,6 +1,6 @@ /* Copyright (c) 2020 ExT (V.Sigalkin) */ -#if !NETFX_CORE +#if !UNITY_WSA || UNITY_EDITOR using UnityEngine; @@ -14,12 +14,9 @@ internal class OSCTransmitterStandaloneBackend : OSCTransmitterBackend { #region Public Vars - public override bool IsAvailable - { - get { return _client != null; } - } + public override bool IsAvailable => _client != null; - #endregion + #endregion #region Private Vars diff --git a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterWindowsStoreBackend.cs b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterWindowsStoreBackend.cs index 5eeaf1c..8663f7e 100644 --- a/Assets/extOSC/Scripts/Core/Network/OSCTransmitterWindowsStoreBackend.cs +++ b/Assets/extOSC/Scripts/Core/Network/OSCTransmitterWindowsStoreBackend.cs @@ -1,6 +1,6 @@ /* Copyright (c) 2020 ExT (V.Sigalkin) */ -#if NETFX_CORE +#if UNITY_WSA && !UNITY_EDITOR using UnityEngine; @@ -13,14 +13,11 @@ namespace extOSC.Core.Network { - internal class OSCTransmitterWindowsStoreBackend : OSCTransmitterBackend + internal class OSCTransmitterWindowsStoreBackend : OSCTransmitterBackend { #region Public Vars - public override bool IsStarted - { - get { return _datagramSocket != null; } - } + public override bool IsAvailable => _datagramSocket != null; #endregion @@ -36,7 +33,7 @@ public override bool IsStarted #region Public Methods - public override void Connect(string localHost, int localPort) + public override void Connect(string localHost, int localPort) { if (_datagramSocket != null) Close(); @@ -47,7 +44,7 @@ public override void Connect(string localHost, int localPort) _datagramSocket = new DatagramSocket(); } - public override void RefreshRemote(string remoteHost, int remotePort) + public override void RefreshRemote(string remoteHost, int remotePort) { _remoteHost = new HostName(remoteHost); _remotePort = remotePort.ToString(); @@ -72,7 +69,8 @@ public override void Send(byte[] data, int length) private async void SendAsync(IBuffer buffer) { - using (var dataWriter = new DataWriter(await _datagramSocket.GetOutputStreamAsync(_remoteHost, _remotePort))) + using (var dataWriter = + new DataWriter(await _datagramSocket.GetOutputStreamAsync(_remoteHost, _remotePort))) { try { @@ -84,7 +82,7 @@ private async void SendAsync(IBuffer buffer) Debug.LogWarningFormat("[OSCTranmitter] Error: {0}", exception); } } - } + } #endregion } diff --git a/Assets/extOSC/Scripts/OSCUtilities.cs b/Assets/extOSC/Scripts/OSCUtilities.cs index 29f2f23..5275a2a 100644 --- a/Assets/extOSC/Scripts/OSCUtilities.cs +++ b/Assets/extOSC/Scripts/OSCUtilities.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; using extOSC.Core; -#if NETFX_CORE +#if UNITY_WSA && !UNITY_EDITOR using System.Reflection; #endif @@ -33,7 +33,7 @@ public static int ClampPort(int port) public static string GetLocalHost() { -#if !NETFX_CORE +#if !UNITY_WSA try { var hostName = Dns.GetHostName(); @@ -488,7 +488,7 @@ public static bool ToArray(this OSCMessage message, out List value) public static bool IsSubclassOf(Type targetType, Type sourceType) { -#if !NETFX_CORE +#if !UNITY_WSA || UNITY_EDITOR return (targetType.IsSubclassOf(sourceType) || targetType == sourceType); #else return (targetType.GetTypeInfo().IsSubclassOf(sourceType) || targetType == sourceType); @@ -520,7 +520,7 @@ public static int IndexOf(this T[] array, T target) private static int StructSizeOf(T structure) where T : struct { -#if !NETFX_CORE +#if !UNITY_WSA return Marshal.SizeOf(structure); #else return Marshal.SizeOf(structure); @@ -529,7 +529,7 @@ private static int StructSizeOf(T structure) where T : struct private static int StructSizeOf() where T : struct { -#if !NETFX_CORE +#if !UNITY_WSA return Marshal.SizeOf(typeof(T)); #else return Marshal.SizeOf(); @@ -538,7 +538,7 @@ private static int StructSizeOf() where T : struct private static T PtrToStructure(IntPtr pointer) where T : struct { -#if !NETFX_CORE +#if !UNITY_WSA return (T) Marshal.PtrToStructure(pointer, typeof(T)); #else return Marshal.PtrToStructure(pointer);