diff --git a/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_02_InteractionDefinitionTests.cs b/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_02_InteractionDefinitionTests.cs index ca3b941c4..faa5b777c 100644 --- a/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_02_InteractionDefinitionTests.cs +++ b/XRTK-Core/Assets/XRTK.Tests/InputSystem/TestFixture_02_InteractionDefinitionTests.cs @@ -1,11 +1,13 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See LICENSE in the project root for license information. +using System.Diagnostics; using XRTK.Definitions.Devices; using XRTK.Definitions.InputSystem; using XRTK.Definitions.Utilities; using NUnit.Framework; using UnityEngine; +using Debug = UnityEngine.Debug; namespace XRTK.Tests.InputSystem { @@ -434,6 +436,130 @@ public void Test_04_01_InitializedVector2() Assert.IsFalse(interaction.Updated); } + [Test] + public void Test_04_01_01_Vector2_One() + { + var iterations = 10000000; + var watch = Stopwatch.StartNew(); + + for (int i = 0; i < iterations; i++) + { + var test = Vector2.one; + } + + watch.Stop(); + Debug.Log($"Test Vector2.one execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + + watch = Stopwatch.StartNew(); + var vector2One = new Vector2(1f, 1f); + + for (int i = 0; i < iterations; i++) + { + var test = vector2One; + } + + watch.Stop(); + Debug.Log($"Test cached Vector2 execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + + watch = Stopwatch.StartNew(); + + for (int i = 0; i < iterations; i++) + { + var test = new Vector2(1f, 1f); + } + + watch.Stop(); + Debug.Log($"Test new Vector2 execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + } + + [Test] + public void Test_04_01_02_Checks() + { + var iterations = 10000000; + var value = new Vector2(1, 1); + var vector2Data = new Vector2(2, 2); + var changed = false; + var updated = false; + var invertAxis = true; + + var cachedVector2 = new Vector2(1f, 1f); + + var watch = Stopwatch.StartNew(); + + for (int i = 0; i < iterations; i++) + { + var invertMultiplier = Vector2.one; + + if (invertAxis) + { + invertMultiplier.x = -1f; + } + + if (!invertAxis) + { + invertMultiplier.y = -1f; + } + + invertAxis = !invertAxis; + var newValue = value * invertMultiplier; + changed = vector2Data != newValue; + updated = changed || !newValue.Equals(Vector2.zero); + // use the internal reading for changed so we don't reset it. + vector2Data = newValue; + } + + watch.Stop(); + Debug.Log($"Test Vector2.one execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + + watch = Stopwatch.StartNew(); + + for (int i = 0; i < iterations; i++) + { + var invertMultiplier = cachedVector2; + + if (invertAxis) + { + invertMultiplier.x = -1f; + } + else + { + invertMultiplier.x = 1f; + } + + if (!invertAxis) + { + invertMultiplier.y = -1f; + } + else + { + invertMultiplier.y = 1f; + } + + invertAxis = !invertAxis; + var newValue = value * invertMultiplier; + changed = vector2Data != newValue; + updated = changed || !newValue.Equals(Vector2.zero); + vector2Data = newValue; + } + + watch.Stop(); + Debug.Log($"Test Vector2 execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + + watch = Stopwatch.StartNew(); + + for (int i = 0; i < iterations; i++) + { + var newValue = value * new Vector2(invertAxis ? -1f : 1f, !invertAxis ? -1f : 1f); + invertAxis = !invertAxis; + changed = vector2Data != newValue; + updated = changed || !newValue.Equals(Vector2.zero); + vector2Data = newValue; + } + + watch.Stop(); + Debug.Log($"Test new Vector2 execution Time: {watch.Elapsed.TotalMilliseconds} ms"); + } + /// /// We test by setting the interaction data to two different values. /// We expect that == true, then false after each subsequent check before assigning a new value. @@ -1294,7 +1420,7 @@ public void Test_08_07_InteractionArrayMixedRealityPose() var initialValue = interactions[0]; Assert.IsNotNull(initialValue); - MixedRealityPose initialSixDofValue = initialValue.PoseData; + var initialSixDofValue = initialValue.PoseData; Assert.IsTrue(initialSixDofValue.Position == Vector3.zero); Assert.IsTrue(initialSixDofValue == MixedRealityPose.ZeroIdentity); diff --git a/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/MixedRealityInteractionMapping.cs b/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/MixedRealityInteractionMapping.cs index a1879215f..6565e008a 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/MixedRealityInteractionMapping.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Definitions/Devices/MixedRealityInteractionMapping.cs @@ -133,6 +133,8 @@ public MixedRealityInteractionMapping(MixedRealityInteractionMapping mixedRealit changed = false; } + private readonly Vector2 vector2One = new Vector2(1f, 1f); + #region Interaction Properties [SerializeField] @@ -381,21 +383,21 @@ public float FloatData { if (AxisType != AxisType.SingleAxis) { - Debug.LogError($"SetFloatValue is only valid for AxisType.SingleAxis InteractionMappings\nPlease check the {inputType} mapping for the current controller"); + Debug.LogError( + $"SetFloatValue is only valid for AxisType.SingleAxis InteractionMappings\nPlease check the {inputType} mapping for the current controller"); } + var newValue = value; + if (invertXAxis) { - Changed = !floatData.Equals(value * -1f); - floatData = value * -1f; - } - else - { - Changed = !floatData.Equals(value); - // use the internal reading for changed so we don't reset it. - Updated = changed || !floatData.Equals(0f); - floatData = value; + newValue *= -1f; } + + Changed = !floatData.Equals(newValue); + // use the internal reading for changed so we don't reset it. + Updated = changed || !floatData.Equals(0f); + floatData = value; } } @@ -414,25 +416,23 @@ public Vector2 Vector2Data Debug.LogError($"SetVector2Value is only valid for AxisType.DualAxis InteractionMappings\nPlease check the {inputType} mapping for the current controller"); } - if (invertXAxis || invertYAxis) + var invertMultiplier = vector2One; + + if (invertXAxis) { - var invertXAxisFactor = invertXAxis ? -1f : 1f; - var invertYAxisFactor = invertYAxis ? -1f : 1f; - - Changed = !vector2Data.x.Equals(value.x * invertXAxisFactor) || - !vector2Data.y.Equals(value.y * invertYAxisFactor); - // use the internal reading for changed so we don't reset it. - Updated = changed || !vector2Data.Equals(Vector2.zero); - vector2Data.x = value.x * invertXAxisFactor; - vector2Data.y = value.y * invertYAxisFactor; + invertMultiplier.x = -1f; } - else + + if (invertYAxis) { - Changed = vector2Data != value; - // use the internal reading for changed so we don't reset it. - Updated = changed || !vector2Data.Equals(Vector2.zero); - vector2Data = value; + invertMultiplier.y = -1f; } + + var newValue = value * invertMultiplier; + Changed = vector2Data != newValue; + // use the internal reading for changed so we don't reset it. + Updated = changed || !newValue.Equals(Vector2.zero); + vector2Data = newValue; } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Extensions/BoundsExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Extensions/BoundsExtensions.cs index f54276240..5280fc932 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Extensions/BoundsExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Extensions/BoundsExtensions.cs @@ -343,12 +343,14 @@ public static void GetColliderBoundsPoints(GameObject target, List boun } else if (colliders[i] is CapsuleCollider) { - CapsuleCollider cc = colliders[i] as CapsuleCollider; - Bounds capsuleBounds = new Bounds(cc.center, Vector3.zero); + var cc = (CapsuleCollider)colliders[i]; + var capsuleBounds = new Bounds(cc.center, Vector3.zero); + var radius = cc.radius; + switch (cc.direction) { case 0: - capsuleBounds.size = new Vector3(cc.height, cc.radius * 2, cc.radius * 2); + capsuleBounds.size = new Vector3(cc.height, cc.radius * 2, radius * 2); break; case 1: @@ -356,7 +358,7 @@ public static void GetColliderBoundsPoints(GameObject target, List boun break; case 2: - capsuleBounds.size = new Vector3(cc.radius * 2, cc.radius * 2, cc.height); + capsuleBounds.size = new Vector3(cc.radius * 2, radius * 2, cc.height); break; } capsuleBounds.GetFacePositions(cc.transform, ref corners); diff --git a/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs b/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs index 630d8fc02..a80c18f00 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Extensions/GameObjectExtensions.cs @@ -44,6 +44,7 @@ public static void SetLayerRecursively(this GameObject root, int layer) /// Start point of the traverse /// The layer to apply /// The previously set layer for each object + /// is public static void SetLayerRecursively(this GameObject root, int layer, out Dictionary cache) { if (root == null) { throw new ArgumentNullException(nameof(root)); } @@ -52,8 +53,9 @@ public static void SetLayerRecursively(this GameObject root, int layer, out Dict foreach (var child in root.transform.EnumerateHierarchy()) { - cache[child.gameObject] = child.gameObject.layer; - child.gameObject.layer = layer; + var childGameObject = child.gameObject; + cache[childGameObject] = childGameObject.layer; + childGameObject.layer = layer; } } @@ -62,6 +64,8 @@ public static void SetLayerRecursively(this GameObject root, int layer, out Dict /// /// Start point of the traverse /// The previously set layer for each object + /// is + /// is public static void ApplyLayerCacheRecursively(this GameObject root, Dictionary cache) { if (root == null) { throw new ArgumentNullException(nameof(root)); } @@ -69,9 +73,10 @@ public static void ApplyLayerCacheRecursively(this GameObject root, Dictionary action) { action(root); - Transform[] items = root.GetComponentsInChildren(); + var items = root.GetComponentsInChildren(); for (var i = 0; i < items.Length; i++) { diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/BoundarySystem/MixedRealityBoundarySystem.cs b/XRTK-Core/Packages/com.xrtk.core/Services/BoundarySystem/MixedRealityBoundarySystem.cs index 8a75ab8d0..7b20ae60d 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/BoundarySystem/MixedRealityBoundarySystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/BoundarySystem/MixedRealityBoundarySystem.cs @@ -671,15 +671,16 @@ public GameObject GetFloorVisualization() } var floorScale = FloorScale; + var position = MixedRealityToolkit.Instance.MixedRealityPlayspace.position; // Render the floor. currentFloorObject = GameObject.CreatePrimitive(PrimitiveType.Cube); currentFloorObject.name = "Boundary System Floor"; currentFloorObject.transform.localScale = new Vector3(floorScale.x, BoundaryObjectThickness, floorScale.y); currentFloorObject.transform.Translate(new Vector3( - MixedRealityToolkit.Instance.MixedRealityPlayspace.position.x, + position.x, FloorHeight.Value - (currentFloorObject.transform.localScale.y * 0.5f), - MixedRealityToolkit.Instance.MixedRealityPlayspace.position.z)); + position.z)); currentFloorObject.layer = FloorPhysicsLayer; currentFloorObject.GetComponent().sharedMaterial = FloorMaterial; @@ -756,11 +757,12 @@ public GameObject GetTrackedAreaVisualization() { layer = DefaultIgnoreRaycastLayer }; + + var position = MixedRealityToolkit.Instance.MixedRealityPlayspace.position; + currentTrackedAreaObject.AddComponent(); - currentTrackedAreaObject.transform.Translate(new Vector3( - MixedRealityToolkit.Instance.MixedRealityPlayspace.position.x, - BoundaryObjectRenderOffset, - MixedRealityToolkit.Instance.MixedRealityPlayspace.position.z)); + currentTrackedAreaObject.transform.Translate( + new Vector3(position.x, BoundaryObjectRenderOffset, position.z)); currentPlayAreaObject.layer = TrackedAreaPhysicsLayer; // Configure the renderer properties. diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/InputSystem/MixedRealityInputSystem.cs b/XRTK-Core/Packages/com.xrtk.core/Services/InputSystem/MixedRealityInputSystem.cs index cfec7d553..d6f6ba968 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/InputSystem/MixedRealityInputSystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/InputSystem/MixedRealityInputSystem.cs @@ -115,8 +115,9 @@ public override void Initialize() { var standaloneInputModules = UnityEngine.Object.FindObjectsOfType(); - CameraCache.Main.transform.position = Vector3.zero; - CameraCache.Main.transform.rotation = Quaternion.identity; + var cameraTransform = CameraCache.Main.transform; + cameraTransform.position = Vector3.zero; + cameraTransform.rotation = Quaternion.identity; if (standaloneInputModules.Length == 0) { @@ -144,27 +145,28 @@ public override void Initialize() } else { - sourceStateEventData = new SourceStateEventData(EventSystem.current); + var eventSystem = EventSystem.current; + sourceStateEventData = new SourceStateEventData(eventSystem); - sourceTrackingEventData = new SourcePoseEventData(EventSystem.current); - sourceVector2EventData = new SourcePoseEventData(EventSystem.current); - sourcePositionEventData = new SourcePoseEventData(EventSystem.current); - sourceRotationEventData = new SourcePoseEventData(EventSystem.current); - sourcePoseEventData = new SourcePoseEventData(EventSystem.current); + sourceTrackingEventData = new SourcePoseEventData(eventSystem); + sourceVector2EventData = new SourcePoseEventData(eventSystem); + sourcePositionEventData = new SourcePoseEventData(eventSystem); + sourceRotationEventData = new SourcePoseEventData(eventSystem); + sourcePoseEventData = new SourcePoseEventData(eventSystem); - focusEventData = new FocusEventData(EventSystem.current); + focusEventData = new FocusEventData(eventSystem); - inputEventData = new InputEventData(EventSystem.current); - pointerEventData = new MixedRealityPointerEventData(EventSystem.current); + inputEventData = new InputEventData(eventSystem); + pointerEventData = new MixedRealityPointerEventData(eventSystem); - floatInputEventData = new InputEventData(EventSystem.current); - vector2InputEventData = new InputEventData(EventSystem.current); - positionInputEventData = new InputEventData(EventSystem.current); - rotationInputEventData = new InputEventData(EventSystem.current); - poseInputEventData = new InputEventData(EventSystem.current); + floatInputEventData = new InputEventData(eventSystem); + vector2InputEventData = new InputEventData(eventSystem); + positionInputEventData = new InputEventData(eventSystem); + rotationInputEventData = new InputEventData(eventSystem); + poseInputEventData = new InputEventData(eventSystem); - speechEventData = new SpeechEventData(EventSystem.current); - dictationEventData = new DictationEventData(EventSystem.current); + speechEventData = new SpeechEventData(eventSystem); + dictationEventData = new DictationEventData(eventSystem); } if (!addedComponents) diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs b/XRTK-Core/Packages/com.xrtk.core/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs index 15fc650d9..01867c93e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/SpatialAwarenessSystem/MixedRealitySpatialAwarenessSystem.cs @@ -151,8 +151,9 @@ public override void Initialize() if (Application.isPlaying) { - meshEventData = new MixedRealitySpatialAwarenessEventData(EventSystem.current); - surfaceFindingEventData = new MixedRealitySpatialAwarenessEventData(EventSystem.current); + var eventSystem = EventSystem.current; + meshEventData = new MixedRealitySpatialAwarenessEventData(eventSystem); + surfaceFindingEventData = new MixedRealitySpatialAwarenessEventData(eventSystem); } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Services/TeleportSystem/MixedRealityTeleportSystem.cs b/XRTK-Core/Packages/com.xrtk.core/Services/TeleportSystem/MixedRealityTeleportSystem.cs index ad6fcf1e2..ef3d020f9 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Services/TeleportSystem/MixedRealityTeleportSystem.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Services/TeleportSystem/MixedRealityTeleportSystem.cs @@ -236,12 +236,13 @@ private void ProcessTeleportationRequest(TeleportEventData eventData) } } - float height = targetPosition.y; - targetPosition -= CameraCache.Main.transform.position - cameraParent.position; + var height = targetPosition.y; + var cameraTransform = CameraCache.Main.transform; + var cameraPosition = cameraTransform.position; + targetPosition -= cameraPosition - cameraParent.position; targetPosition.y = height; cameraParent.position = targetPosition; - - cameraParent.RotateAround(CameraCache.Main.transform.position, Vector3.up, targetRotation.y - CameraCache.Main.transform.eulerAngles.y); + cameraParent.RotateAround(cameraPosition, Vector3.up, targetRotation.y - cameraTransform.eulerAngles.y); isProcessingTeleportRequest = false; diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Editor/InputMappingAxisUtility.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Editor/InputMappingAxisUtility.cs index 228c8da81..4ebde84ba 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Editor/InputMappingAxisUtility.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Editor/InputMappingAxisUtility.cs @@ -43,11 +43,11 @@ public static void CheckUnityInputManagerMappings(InputManagerAxis[] axisMapping if (axisMappings != null) { - for (var i = 0; i < axisMappings.Length; i++) + foreach (var axis in axisMappings) { - if (!DoesAxisNameExist(axisMappings[i].Name)) + if (!DoesAxisNameExist(axis.Name)) { - AddAxis(axisMappings[i]); + AddAxis(axis); } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/Interpolator.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/Interpolator.cs index 361018873..882ce49e4 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/Interpolator.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/Interpolator.cs @@ -122,10 +122,11 @@ public class Interpolator : MonoBehaviour private void Awake() { - targetPosition = transform.position; - targetRotation = transform.rotation; - targetLocalRotation = transform.localRotation; - targetLocalScale = transform.localScale; + var targetTransform = transform; + targetPosition = targetTransform.position; + targetRotation = targetTransform.rotation; + targetLocalRotation = targetTransform.localRotation; + targetLocalScale = targetTransform.localScale; enabled = false; } @@ -254,10 +255,11 @@ private void Update() /// Reset() is usually reserved as a MonoBehaviour API call in editor, but is used in this case as a convenience method. public void Reset() { - targetPosition = transform.position; - targetRotation = transform.rotation; - targetLocalRotation = transform.localRotation; - targetLocalScale = transform.localScale; + var targetTransform = transform; + targetPosition = targetTransform.position; + targetRotation = targetTransform.rotation; + targetLocalRotation = targetTransform.localRotation; + targetLocalScale = targetTransform.localScale; AnimatingPosition = false; AnimatingRotation = false; @@ -424,10 +426,11 @@ public void SnapToTarget() { if (enabled) { - transform.position = TargetPosition; - transform.rotation = TargetRotation; - transform.localRotation = TargetLocalRotation; - transform.localScale = TargetLocalScale; + var targetTransform = transform; + targetTransform.position = TargetPosition; + targetTransform.rotation = TargetRotation; + targetTransform.localRotation = TargetLocalRotation; + targetTransform.localScale = TargetLocalScale; AnimatingPosition = false; AnimatingLocalScale = false; diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/TwoHandMoveLogic.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/TwoHandMoveLogic.cs index 5bf7640df..e99ba918e 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/TwoHandMoveLogic.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Physics/TwoHandMoveLogic.cs @@ -34,10 +34,12 @@ public void Setup(Vector3 startHandPositionMeters, Transform manipulationRoot) // The pivot is just below and in front of the head. var pivotPosition = GetHandPivotPosition(); - objRefDistance = Vector3.Distance(manipulationRoot.position, pivotPosition); + var manipulationPosition = manipulationRoot.position; + + objRefDistance = Vector3.Distance(manipulationPosition, pivotPosition); handRefDistance = Vector3.Distance(newHandPosition, pivotPosition); - var objDirection = Vector3.Normalize(manipulationRoot.position - pivotPosition); + var objDirection = Vector3.Normalize(manipulationPosition - pivotPosition); var handDirection = Vector3.Normalize(newHandPosition - pivotPosition); // We transform the forward vector of the object, the direction of the object, and the direction of the hand @@ -84,8 +86,8 @@ public Vector3 Update(Vector3 centroid, Vector3 manipulationObjectPosition) /// A point that is below and just in front of the head. public static Vector3 GetHandPivotPosition() { - Vector3 pivot = CameraCache.Main.transform.position + offsetPosition - CameraCache.Main.transform.forward * 0.2f; // a bit lower and behind - return pivot; + var cameraTransform = CameraCache.Main.transform; + return cameraTransform.position + offsetPosition - cameraTransform.forward * 0.2f; // a bit lower and behind } } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingPlane.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingPlane.cs index d15ca187c..485c82b74 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingPlane.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingPlane.cs @@ -41,13 +41,15 @@ protected override void Initialize() clipPlaneId = Shader.PropertyToID("_ClipPlane"); } - protected override void UpdateShaderProperties(MaterialPropertyBlock _materialPropertyBlock) + protected override void UpdateShaderProperties(MaterialPropertyBlock materialPropertyBlock) { - planeSize.x = transform.up.x; - planeSize.y = transform.up.y; - planeSize.z = transform.up.z; - planeSize.w = Vector3.Dot(transform.up, transform.position); - _materialPropertyBlock.SetVector(clipPlaneId, planeSize); + var clipTransform = transform; + var clipTransformUp = clipTransform.up; + planeSize.x = clipTransformUp.x; + planeSize.y = clipTransformUp.y; + planeSize.z = clipTransformUp.z; + planeSize.w = Vector3.Dot(clipTransformUp, clipTransform.position); + materialPropertyBlock.SetVector(clipPlaneId, planeSize); } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingSphere.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingSphere.cs index c2a71497b..a155a7862 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingSphere.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Rendering/ClippingSphere.cs @@ -46,13 +46,14 @@ protected override void Initialize() clipSphereId = Shader.PropertyToID("_ClipSphere"); } - protected override void UpdateShaderProperties(MaterialPropertyBlock _materialPropertyBlock) + protected override void UpdateShaderProperties(MaterialPropertyBlock materialPropertyBlock) { - sphereSize.x = transform.position.x; - sphereSize.y = transform.position.y; - sphereSize.z = transform.position.z; + var clipTransformPosition = transform.position; + sphereSize.x = clipTransformPosition.x; + sphereSize.y = clipTransformPosition.y; + sphereSize.z = clipTransformPosition.z; sphereSize.w = radius; - _materialPropertyBlock.SetVector(clipSphereId, sphereSize); + materialPropertyBlock.SetVector(clipSphereId, sphereSize); } } } \ No newline at end of file diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/ConstantViewSize.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/ConstantViewSize.cs index b7ea3f634..a67701013 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/ConstantViewSize.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/ConstantViewSize.cs @@ -88,10 +88,12 @@ protected virtual void Start() } else { - Vector3 cachedScale = transform.root.localScale; - transform.root.localScale = Vector3.one; + var cachedTransform = transform; + var cachedRoot = cachedTransform.root; + var cachedScale = cachedRoot.localScale; + cachedRoot.localScale = Vector3.one; - var combinedBounds = new Bounds(transform.position, Vector3.zero); + var combinedBounds = new Bounds(cachedTransform.position, Vector3.zero); var renderers = GetComponentsInChildren(); for (var i = 0; i < renderers.Length; i++) diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/InBetween.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/InBetween.cs index 8cb4b6892..8e743b12a 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/InBetween.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/InBetween.cs @@ -83,8 +83,9 @@ private void AdjustPositionForOffset(Transform targetTransform, Transform second { if (targetTransform != null && secondTransform != null) { - Vector3 centerline = targetTransform.position - secondTransform.position; - GoalPosition = secondTransform.position + (centerline * partwayOffset); + var secondTransformPosition = secondTransform.position; + var centerLine = targetTransform.position - secondTransformPosition; + GoalPosition = secondTransformPosition + (centerLine * partwayOffset); UpdateWorkingPositionToGoal(); } } diff --git a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/Solver.cs b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/Solver.cs index 8ecd2dc10..07214ea40 100644 --- a/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/Solver.cs +++ b/XRTK-Core/Packages/com.xrtk.core/Utilities/Solvers/Solver.cs @@ -251,25 +251,27 @@ public static Quaternion SmoothTo(Quaternion source, Quaternion goal, float delt /// protected void UpdateTransformToGoal() { + var cachedTransform = transform; + if (smoothing) { - Vector3 pos = transform.position; - Quaternion rot = transform.rotation; - Vector3 scale = transform.localScale; + var pos = cachedTransform.position; + var rot = cachedTransform.rotation; + var scale = cachedTransform.localScale; pos = SmoothTo(pos, GoalPosition, SolverHandler.DeltaTime, moveLerpTime); rot = SmoothTo(rot, GoalRotation, SolverHandler.DeltaTime, rotateLerpTime); scale = SmoothTo(scale, GoalScale, SolverHandler.DeltaTime, scaleLerpTime); - transform.position = pos; - transform.rotation = rot; - transform.localScale = scale; + cachedTransform.position = pos; + cachedTransform.rotation = rot; + cachedTransform.localScale = scale; } else { - transform.position = GoalPosition; - transform.rotation = GoalRotation; - transform.localScale = GoalScale; + cachedTransform.position = GoalPosition; + cachedTransform.rotation = GoalRotation; + cachedTransform.localScale = GoalScale; } }