diff --git a/org.mixedrealitytoolkit.core/CHANGELOG.md b/org.mixedrealitytoolkit.core/CHANGELOG.md index 58ea40a5f..f5b74bc77 100644 --- a/org.mixedrealitytoolkit.core/CHANGELOG.md +++ b/org.mixedrealitytoolkit.core/CHANGELOG.md @@ -17,11 +17,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Removed * Removed ITrackedInteractor, as it was supporting an unused codepath and there are better ways to get this data (like querying the attach transform). [PR #1044](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1044) -* Removed FindObjectUtility, as it was a backwards-compatibility layer for pre-2021.3.18. Since our min version is now 2022.3, we can just call the API directly. [PR #1056](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1056) ### Deprecated * Deprecated IHandedInteractor, as its info is now queryable directly from IXRInteractor's handedness property. [PR #1042](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1042) +* Deprecated FindObjectUtility, as it was a backwards-compatibility layer for pre-2021.3.18. Since our min version is now 2022.3, we can just call the API directly. [PR #1058](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1058) ## [4.0.0-development.pre.1] - 2024-07-09 diff --git a/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs b/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs new file mode 100644 index 000000000..204b60847 --- /dev/null +++ b/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs @@ -0,0 +1,54 @@ +// Copyright (c) Mixed Reality Toolkit Contributors +// Licensed under the BSD 3-Clause + +using System; +using UnityEngine; + +namespace MixedReality.Toolkit +{ + /// + /// A static utility used to avoid deprecated Find Object functions in favor of replacements introduced in Unity >= 2021.3.18. + /// + [Obsolete("FindObjectUtility has been deprecated in version 4.0.0. Please use the corresponding UnityEngine.Object methods instead.")] + public static class FindObjectUtility + { + /// + /// Returns the first object matching the specified type. + /// + /// If true, inactive objects will be included in the search. False by default. + public static T FindFirstObjectByType(bool includeInactive = false) where T : Component + { + return UnityEngine.Object.FindFirstObjectByType(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude); + } + + /// + /// Returns an object matching the specified type. + /// + /// If true, inactive objects will be included in the search. False by default. + public static T FindAnyObjectByType(bool includeInactive = false) where T : Component + { + return UnityEngine.Object.FindAnyObjectByType(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude); + } + + /// + /// Returns all objects matching the specified type. + /// + /// If true, inactive objects will be included in the search. False by default. + /// If false, results will not sorted by InstanceID. True by default. + public static T[] FindObjectsByType(bool includeInactive = false, bool sort = true) where T : Component + { + return UnityEngine.Object.FindObjectsByType(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None); + } + + /// + /// Returns all objects matching the specified type. + /// + /// If true, inactive objects will be included in the search. False by default. + /// If false, results will not sorted by InstanceID. True by default. + /// The type to search for. + public static UnityEngine.Object[] FindObjectsByType(Type type, bool includeInactive = false, bool sort = true) + { + return UnityEngine.Object.FindObjectsByType(type, includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None); + } + } +} diff --git a/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs.meta b/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs.meta new file mode 100644 index 000000000..af04befc3 --- /dev/null +++ b/org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1b33dd2ea80dac64b9bb8676798b8924 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsHandleInteractable.cs b/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsHandleInteractable.cs index 2e609bdf9..ca77701c1 100644 --- a/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsHandleInteractable.cs +++ b/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsHandleInteractable.cs @@ -13,7 +13,7 @@ namespace MixedReality.Toolkit.SpatialManipulation /// Scale handles subclass this to implement custom occlusion + reorientation logic. /// [AddComponentMenu("MRTK/Spatial Manipulation/Bounds Handle Interactable")] - public class BoundsHandleInteractable : StatefulInteractable, ISnapInteractable + public class BoundsHandleInteractable : StatefulInteractable, ISnapInteractable, ISerializationCallbackReceiver { private BoundsControl boundsControlRoot; @@ -57,6 +57,41 @@ public BoundsControl BoundsControlRoot [Tooltip("Maximum lossy scale for the handle. Only applicable if ScaleAdjustType is Advanced.")] private float maxLossyScale = 4f; + #region Handling Obsolete Properties + + // A temporary variable used to migrate instances of BoundsHandleInteractable to use the scaleMaintainType property + // instead of the serialized field maintainGlobalSize. + // TODO: Remove this after some time to ensure users have successfully migrated. + [SerializeField, HideInInspector] + private bool migratedSuccessfully = false; + + [SerializeField, HideInInspector] + private bool maintainGlobalSize = true; + + /// + /// Should the handle maintain its global size, even as the object changes size? + /// + [Obsolete("This property has been deprecated in version 3.4.0. Use ScaleMaintainType instead.")] + public bool MaintainGlobalSize + { + get => scaleMaintainType == ScaleMaintainType.GlobalSize; + set => scaleMaintainType = value ? ScaleMaintainType.GlobalSize : ScaleMaintainType.FixedScale; + } + + public void OnBeforeSerialize() { } + + public void OnAfterDeserialize() + { + // Only update the scaleMaintainType if it hasn't been set and the old property was not migrated yet + if (!migratedSuccessfully && scaleMaintainType == ScaleMaintainType.GlobalSize) + { + scaleMaintainType = maintainGlobalSize ? ScaleMaintainType.GlobalSize : ScaleMaintainType.FixedScale; + migratedSuccessfully = true; + } + } + + #endregion Handling Obsolete Properties + #endregion Bounds Handle Scaling #region ISnapInteractable