Skip to content

Commit d3b8208

Browse files
committed
changed over more code
1 parent 7550994 commit d3b8208

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

Basis/Packages/com.basis.framework/Device Management/BasisDeviceManagement.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static string StaticCurrentMode
160160
/// <summary>
161161
/// Registered device SDK managers capable of booting into given modes (Desktop/XR/etc.).
162162
/// </summary>
163-
[SerializeField] public List<BasisBaseTypeManagement> BaseTypes = new();
163+
[SerializeField] public BasisBaseTypeManagement[] BaseTypes;
164164

165165
/// <summary>
166166
/// Helpers that constrain transforms to input devices.
@@ -264,7 +264,7 @@ private async void OnDestroy()
264264
public void Simulate()
265265
{
266266
OnDeviceManagementLoop?.Invoke();
267-
int Count = BaseTypes.Count;
267+
int Count = BaseTypes.Length;
268268
for (int Index = 0; Index < Count; Index++)
269269
{
270270
BasisBaseTypeManagement Sim = BaseTypes[Index];
@@ -450,7 +450,8 @@ public async Task StartDevices(string mode)
450450
/// </summary>
451451
public void StopAllDevices()
452452
{
453-
for (int i = 0; i < BaseTypes.Count; i++)
453+
var length = BaseTypes.Length;
454+
for (int i = 0; i < length; i++)
454455
{
455456
BaseTypes[i]?.AttemptStopSDK();
456457
}
@@ -477,7 +478,8 @@ public void ShutDownXR()
477478
/// </summary>
478479
public void StartAllStartIfPermanentlyExists()
479480
{
480-
for (int i = 0; i < BaseTypes.Count; i++)
481+
var length = BaseTypes.Length;
482+
for (int i = 0; i < length; i++)
481483
{
482484
BaseTypes[i]?.StartIfPermanentlyExists();
483485
}
@@ -507,9 +509,13 @@ public static void UnassignFBTrackers()
507509
public bool TryFindBasisBaseTypeManagement(string name, out List<BasisBaseTypeManagement> match, bool OnlyFinding = false)
508510
{
509511
match = new List<BasisBaseTypeManagement>();
510-
if (string.IsNullOrEmpty(name) || BaseTypes == null) return false;
512+
if (string.IsNullOrEmpty(name) || BaseTypes == null)
513+
{
514+
return false;
515+
}
511516

512-
for (int i = 0; i < BaseTypes.Count; i++)
517+
var length = BaseTypes.Length;
518+
for (int i = 0; i < length; i++)
513519
{
514520
var type = BaseTypes[i];
515521
if (type != null && type.AttemptIsDeviceBootable(name, OnlyFinding))
@@ -888,8 +894,9 @@ public async Task SoftSwitchToDesktop()
888894

889895
BasisDebug.Log($"Soft-switching from {AutoSwapPreviousVRMode} to Desktop (keeping runtime alive)", BasisDebug.LogTag.Device);
890896

897+
var length = BaseTypes.Length;
891898
// Soft-stop VR input devices — runtime stays alive
892-
for (int i = 0; i < BaseTypes.Count; i++)
899+
for (int i = 0; i < length; i++)
893900
{
894901
var bt = BaseTypes[i];
895902
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(AutoSwapPreviousVRMode))
@@ -925,8 +932,9 @@ public async Task SoftSwitchToVR()
925932

926933
BasisDebug.Log($"Soft-switching from Desktop back to {vrMode}", BasisDebug.LogTag.Device);
927934

935+
var length = BaseTypes.Length;
928936
// Stop desktop devices normally
929-
for (int i = 0; i < BaseTypes.Count; i++)
937+
for (int i = 0; i < length; i++)
930938
{
931939
var bt = BaseTypes[i];
932940
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(BasisConstants.Desktop))
@@ -941,7 +949,7 @@ public async Task SoftSwitchToVR()
941949
BasisCursorManagement.OnReset();
942950

943951
// Soft-start VR input devices — runtime is already alive
944-
for (int i = 0; i < BaseTypes.Count; i++)
952+
for (int i = 0; i < length; i++)
945953
{
946954
var bt = BaseTypes[i];
947955
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(vrMode))

Basis/Packages/com.basis.framework/IK/BasisIKPlaybackDriver.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Basis.Scripts.Device_Management.Devices.Simulation;
66
using Basis.Scripts.Drivers;
77
using Basis.Scripts.TransformBinders.BoneControl;
8+
using System;
89
using System.Collections.Generic;
910
using UnityEngine;
1011
using UnityEngine.Animations;
@@ -260,8 +261,10 @@ private void CreateSimulatedDevices()
260261

261262
// Find or create the simulation manager
262263
BasisSimulateXR simulator = null;
263-
foreach (var bt in BasisDeviceManagement.Instance.BaseTypes)
264+
var Instance = BasisDeviceManagement.Instance;
265+
for (int Index = 0; Index < Instance.BaseTypes.Length; Index++)
264266
{
267+
BasisBaseTypeManagement bt = Instance.BaseTypes[Index];
265268
if (bt is BasisSimulateXR sim)
266269
{
267270
simulator = sim;
@@ -275,7 +278,10 @@ private void CreateSimulatedDevices()
275278
GameObject simGO = new GameObject("IKPlayback_SimulateXR");
276279
simGO.hideFlags = HideFlags.HideAndDontSave;
277280
simulator = simGO.AddComponent<BasisSimulateXR>();
278-
BasisDeviceManagement.Instance.BaseTypes.Add(simulator);
281+
var oldArray = Instance.BaseTypes;
282+
Array.Resize(ref oldArray, oldArray.Length + 1);
283+
oldArray[^1] = simulator;
284+
Instance.BaseTypes = oldArray;
279285
}
280286

281287
foreach (var (bone, role, group) in BoneRoleMap)

Basis/Packages/com.basis.framework/IK/FootPlacement/BasisLocalFootDriver.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public void Simulate(float dt)
728728
/// <summary>
729729
/// Main-thread input gather + schedule only. Caller must pair with CompleteSimulate().
730730
/// </summary>
731-
public void ScheduleSimulate(float dt)
731+
public unsafe void ScheduleSimulate(float dt)
732732
{
733733
_jobScheduled = false;
734734
if (!IsInitialized || dt <= 0f) return;
@@ -744,8 +744,9 @@ public void ScheduleSimulate(float dt)
744744
var chestCtrl = BasisLocalBoneDriver.ChestControl;
745745
bool groundHit = Physics.Raycast(hips.position, -cachedPlayerUp, out RaycastHit ch, rayCastRange, groundLayers, QueryTriggerInteraction.Ignore);
746746

747-
// ── 2. Pack input ──
748-
_nativeInput[0] = new BasisFootSimInput
747+
// ── 2. Pack input (write in place; no job is in flight here) ──
748+
ref BasisFootSimInput inputSlot = ref UnsafeUtility.ArrayElementAsRef<BasisFootSimInput>(_nativeInput.GetUnsafePtr(), 0);
749+
inputSlot = new BasisFootSimInput
749750
{
750751
dt = dt,
751752
headPos = headData.position,

0 commit comments

Comments
 (0)