Skip to content

Commit f44d942

Browse files
authored
Restore a few deleted things (and obsolete them instead) (#1058)
* Re-add FindObjectUtility (and obsolete it) * Update CHANGELOG.md * Re-add BoundsHandleInteractable's migration path, as we haven't even had a 3.x release with it yet
1 parent aaa2f22 commit f44d942

File tree

4 files changed

+102
-2
lines changed

4 files changed

+102
-2
lines changed

org.mixedrealitytoolkit.core/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1717
### Removed
1818

1919
* 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)
20-
* 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)
2120

2221
### Deprecated
2322

2423
* Deprecated IHandedInteractor, as its info is now queryable directly from IXRInteractor's handedness property. [PR #1042](https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity/pull/1042)
24+
* 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)
2525

2626
## [4.0.0-development.pre.1] - 2024-07-09
2727

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Mixed Reality Toolkit Contributors
2+
// Licensed under the BSD 3-Clause
3+
4+
using System;
5+
using UnityEngine;
6+
7+
namespace MixedReality.Toolkit
8+
{
9+
/// <summary>
10+
/// A static utility used to avoid deprecated Find Object functions in favor of replacements introduced in Unity >= 2021.3.18.
11+
/// </summary>
12+
[Obsolete("FindObjectUtility has been deprecated in version 4.0.0. Please use the corresponding UnityEngine.Object methods instead.")]
13+
public static class FindObjectUtility
14+
{
15+
/// <summary>
16+
/// Returns the first object matching the specified type.
17+
/// </summary>
18+
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
19+
public static T FindFirstObjectByType<T>(bool includeInactive = false) where T : Component
20+
{
21+
return UnityEngine.Object.FindFirstObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
22+
}
23+
24+
/// <summary>
25+
/// Returns an object matching the specified type.
26+
/// </summary>
27+
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
28+
public static T FindAnyObjectByType<T>(bool includeInactive = false) where T : Component
29+
{
30+
return UnityEngine.Object.FindAnyObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
31+
}
32+
33+
/// <summary>
34+
/// Returns all objects matching the specified type.
35+
/// </summary>
36+
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
37+
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
38+
public static T[] FindObjectsByType<T>(bool includeInactive = false, bool sort = true) where T : Component
39+
{
40+
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
41+
}
42+
43+
/// <summary>
44+
/// Returns all objects matching the specified type.
45+
/// </summary>
46+
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
47+
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
48+
/// <param name="type">The type to search for.</param>
49+
public static UnityEngine.Object[] FindObjectsByType(Type type, bool includeInactive = false, bool sort = true)
50+
{
51+
return UnityEngine.Object.FindObjectsByType(type, includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
52+
}
53+
}
54+
}

org.mixedrealitytoolkit.core/Utilities/FindObjectUtility.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsHandleInteractable.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MixedReality.Toolkit.SpatialManipulation
1313
/// Scale handles subclass this to implement custom occlusion + reorientation logic.
1414
/// </summary>
1515
[AddComponentMenu("MRTK/Spatial Manipulation/Bounds Handle Interactable")]
16-
public class BoundsHandleInteractable : StatefulInteractable, ISnapInteractable
16+
public class BoundsHandleInteractable : StatefulInteractable, ISnapInteractable, ISerializationCallbackReceiver
1717
{
1818
private BoundsControl boundsControlRoot;
1919

@@ -57,6 +57,41 @@ public BoundsControl BoundsControlRoot
5757
[Tooltip("Maximum lossy scale for the handle. Only applicable if ScaleAdjustType is Advanced.")]
5858
private float maxLossyScale = 4f;
5959

60+
#region Handling Obsolete Properties
61+
62+
// A temporary variable used to migrate instances of BoundsHandleInteractable to use the scaleMaintainType property
63+
// instead of the serialized field maintainGlobalSize.
64+
// TODO: Remove this after some time to ensure users have successfully migrated.
65+
[SerializeField, HideInInspector]
66+
private bool migratedSuccessfully = false;
67+
68+
[SerializeField, HideInInspector]
69+
private bool maintainGlobalSize = true;
70+
71+
/// <summary>
72+
/// Should the handle maintain its global size, even as the object changes size?
73+
/// </summary>
74+
[Obsolete("This property has been deprecated in version 3.4.0. Use ScaleMaintainType instead.")]
75+
public bool MaintainGlobalSize
76+
{
77+
get => scaleMaintainType == ScaleMaintainType.GlobalSize;
78+
set => scaleMaintainType = value ? ScaleMaintainType.GlobalSize : ScaleMaintainType.FixedScale;
79+
}
80+
81+
public void OnBeforeSerialize() { }
82+
83+
public void OnAfterDeserialize()
84+
{
85+
// Only update the scaleMaintainType if it hasn't been set and the old property was not migrated yet
86+
if (!migratedSuccessfully && scaleMaintainType == ScaleMaintainType.GlobalSize)
87+
{
88+
scaleMaintainType = maintainGlobalSize ? ScaleMaintainType.GlobalSize : ScaleMaintainType.FixedScale;
89+
migratedSuccessfully = true;
90+
}
91+
}
92+
93+
#endregion Handling Obsolete Properties
94+
6095
#endregion Bounds Handle Scaling
6196

6297
#region ISnapInteractable

0 commit comments

Comments
 (0)