From 1dc1fd8cbe8cf03e9b1b6f494209021dca90e894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=BCger?= Date: Thu, 20 Feb 2025 15:43:25 +0100 Subject: [PATCH 1/5] removed unused using directive --- Runtime/InputSources/TuioInput.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Runtime/InputSources/TuioInput.cs b/Runtime/InputSources/TuioInput.cs index 54b07e08..8f52e1b0 100644 --- a/Runtime/InputSources/TuioInput.cs +++ b/Runtime/InputSources/TuioInput.cs @@ -5,7 +5,6 @@ using TouchScript.Utils; using TuioNet.Common; using UnityEngine; -using UnityEngine.Serialization; namespace TouchScript.InputSources { From f10573e8573cfd5ca5f09c03f972cfaf82d000fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=BCger?= Date: Thu, 20 Feb 2025 15:44:23 +0100 Subject: [PATCH 2/5] restore ConnectionType accessor --- Runtime/InputSources/TuioInput.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Runtime/InputSources/TuioInput.cs b/Runtime/InputSources/TuioInput.cs index 8f52e1b0..fa3d967e 100644 --- a/Runtime/InputSources/TuioInput.cs +++ b/Runtime/InputSources/TuioInput.cs @@ -28,6 +28,15 @@ public class TuioInput : InputSource private ITuioInput _tuioInput; + public TuioConnectionType ConnectionType + { + get => _connectionType; + set + { + _connectionType = value; + } + } + public Vector2Int Resolution { get; private set; } public int UdpPort From aedadd45de24983800585521c36ea7947168ab1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=BCger?= Date: Thu, 20 Feb 2025 15:45:07 +0100 Subject: [PATCH 3/5] add general Port get-accessor (for UDP as well as websocket port) --- Runtime/InputSources/TuioInput.cs | 37 +++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Runtime/InputSources/TuioInput.cs b/Runtime/InputSources/TuioInput.cs index fa3d967e..61fd2ee2 100644 --- a/Runtime/InputSources/TuioInput.cs +++ b/Runtime/InputSources/TuioInput.cs @@ -61,6 +61,30 @@ public string IpAddress } } + public int Port + { + get + { + if (_connectionType == TuioConnectionType.Websocket) + { + return _tuioVersion switch + { + TuioVersion.Tuio11 => 3333, + TuioVersion.Tuio20 => 3343, + _ => throw new ArgumentOutOfRangeException($"{typeof(TuioVersion)} has no value of {_tuioVersion}.") + }; + } + else if(_connectionType == TuioConnectionType.UDP) + { + return _udpPort; + } + else + { + throw new ArgumentOutOfRangeException($"{typeof(TuioConnectionType)} has no value of {_connectionType}."); + } + } + } + public ITuioDispatcher TuioDispatcher { get @@ -96,18 +120,7 @@ public void Reinit() protected override void Init() { if(_isInitialized) return; - var port = UdpPort; - if (_connectionType == TuioConnectionType.Websocket) - { - port = _tuioVersion switch - { - TuioVersion.Tuio11 => 3333, - TuioVersion.Tuio20 => 3343, - _ => throw new ArgumentOutOfRangeException($"{typeof(TuioVersion)} has no value of {_tuioVersion}.") - }; - } - - _session = new TuioSession(_tuioVersion, _connectionType, IpAddress, port, false); + _session = new TuioSession(_tuioVersion, _connectionType, IpAddress, Port, false); _isInitialized = true; } From 6079f8f61581692e7a2af7746ec755f841db1da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=BCger?= Date: Thu, 20 Feb 2025 15:46:29 +0100 Subject: [PATCH 4/5] fixed recursive call of UdpPort accessor (caused stack overflow) --- Runtime/InputSources/TuioInput.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/InputSources/TuioInput.cs b/Runtime/InputSources/TuioInput.cs index 61fd2ee2..0b165616 100644 --- a/Runtime/InputSources/TuioInput.cs +++ b/Runtime/InputSources/TuioInput.cs @@ -45,7 +45,7 @@ public int UdpPort set { if(value < 0) return; - UdpPort = value; + _udpPort = value; } } From 05165de1c0bdb29ec43b125ff61f4c1d77475d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Kr=C3=BCger?= Date: Thu, 20 Feb 2025 15:59:02 +0100 Subject: [PATCH 5/5] change if statement to switch expression --- Runtime/InputSources/TuioInput.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/Runtime/InputSources/TuioInput.cs b/Runtime/InputSources/TuioInput.cs index 0b165616..d0e2875a 100644 --- a/Runtime/InputSources/TuioInput.cs +++ b/Runtime/InputSources/TuioInput.cs @@ -65,23 +65,17 @@ public int Port { get { - if (_connectionType == TuioConnectionType.Websocket) + return _connectionType switch { - return _tuioVersion switch + TuioConnectionType.Websocket => _tuioVersion switch { TuioVersion.Tuio11 => 3333, TuioVersion.Tuio20 => 3343, _ => throw new ArgumentOutOfRangeException($"{typeof(TuioVersion)} has no value of {_tuioVersion}.") - }; - } - else if(_connectionType == TuioConnectionType.UDP) - { - return _udpPort; - } - else - { - throw new ArgumentOutOfRangeException($"{typeof(TuioConnectionType)} has no value of {_connectionType}."); - } + }, + TuioConnectionType.UDP => _udpPort, + _ => throw new ArgumentOutOfRangeException($"{typeof(TuioConnectionType)} has no value of {_connectionType}."), + }; } }