Refactor code structure for improved readability and maintainability

This commit is contained in:
2026-06-01 18:23:19 +08:00
parent 948d50cab4
commit 9260e46b3c
7 changed files with 1396 additions and 27 deletions

View File

@ -80,7 +80,7 @@ public static class XrRmUdpSenderProjectSetup
string targetHost = ResolveTargetHost();
component.host = targetHost;
component.port = 15000;
component.sendHz = 60.0f;
component.sendHz = 90.0f;
component.convertUnityToProjectCoordinates = true;
component.sendOnStart = true;

View File

@ -168,9 +168,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: e4c7a11d85854eddb40a6a614bfb129c, type: 3}
m_Name:
m_EditorClassIdentifier:
host: 192.168.9.99
host: 192.168.9.92
port: 15000
sendHz: 60
sendHz: 90
convertUnityToProjectCoordinates: 1
sendOnStart: 1
--- !u!114 &100003

View File

@ -12,13 +12,14 @@ public class PicoControllerUdpSender : MonoBehaviour
private const string PortPrefsKey = "xr_rm_udp_sender.port";
private const string SendHzPrefsKey = "xr_rm_udp_sender.send_hz";
private const string ConvertPrefsKey = "xr_rm_udp_sender.convert_coordinates";
private const int MaxPacketsPerFrame = 4;
[Header("ROS UDP Target")]
public string host = "192.168.9.99";
public int port = 15000;
[Header("Send")]
public float sendHz = 60.0f;
public float sendHz = 90.0f;
public bool convertUnityToProjectCoordinates = true;
public bool sendOnStart = true;
@ -106,17 +107,24 @@ public class PicoControllerUdpSender : MonoBehaviour
return;
}
if (Time.unscaledTime < nextSendTime)
{
return;
}
nextSendTime = Time.unscaledTime + 1.0f / Mathf.Max(sendHz, 1.0f);
packet.t = Time.realtimeSinceStartupAsDouble;
FillController(XRNode.LeftHand, packet.controllers.left);
FillController(XRNode.RightHand, packet.controllers.right);
SendPacket();
float now = Time.unscaledTime;
float interval = 1.0f / Mathf.Max(sendHz, 1.0f);
if (nextSendTime <= 0.0f || now - nextSendTime > interval * MaxPacketsPerFrame)
{
nextSendTime = now;
}
int sentThisFrame = 0;
while (now >= nextSendTime && sentThisFrame < MaxPacketsPerFrame)
{
packet.t = Time.realtimeSinceStartupAsDouble;
SendPacket();
nextSendTime += interval;
sentThisFrame++;
}
}
public bool ApplyConfig(string newHost, int newPort, float newSendHz, bool newConvertUnityToProjectCoordinates, bool save)

View File

@ -3,6 +3,11 @@ using System.Globalization;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR;
#if PICO_OPENXR_SDK
using Unity.XR.OpenXR.Features.PICOSupport;
#else
using Unity.XR.PXR;
#endif
public class PicoUdpConfigPanel : MonoBehaviour
{
@ -90,6 +95,29 @@ public class PicoUdpConfigPanel : MonoBehaviour
QualitySettings.vSyncCount = 0;
Screen.sleepTimeout = SleepTimeout.NeverSleep;
XRSettings.eyeTextureResolutionScale = 1.0f;
RequestPicoDisplayRefreshRate();
}
private void RequestPicoDisplayRefreshRate()
{
#if UNITY_ANDROID && !UNITY_EDITOR
try
{
#if PICO_OPENXR_SDK
bool applied = DisplayRefreshRateFeature.SetDisplayRefreshRate((float)targetFrameRate);
if (!applied)
{
Debug.LogWarning($"XR-RM failed to request PICO display refresh rate: {targetFrameRate} Hz");
}
#else
PXR_System.SetSystemDisplayFrequency((float)targetFrameRate);
#endif
}
catch (Exception exception)
{
Debug.LogWarning($"XR-RM failed to request PICO display refresh rate: {exception.Message}");
}
#endif
}
private void EnsurePanel()

View File

@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: PXR_Settings
m_EditorClassIdentifier:
stereoRenderingModeAndroid: 0
systemDisplayFrequency: 0
systemDisplayFrequency: 2
optimizeBufferDiscards: 1
enableAppSpaceWarp: 0
systemSplashScreen: {fileID: 0}