Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Precompile Statements to Prevent Warnings in Unity 2023 #11790

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update Asmdef
marlenaklein-msft committed Oct 25, 2023
commit f01164e9e3e6169a97b777679c638293d2df59d5
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ private static void OnSceneSaved(Scene scene)

private static void CleanupCurrentFacades()
{
foreach (MixedRealityToolkit toolkitInstance in FindObjectUtility.FindObjectsOfType<MixedRealityToolkit>())
foreach (MixedRealityToolkit toolkitInstance in FindObjectUtility.FindObjectsByType<MixedRealityToolkit>())
{
DestroyAllChildren(toolkitInstance);
}
Original file line number Diff line number Diff line change
@@ -423,7 +423,7 @@ protected override void OnEnable()
}
else
{
foreach (var dbr in FindObjectUtility.FindObjectsOfType<DepthBufferRenderer>())
foreach (var dbr in FindObjectUtility.FindObjectsByType<DepthBufferRenderer>())
{
UnityObjectExtensions.DestroyObject(dbr);
}
Original file line number Diff line number Diff line change
@@ -347,7 +347,7 @@ private static void RefreshSceneInfoFieldsInOpenScenes()
foreach (Tuple<Type, FieldInfo> typeFieldInfoPair in cachedComponentTypes)
{
FieldInfo fieldInfo = typeFieldInfoPair.Item2;
foreach (Component source in FindObjectUtility.FindObjectsOfType(typeFieldInfoPair.Item1))
foreach (Component source in FindObjectUtility.FindObjectsByType(typeFieldInfoPair.Item1))
{
CheckForChangesInField(source, fieldInfo);
}
4 changes: 2 additions & 2 deletions Assets/MRTK/Core/Services/MixedRealityToolkit.cs
Original file line number Diff line number Diff line change
@@ -586,7 +586,7 @@ private void EnsureMixedRealityRequirements()
bool addedComponents = false;
if (!Application.isPlaying && CameraCache.Main != null)
{
EventSystem[] eventSystems = FindObjectUtility.FindObjectsOfType<EventSystem>();
EventSystem[] eventSystems = FindObjectUtility.FindObjectsByType<EventSystem>();

if (eventSystems.Length == 0)
{
@@ -644,7 +644,7 @@ public static MixedRealityToolkit Instance
//
// To avoid returning null in this case, make sure to search the scene for MRTK.
// We do this only when in editor to avoid any performance cost at runtime.
List<MixedRealityToolkit> mrtks = new List<MixedRealityToolkit>(FindObjectUtility.FindObjectsOfType<MixedRealityToolkit>());
List<MixedRealityToolkit> mrtks = new List<MixedRealityToolkit>(FindObjectUtility.FindObjectsByType<MixedRealityToolkit>());
// Sort the list by instance ID so we get deterministic results when selecting our next active instance
mrtks.Sort(delegate (MixedRealityToolkit i1, MixedRealityToolkit i2) { return i1.GetInstanceID().CompareTo(i2.GetInstanceID()); });

9 changes: 8 additions & 1 deletion Assets/MRTK/Core/Utilities/Async/MRTK.Async.asmdef
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "Microsoft.MixedReality.Toolkit.Async",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
@@ -8,6 +9,12 @@
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"versionDefines": [
{
"name": "Unity",
"expression": "2021.3.18",
"define": "UNITY_2021_3_18_OR_NEWER"
}
],
"noEngineReferences": false
}
2 changes: 1 addition & 1 deletion Assets/MRTK/Core/Utilities/CameraCache.cs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ public static Camera Main
Debug.Log("No main camera found. Searching for cameras in the scene.");

// If no main camera was found, try to determine one.
Camera[] cameras = FindObjectUtility.FindObjectsOfType<Camera>();
Camera[] cameras = FindObjectUtility.FindObjectsByType<Camera>();
if (cameras.Length == 0)
{
Debug.LogWarning("No cameras found. Creating a \"MainCamera\".");
35 changes: 31 additions & 4 deletions Assets/MRTK/Core/Utilities/FindObjectUtility.cs
Original file line number Diff line number Diff line change
@@ -6,27 +6,54 @@

namespace Microsoft.MixedReality.Toolkit.Utilities
{
/// <summary>
/// A static utility used to avoid deprecated Find Object functions in favor of replacements introduced in Unity >= 2021.3.18.
/// </summary>
public static class FindObjectUtility
{
/// <summary>
/// Returns the first object matching the specified type.
/// </summary>
/// <remarks>
/// If Unity >= 2021.3.18, calls FindFirstObjectByType. Otherwise calls FindObjectOfType.
/// </remarks>
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
public static T FindObjectByType<T>(bool includeInactive = false) where T : Component
{
#if UNITY_2021_3_18_OR_NEWER
return UnityEngine.Object.FindFirstObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
return UnityEngine.Object.FindFirstObjectByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude);
#else
return UnityEngine.Object.FindObjectOfType<T>(includeInactive);
#endif
}

public static T[] FindObjectsOfType<T>(bool includeInactive = false, bool sort = true) where T : Component
/// <summary>
/// Returns all objects matching the specified type.
/// </summary>
/// <remarks>
/// If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
/// </remarks>
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
public static T[] FindObjectsByType<T>(bool includeInactive = false, bool sort = true) where T : Component
{
#if UNITY_2021_3_18_OR_NEWER
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
return UnityEngine.Object.FindObjectsByType<T>(includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
#else
return UnityEngine.Object.FindObjectsOfType<T>(includeInactive);
#endif
}

public static UnityEngine.Object[] FindObjectsOfType(Type type, bool includeInactive = false, bool sort = true)
/// <summary>
/// Returns all objects matching the specified type.
/// </summary>
/// <remarks>
/// If Unity >= 2021.3.18, calls FindObjectsByType. Otherwise calls FindObjectsOfType.
/// </remarks>
/// <param name="includeInactive">If true, inactive objects will be included in the search. False by default.</param>
/// <param name="sort">If false, results will not sorted by InstanceID. True by default.</param>
/// <param name="type">The type to search for.</param>
public static UnityEngine.Object[] FindObjectsByType(Type type, bool includeInactive = false, bool sort = true)
{
#if UNITY_2021_3_18_OR_NEWER
return UnityEngine.Object.FindObjectsByType(type, includeInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude, sort ? FindObjectsSortMode.InstanceID : FindObjectsSortMode.None);
Original file line number Diff line number Diff line change
@@ -422,15 +422,15 @@ private List<Camera> GatherFadeTargetCameras()
{
case CameraFaderTargets.All:
// Add every single camera in all scenes
targetCameras.AddRange(FindObjectUtility.FindObjectsOfType<Camera>());
targetCameras.AddRange(FindObjectUtility.FindObjectsByType<Camera>());
break;

case CameraFaderTargets.Main:
targetCameras.Add(CameraCache.Main);
break;

case CameraFaderTargets.UI:
foreach (Canvas canvas in FindObjectUtility.FindObjectsOfType<Canvas>())
foreach (Canvas canvas in FindObjectUtility.FindObjectsByType<Canvas>())
{
switch (canvas.renderMode)
{
Original file line number Diff line number Diff line change
@@ -297,7 +297,7 @@ private void MigrateAppBar(BoundingBox boundingBox, BoundsControl boundsControl)
{
// note: this might be expensive for larger scenes but we don't know where the appbar is
// placed in the hierarchy so we have to search the scene for it
AppBar[] appBars = FindObjectUtility.FindObjectsOfType<AppBar>();
AppBar[] appBars = FindObjectUtility.FindObjectsByType<AppBar>();
for (int i = 0; i < appBars.Length; ++i)
{
AppBar appBar = appBars[i];
Original file line number Diff line number Diff line change
@@ -336,7 +336,7 @@ public void RemoveAllAnchors()
Debug.LogWarning("[WorldAnchorManager] RemoveAllAnchors called before anchor store is ready.");
}

var anchors = FindObjectUtility.FindObjectsOfType<WorldAnchor>();
var anchors = FindObjectUtility.FindObjectsByType<WorldAnchor>();

if (anchors == null)
{
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ private void InitializeManager()
Initialize<IMixedRealityRaycastProvider>(profile.RaycastProviderType, args: args);


EventSystem[] eventSystems = FindObjectUtility.FindObjectsOfType<EventSystem>();
EventSystem[] eventSystems = FindObjectUtility.FindObjectsByType<EventSystem>();

if (eventSystems.Length == 0)
{
Original file line number Diff line number Diff line change
@@ -170,7 +170,7 @@ public override void Initialize()
return;
}

BaseInputModule[] inputModules = FindObjectUtility.FindObjectsOfType<BaseInputModule>();
BaseInputModule[] inputModules = FindObjectUtility.FindObjectsByType<BaseInputModule>();

if (inputModules.Length == 0)
{
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ private void InitializeInternal()
#if UNITY_EDITOR
if (!UnityEditor.EditorApplication.isPlaying)
{
var eventSystems = FindObjectUtility.FindObjectsOfType<EventSystem>();
var eventSystems = FindObjectUtility.FindObjectsByType<EventSystem>();

if (eventSystems.Length == 0)
{
Original file line number Diff line number Diff line change
@@ -477,7 +477,7 @@ public void TestCreateMultipleInstancesInMultipleScenes()
_ = new GameObject("MixedRealityToolkit").AddComponent<MixedRealityToolkit>();
}

MixedRealityToolkit[] instances = FindObjectUtility.FindObjectsOfType<MixedRealityToolkit>();
MixedRealityToolkit[] instances = FindObjectUtility.FindObjectsByType<MixedRealityToolkit>();
for (int i = 0; i < instances.Length; i++)
{
MixedRealityToolkit.SetActiveInstance(instances[i]);
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ public IEnumerator VerifyPlayspaceChildren()
int uiRaycastCameraCount = 0;
// Confirm that we have one UIRaycastCamera.
Debug.Log("Validating UIRaycastCamera count.");
Camera[] cameras = FindObjectUtility.FindObjectsOfType<Camera>();
Camera[] cameras = FindObjectUtility.FindObjectsByType<Camera>();
foreach (Camera camera in cameras)
{
if ("UIRaycastCamera" == camera.name)
2 changes: 1 addition & 1 deletion Assets/MRTK/Tests/TestUtilities/PlayModeTestUtilities.cs
Original file line number Diff line number Diff line change
@@ -266,7 +266,7 @@ public static IEnumerator SetupMrtkWithoutGlobalInputHandlers()
UnityEngine.Object.Destroy(CoreServices.InputSystem.GazeProvider.GazeCursor as Behaviour);
CoreServices.InputSystem.GazeProvider.Enabled = false;

var diagnosticsVoiceControls = FindObjectUtility.FindObjectsOfType<DiagnosticsSystemVoiceControls>();
var diagnosticsVoiceControls = FindObjectUtility.FindObjectsByType<DiagnosticsSystemVoiceControls>();
foreach (var diagnosticsComponent in diagnosticsVoiceControls)
{
diagnosticsComponent.enabled = false;
2 changes: 1 addition & 1 deletion Assets/MRTK/Tests/TestUtilities/TestUtilities.cs
Original file line number Diff line number Diff line change
@@ -274,7 +274,7 @@ public static void InitializeMixedRealityToolkitAndCreateScenes(bool useDefaultP

public static void InitializeCamera()
{
Camera[] cameras = FindObjectUtility.FindObjectsOfType<Camera>();
Camera[] cameras = FindObjectUtility.FindObjectsByType<Camera>();

if (cameras.Length == 0)
{
10 changes: 5 additions & 5 deletions Assets/MRTK/Tools/OptimizeWindow/MixedRealityOptimizeWindow.cs
Original file line number Diff line number Diff line change
@@ -506,13 +506,13 @@ private void RenderOptimalRenderingSection()

private void AnalyzeScene()
{
sceneLights = FindObjectUtility.FindObjectsOfType<Light>();
sceneLights = FindObjectUtility.FindObjectsByType<Light>();

AnalyzeRaycastTargets();

// TODO: Consider searching for particle renderers count?

MeshesOrderedByPolyCountDesc = FindObjectUtility.FindObjectsOfType<MeshFilter>()
MeshesOrderedByPolyCountDesc = FindObjectUtility.FindObjectsByType<MeshFilter>()
.Where(f => f != null && f.sharedMesh != null)
.OrderByDescending(f => f.sharedMesh.triangles.Length)
.ToArray();
@@ -537,8 +537,8 @@ private void AnalyzeScene()

private void AnalyzeRaycastTargets()
{
totalRaycastableUnityUI_Text = FindObjectUtility.FindObjectsOfType<Text>().Where(t => t.raycastTarget).Count();
totalRaycastableUnityUI_TMP_UGUI = FindObjectUtility.FindObjectsOfType<TextMeshProUGUI>().Where(t => t.raycastTarget).Count();
totalRaycastableUnityUI_Text = FindObjectUtility.FindObjectsByType<Text>().Where(t => t.raycastTarget).Count();
totalRaycastableUnityUI_TMP_UGUI = FindObjectUtility.FindObjectsByType<TextMeshProUGUI>().Where(t => t.raycastTarget).Count();
}

private void DiscoverMaterials()
@@ -591,7 +591,7 @@ private bool CanConvertMaterial(Material asset)

private static void DisableRaycastTargetAll<T>() where T : Graphic
{
DisableRaycastTarget(FindObjectUtility.FindObjectsOfType<T>());
DisableRaycastTarget(FindObjectUtility.FindObjectsByType<T>());
}

private static void DisableRaycastTarget(Graphic[] elements)
2 changes: 1 addition & 1 deletion Assets/MRTK/Tools/Toolbox/MixedRealityToolboxWindow.cs
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ private static bool IsSearchMatch(string field, string searchContent)

private void FindAllMRTKCanvases()
{
canvasUtilities = FindObjectUtility.FindObjectsOfType<Input.Utilities.CanvasUtility>();
canvasUtilities = FindObjectUtility.FindObjectsByType<Input.Utilities.CanvasUtility>();
dropdownValues = new string[canvasUtilities.Length];

for (int i = 0; i < canvasUtilities.Length; i++)