Reformat files

This commit is contained in:
Santiago Lo Coco 2024-11-05 21:56:13 +01:00
parent d1ad9de1a1
commit 8551bf9c8f
10 changed files with 174 additions and 85 deletions

View File

@ -1,8 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class ConfigureNavBar : MonoBehaviour
{
@ -37,15 +37,22 @@ public class ConfigureNavBar : MonoBehaviour
if (boxCollider1 != null)
{
boxCollider1.size = new Vector3(boxCollider1.size.x, isVisible ? 400 : 370, boxCollider1.size.z);
boxCollider1.size = new Vector3(
boxCollider1.size.x,
isVisible ? 400 : 370,
boxCollider1.size.z
);
boxCollider1.center = new Vector3(0, isVisible ? 0 : -16, 0);
}
if (boxCollider2 != null)
{
boxCollider2.size = new Vector3(boxCollider2.size.x, isVisible ? 400 : 370, boxCollider2.size.z);
boxCollider2.size = new Vector3(
boxCollider2.size.x,
isVisible ? 400 : 370,
boxCollider2.size.z
);
boxCollider2.center = new Vector3(0, isVisible ? 0 : -16, 0);
}
}
}

View File

@ -1,8 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.SpatialAwareness;
using UnityEngine;
public class ConfigureObservers : MonoBehaviour
{
@ -10,7 +10,8 @@ public class ConfigureObservers : MonoBehaviour
private void Start()
{
spatialAwarenessSystem = MixedRealityToolkit.Instance.GetService<IMixedRealitySpatialAwarenessSystem>();
spatialAwarenessSystem =
MixedRealityToolkit.Instance.GetService<IMixedRealitySpatialAwarenessSystem>();
if (spatialAwarenessSystem != null)
{
@ -23,4 +24,3 @@ public class ConfigureObservers : MonoBehaviour
}
}
}

View File

@ -1,9 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Utilities;
using Microsoft.MixedReality.Toolkit.Utilities.Solvers;
using UnityEngine;
public class ConfigureOrbital : MonoBehaviour
{
@ -35,9 +35,16 @@ public class ConfigureOrbital : MonoBehaviour
solverHandler2 = canvas2.GetComponent<SolverHandler>();
}
if (orbital1 == null || solverHandler1 == null || orbital2 == null || solverHandler2 == null)
if (
orbital1 == null
|| solverHandler1 == null
|| orbital2 == null
|| solverHandler2 == null
)
{
Debug.LogError("One or both Canvas objects are missing an Orbital or SolverHandler component.");
Debug.LogError(
"One or both Canvas objects are missing an Orbital or SolverHandler component."
);
}
}
@ -57,7 +64,8 @@ public class ConfigureOrbital : MonoBehaviour
{
Vector3 headPosition = Camera.main.transform.position;
Quaternion headRotation = Camera.main.transform.rotation;
Vector3 relativePosition = Quaternion.Inverse(headRotation) * (orbital.transform.position - headPosition);
Vector3 relativePosition =
Quaternion.Inverse(headRotation) * (orbital.transform.position - headPosition);
orbital.LocalOffset = relativePosition;

View File

@ -1,9 +1,9 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Microsoft.MixedReality.Toolkit;
using Microsoft.MixedReality.Toolkit.Utilities;
using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine;
public class ConfigurePointer : MonoBehaviour
{
@ -33,4 +33,3 @@ public class ConfigurePointer : MonoBehaviour
PointerUtils.SetHandRayPointerBehavior(PointerBehavior.AlwaysOff);
}
}

View File

@ -1,10 +1,10 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using System;
using System.Collections;
using System.Collections.Generic;
using Microsoft.MixedReality.WebView;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class EndpointLoader : MonoBehaviour
{
@ -71,7 +71,12 @@ public class EndpointLoader : MonoBehaviour
{
Vector3 nextPosition = CalculateNextPosition();
GameObject newItem = Instantiate(dynamicItem, nextPosition, dynamicItem.transform.rotation, dynamicItem.transform.parent);
GameObject newItem = Instantiate(
dynamicItem,
nextPosition,
dynamicItem.transform.rotation,
dynamicItem.transform.parent
);
newItem.SetActive(true);
instantiatedItems.Add(newItem);
@ -104,9 +109,17 @@ public class EndpointLoader : MonoBehaviour
}
}
private void ProcessEndpointResponse(UnityWebRequest request, WebView webView, string endpoint, ref bool loadedFlag)
private void ProcessEndpointResponse(
UnityWebRequest request,
WebView webView,
string endpoint,
ref bool loadedFlag
)
{
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
if (
request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError
)
{
Debug.LogError($"Error loading from {endpoint}: {request.error}");
}
@ -132,7 +145,10 @@ public class EndpointLoader : MonoBehaviour
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
if (
request.result == UnityWebRequest.Result.ConnectionError
|| request.result == UnityWebRequest.Result.ProtocolError
)
{
Debug.LogWarning($"Error loading endpoints: {request.error}");
@ -181,23 +197,28 @@ public class EndpointLoader : MonoBehaviour
Debug.Log("Starting multicast discovery for endpoints");
triedMulticast = true;
serviceDiscovery.StartListening((service) =>
{
bool wasAdded = availableServices.Add(service);
if (wasAdded)
serviceDiscovery.StartListening(
(service) =>
{
AddServiceToTable(service);
bool wasAdded = availableServices.Add(service);
if (wasAdded)
{
AddServiceToTable(service);
}
}
});
);
}
private void AddServiceToTable(MdnsService service)
{
servicesListPopulator.AddItemFromService(service, () =>
{
apiUrl = $"http://{service.Host}:{service.Port}{service.Path}";
StartCoroutine(LoadEndpoints());
});
servicesListPopulator.AddItemFromService(
service,
() =>
{
apiUrl = $"http://{service.Host}:{service.Port}{service.Path}";
StartCoroutine(LoadEndpoints());
}
);
}
public void ClearServices()

View File

@ -23,11 +23,11 @@ public class MdnsService
public override bool Equals(object obj)
{
return obj is MdnsService service &&
IpAddress == service.IpAddress &&
Host == service.Host &&
Port == service.Port &&
Path == service.Path;
return obj is MdnsService service
&& IpAddress == service.IpAddress
&& Host == service.Host
&& Port == service.Port
&& Path == service.Path;
}
public override int GetHashCode()

View File

@ -16,4 +16,4 @@ public class ScrollablePagination : MonoBehaviour
scrollView.MoveByTiers(amount);
}
}
}

View File

@ -1,11 +1,11 @@
using System;
using System.Net;
using System.Net.Sockets;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Collections.Generic;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
public class ServiceDiscovery : MonoBehaviour
@ -82,7 +82,11 @@ public class ServiceDiscovery : MonoBehaviour
}
udpClient = new UdpClient();
udpClient.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
udpClient.Client.SetSocketOption(
SocketOptionLevel.Socket,
SocketOptionName.ReuseAddress,
true
);
udpClient.Client.Bind(new IPEndPoint(defaultIP, multicastPort));
udpClient.JoinMulticastGroup(IPAddress.Parse(multicastAddress), defaultIP);
@ -105,7 +109,11 @@ public class ServiceDiscovery : MonoBehaviour
byte[] query = CreateMdnsQuery(serviceName);
Debug.Log($"Sending mDNS query for {serviceName}");
udpClient.Send(query, query.Length, new IPEndPoint(IPAddress.Parse(multicastAddress), multicastPort));
udpClient.Send(
query,
query.Length,
new IPEndPoint(IPAddress.Parse(multicastAddress), multicastPort)
);
}
private byte[] CreateMdnsQuery(string serviceName)
@ -114,9 +122,27 @@ public class ServiceDiscovery : MonoBehaviour
ushort flags = 0x0100;
ushort questions = 1;
byte[] header = new byte[12];
Array.Copy(BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)transactionId)), 0, header, 0, 2);
Array.Copy(BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)flags)), 0, header, 2, 2);
Array.Copy(BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)questions)), 0, header, 4, 2);
Array.Copy(
BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)transactionId)),
0,
header,
0,
2
);
Array.Copy(
BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)flags)),
0,
header,
2,
2
);
Array.Copy(
BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)questions)),
0,
header,
4,
2
);
byte[] name = EncodeName(serviceName);
byte[] query = new byte[header.Length + name.Length + 4];
@ -160,7 +186,10 @@ public class ServiceDiscovery : MonoBehaviour
IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, multicastPort);
byte[] receivedBytes = udpClient.EndReceive(result, ref remoteEndPoint);
ushort flags = BitConverter.ToUInt16(new byte[] { receivedBytes[3], receivedBytes[2] }, 0);
ushort flags = BitConverter.ToUInt16(
new byte[] { receivedBytes[3], receivedBytes[2] },
0
);
if (flags == 0x0100)
{
udpClient?.BeginReceive(OnReceive, null);
@ -179,9 +208,19 @@ public class ServiceDiscovery : MonoBehaviour
private void AddMdnsService()
{
if (receivedIp != null && receivedPort != null && receivedHost != null && receivedPath != null)
if (
receivedIp != null
&& receivedPort != null
&& receivedHost != null
&& receivedPath != null
)
{
MdnsService currentService = new MdnsService(receivedIp, int.Parse(receivedPort), receivedPath, receivedHost);
MdnsService currentService = new MdnsService(
receivedIp,
int.Parse(receivedPort),
receivedPath,
receivedHost
);
serviceQueue.Enqueue(currentService);
Debug.Log($"Added service: {currentService}");
receivedIp = null;
@ -221,10 +260,13 @@ public class ServiceDiscovery : MonoBehaviour
string name;
(name, offset) = ReadName(data, offset);
ushort recordType = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset));
ushort recordClass = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 2));
ushort recordType = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset));
ushort recordClass = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 2));
uint ttl = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, offset + 4));
ushort dataLength = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 8));
ushort dataLength = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 8));
offset += 10;
if (ttl == 0)
@ -235,7 +277,9 @@ public class ServiceDiscovery : MonoBehaviour
if (recordType == 1) // A Record
{
IPAddress ipAddress = new IPAddress(new ArraySegment<byte>(data, offset, dataLength).ToArray());
IPAddress ipAddress = new IPAddress(
new ArraySegment<byte>(data, offset, dataLength).ToArray()
);
receivedIp = ipAddress.ToString();
receivedHost = name;
}
@ -246,9 +290,12 @@ public class ServiceDiscovery : MonoBehaviour
}
else if (recordType == 33) // SRV Record
{
ushort priority = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset));
ushort weight = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 2));
ushort port = (ushort)IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 4));
ushort priority = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset));
ushort weight = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 2));
ushort port = (ushort)
IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, offset + 4));
string target;
(target, _) = ReadName(data, offset + 6);
receivedPort = port.ToString();
@ -341,4 +388,3 @@ public class ServiceDiscovery : MonoBehaviour
udpClient = null;
}
}

View File

@ -1,9 +1,9 @@
using TMPro;
using System;
using System;
using System.Collections;
using UnityEngine;
using Microsoft.MixedReality.Toolkit.UI;
using Microsoft.MixedReality.Toolkit.Utilities;
using TMPro;
using UnityEngine;
public class ServicesListPopulator : MonoBehaviour
{
@ -27,12 +27,14 @@ public class ServicesListPopulator : MonoBehaviour
TextMeshPro[] textMeshes = itemInstance.GetComponentsInChildren<TextMeshPro>();
textMeshes[0].text = service.Host + ":" + service.Port + service.Path;
textMeshes[1].text = service.IpAddress;
itemInstance.GetComponentInChildren<Interactable>().OnClick.AddListener(() =>
{
Debug.Log($"Clicked on service: {service.Host}");
action.Invoke();
ToggleVisibility();
});
itemInstance
.GetComponentInChildren<Interactable>()
.OnClick.AddListener(() =>
{
Debug.Log($"Clicked on service: {service.Host}");
action.Invoke();
ToggleVisibility();
});
gridObjectCollection.UpdateCollection();
scrollView.UpdateContent();
@ -58,7 +60,11 @@ public class ServicesListPopulator : MonoBehaviour
foreach (Transform child in gridObjectCollection.transform)
{
TextMeshPro[] textMeshes = child.GetComponentsInChildren<TextMeshPro>();
if (textMeshes.Length >= 2 && textMeshes[0].text == fullAddress && textMeshes[1].text == ipAddress)
if (
textMeshes.Length >= 2
&& textMeshes[0].text == fullAddress
&& textMeshes[1].text == ipAddress
)
{
Debug.Log($"Removing service from table: {service}");
Destroy(child.gameObject);
@ -76,4 +82,4 @@ public class ServicesListPopulator : MonoBehaviour
gameObject.SetActive(isVisible);
}
}
}

View File

@ -1,8 +1,8 @@
using Microsoft.MixedReality.WebView;
using UnityEngine.UI;
using UnityEngine;
using TMPro;
using System;
using Microsoft.MixedReality.WebView;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class WebViewBrowser : MonoBehaviour
{
@ -12,17 +12,19 @@ public class WebViewBrowser : MonoBehaviour
private void Start()
{
var webViewComponent = gameObject.GetComponent<WebView>();
webViewComponent.GetWebViewWhenReady((IWebView webView) =>
{
URLField.onSubmit.AddListener((text) => LoadUrl(webView));
webView.Navigated += OnNavigated;
if (webView.Page != null)
webViewComponent.GetWebViewWhenReady(
(IWebView webView) =>
{
URLField.text = webView.Page.AbsoluteUri;
URLField.onSubmit.AddListener((text) => LoadUrl(webView));
webView.Navigated += OnNavigated;
if (webView.Page != null)
{
URLField.text = webView.Page.AbsoluteUri;
}
}
});
);
}
private void OnNavigated(string path)
@ -41,4 +43,4 @@ public class WebViewBrowser : MonoBehaviour
Debug.LogWarning("Invalid URL entered.");
}
}
}
}