Skip to content

Commit f69acf0

Browse files
committed
Cleanup
1 parent deea7d2 commit f69acf0

13 files changed

Lines changed: 86 additions & 92 deletions

File tree

MCPForUnity/Editor/Helpers/GameObjectLookup.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System;
32
using System.Collections.Generic;
43
using System.Linq;

MCPForUnity/Editor/Resources/Editor/Windows.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System;
32
using System.Collections.Generic;
43
using MCPForUnity.Editor.Helpers;

MCPForUnity/Editor/Tools/Cameras/CameraControl.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System;
32
using System.Collections.Generic;
43
using System.Linq;
@@ -15,23 +14,15 @@ internal static class CameraControl
1514
{
1615
internal static object ListCameras(JObject @params)
1716
{
18-
#if UNITY_2022_2_OR_NEWER
19-
var unityCameras = UnityEngine.Object.FindObjectsByType<UnityEngine.Camera>(FindObjectsSortMode.None);
20-
#else
21-
var unityCameras = UnityEngine.Object.FindObjectsOfType<UnityEngine.Camera>();
22-
#endif
17+
var unityCameras = UnityFindObjectsCompat.FindAll<UnityEngine.Camera>();
2318
var cameraList = new List<object>();
2419
var unityCamList = new List<object>();
2520

2621
// Cinemachine cameras
2722
if (CameraHelpers.HasCinemachine)
2823
{
2924
var cmType = CameraHelpers.CinemachineCameraType;
30-
#if UNITY_2022_2_OR_NEWER
31-
var allCm = UnityEngine.Object.FindObjectsByType(cmType, FindObjectsSortMode.None);
32-
#else
33-
var allCm = UnityEngine.Object.FindObjectsOfType(cmType);
34-
#endif
25+
var allCm = UnityFindObjectsCompat.FindAll(cmType);
3526
foreach (Component cm in allCm)
3627
{
3728
var follow = CameraHelpers.GetReflectionProperty(cm, "Follow") as Transform;

MCPForUnity/Editor/Tools/Cameras/CameraHelpers.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Reflection;
55
using MCPForUnity.Editor.Helpers;
6+
using MCPForUnity.Runtime.Helpers;
67
using Newtonsoft.Json.Linq;
78
using UnityEditor;
89
using UnityEngine;
@@ -141,23 +142,15 @@ internal static Component FindBrain()
141142
if (!HasCinemachine || _cmBrainType == null)
142143
return null;
143144

144-
#if UNITY_2022_2_OR_NEWER
145-
return UnityEngine.Object.FindFirstObjectByType(_cmBrainType) as Component;
146-
#else
147-
return UnityEngine.Object.FindObjectOfType(_cmBrainType) as Component;
148-
#endif
145+
return UnityFindObjectsCompat.FindAny(_cmBrainType) as Component;
149146
}
150147

151148
internal static UnityEngine.Camera FindMainCamera()
152149
{
153150
var main = UnityEngine.Camera.main;
154151
if (main != null) return main;
155152

156-
#if UNITY_2022_2_OR_NEWER
157-
var allCams = UnityEngine.Object.FindObjectsByType<UnityEngine.Camera>(FindObjectsSortMode.None);
158-
#else
159-
var allCams = UnityEngine.Object.FindObjectsOfType<UnityEngine.Camera>();
160-
#endif
153+
var allCams = UnityFindObjectsCompat.FindAll<UnityEngine.Camera>();
161154
return allCams.Length > 0 ? allCams[0] : null;
162155
}
163156

MCPForUnity/Editor/Tools/GameObjects/ManageGameObjectCommon.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
#nullable disable
32
using System;
43
using System.Collections.Generic;
@@ -156,16 +155,9 @@ internal static List<GameObject> FindObjectsInternal(
156155
}
157156
else
158157
{
159-
#if UNITY_2023_1_OR_NEWER
160-
var inactive = searchInactive ? FindObjectsInactive.Include : FindObjectsInactive.Exclude;
161-
searchPoolComp = UnityEngine.Object.FindObjectsByType(componentType, inactive, FindObjectsSortMode.None)
158+
searchPoolComp = UnityFindObjectsCompat.FindAll(componentType, searchInactive)
162159
.Cast<Component>()
163160
.Select(c => c.gameObject);
164-
#else
165-
searchPoolComp = UnityEngine.Object.FindObjectsOfType(componentType, searchInactive)
166-
.Cast<Component>()
167-
.Select(c => c.gameObject);
168-
#endif
169161
}
170162
results.AddRange(searchPoolComp.Where(go => go != null));
171163
}

MCPForUnity/Editor/Tools/Graphics/GraphicsHelpers.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Reflection;
55
using MCPForUnity.Editor.Helpers;
6+
using MCPForUnity.Runtime.Helpers;
67
using Newtonsoft.Json.Linq;
78
using UnityEditor;
89
using UnityEngine;
@@ -109,11 +110,7 @@ internal static Component FindVolume(JObject @params)
109110
string target = p.Get("target");
110111
if (string.IsNullOrEmpty(target))
111112
{
112-
#if UNITY_2022_2_OR_NEWER
113-
var allVolumes = UnityEngine.Object.FindObjectsByType(VolumeType, FindObjectsSortMode.None);
114-
#else
115-
var allVolumes = UnityEngine.Object.FindObjectsOfType(VolumeType);
116-
#endif
113+
var allVolumes = UnityFindObjectsCompat.FindAll(VolumeType);
117114
return allVolumes.Length > 0 ? allVolumes[0] as Component : null;
118115
}
119116

MCPForUnity/Editor/Tools/Graphics/VolumeOps.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System;
32
using System.Collections.Generic;
43
using System.Linq;
@@ -456,11 +455,7 @@ internal static object ListVolumes(JObject @params)
456455
if (!GraphicsHelpers.HasVolumeSystem)
457456
return new { success = true, message = "Volume system not available.", data = new { volumes = new List<object>() } };
458457

459-
#if UNITY_2022_2_OR_NEWER
460-
var allVolumes = UnityEngine.Object.FindObjectsByType(GraphicsHelpers.VolumeType, FindObjectsSortMode.None);
461-
#else
462-
var allVolumes = UnityEngine.Object.FindObjectsOfType(GraphicsHelpers.VolumeType);
463-
#endif
458+
var allVolumes = UnityFindObjectsCompat.FindAll(GraphicsHelpers.VolumeType);
464459
var volumeList = new List<object>();
465460

466461
foreach (Component vol in allVolumes)

MCPForUnity/Editor/Tools/ManageAsset.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
using UnityEngine;
99
using MCPForUnity.Editor.Helpers; // For Response class
1010
using MCPForUnity.Editor.Tools;
11+
using MCPForUnity.Runtime.Helpers;
1112

1213
#if UNITY_6000_0_OR_NEWER
1314
using PhysicsMaterialType = UnityEngine.PhysicsMaterial;
14-
using PhysicsMaterialCombine = UnityEngine.PhysicsMaterialCombine;
15+
using PhysicsMaterialCombine = UnityEngine.PhysicsMaterialCombine;
1516
#else
1617
using PhysicsMaterialType = UnityEngine.PhysicMaterial;
1718
using PhysicsMaterialCombine = UnityEngine.PhysicMaterialCombine;
18-
using MCPForUnity.Runtime.Helpers;
1919
#endif
2020

2121
namespace MCPForUnity.Editor.Tools

MCPForUnity/Editor/Tools/ManageScene.cs

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System;
32
using System.Collections.Generic;
43
using System.IO;
@@ -599,11 +598,7 @@ private static object CaptureScreenshot(SceneCommand cmd)
599598
targetCamera = Camera.main;
600599
if (targetCamera == null)
601600
{
602-
#if UNITY_2022_2_OR_NEWER
603-
var allCams = UnityEngine.Object.FindObjectsByType<Camera>(FindObjectsSortMode.None);
604-
#else
605-
var allCams = UnityEngine.Object.FindObjectsOfType<Camera>();
606-
#endif
601+
var allCams = UnityFindObjectsCompat.FindAll<Camera>();
607602
targetCamera = allCams.Length > 0 ? allCams[0] : null;
608603
}
609604
}
@@ -641,11 +636,7 @@ private static object CaptureScreenshot(SceneCommand cmd)
641636

642637
// Default path: use ScreenCapture API if available, camera fallback otherwise
643638
bool screenCaptureAvailable = ScreenshotUtility.IsScreenCaptureModuleAvailable;
644-
#if UNITY_2022_2_OR_NEWER
645-
bool hasCameraFallback = Camera.main != null || UnityEngine.Object.FindObjectsByType<Camera>(FindObjectsSortMode.None).Length > 0;
646-
#else
647-
bool hasCameraFallback = Camera.main != null || UnityEngine.Object.FindObjectsOfType<Camera>().Length > 0;
648-
#endif
639+
bool hasCameraFallback = Camera.main != null || UnityFindObjectsCompat.FindAll<Camera>().Length > 0;
649640

650641
#if UNITY_2022_1_OR_NEWER
651642
if (!screenCaptureAvailable && !hasCameraFallback)
@@ -820,11 +811,7 @@ private static object CaptureSurroundBatch(SceneCommand cmd)
820811
// Default: calculate combined bounds of all renderers in the scene
821812
Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
822813
bool hasBounds = false;
823-
#if UNITY_2022_2_OR_NEWER
824-
var renderers = UnityEngine.Object.FindObjectsByType<Renderer>(FindObjectsSortMode.None);
825-
#else
826-
var renderers = UnityEngine.Object.FindObjectsOfType<Renderer>();
827-
#endif
814+
var renderers = UnityFindObjectsCompat.FindAll<Renderer>();
828815
foreach (var r in renderers)
829816
{
830817
if (r == null || !r.gameObject.activeInHierarchy) continue;
@@ -965,11 +952,7 @@ private static object CaptureOrbitBatch(SceneCommand cmd)
965952
// Default: calculate combined bounds of all renderers in the scene
966953
Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
967954
bool hasBounds = false;
968-
#if UNITY_2022_2_OR_NEWER
969-
var renderers = UnityEngine.Object.FindObjectsByType<Renderer>(FindObjectsSortMode.None);
970-
#else
971-
var renderers = UnityEngine.Object.FindObjectsOfType<Renderer>();
972-
#endif
955+
var renderers = UnityFindObjectsCompat.FindAll<Renderer>();
973956
foreach (var r in renderers)
974957
{
975958
if (r == null || !r.gameObject.activeInHierarchy) continue;
@@ -1217,11 +1200,7 @@ private static Camera ResolveCamera(string cameraRef)
12171200
}
12181201

12191202
// Search all cameras by name or path
1220-
#if UNITY_2022_2_OR_NEWER
1221-
var allCams = UnityEngine.Object.FindObjectsByType<Camera>(FindObjectsSortMode.None);
1222-
#else
1223-
var allCams = UnityEngine.Object.FindObjectsOfType<Camera>();
1224-
#endif
1203+
var allCams = UnityFindObjectsCompat.FindAll<Camera>();
12251204
foreach (var cam in allCams)
12261205
{
12271206
if (cam.name == cameraRef) return cam;
@@ -1273,11 +1252,7 @@ private static object FrameSceneView(SceneCommand cmd)
12731252
// Frame entire scene by computing combined bounds of all renderers
12741253
Bounds allBounds = new Bounds(Vector3.zero, Vector3.zero);
12751254
bool hasAny = false;
1276-
#if UNITY_2022_2_OR_NEWER
1277-
foreach (var r in UnityEngine.Object.FindObjectsByType<Renderer>(FindObjectsSortMode.None))
1278-
#else
1279-
foreach (var r in UnityEngine.Object.FindObjectsOfType<Renderer>())
1280-
#endif
1255+
foreach (var r in UnityFindObjectsCompat.FindAll<Renderer>())
12811256
{
12821257
if (r == null || !r.gameObject.activeInHierarchy) continue;
12831258
if (!hasAny) { allBounds = r.bounds; hasAny = true; }

MCPForUnity/Editor/Tools/Physics/PhysicsSimulationOps.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#pragma warning disable 0619
21
using System.Collections.Generic;
32
using MCPForUnity.Editor.Helpers;
43
using Newtonsoft.Json.Linq;
@@ -140,11 +139,7 @@ private static List<object> CollectActiveRigidbodies(string dimension)
140139

141140
if (dimension == "2d")
142141
{
143-
#if UNITY_2022_2_OR_NEWER
144-
var allRb2d = Object.FindObjectsByType<Rigidbody2D>(FindObjectsSortMode.None);
145-
#else
146-
var allRb2d = Object.FindObjectsOfType<Rigidbody2D>();
147-
#endif
142+
var allRb2d = UnityFindObjectsCompat.FindAll<Rigidbody2D>();
148143
foreach (var rb2d in allRb2d)
149144
{
150145
if (results.Count >= maxResults) break;
@@ -167,11 +162,7 @@ private static List<object> CollectActiveRigidbodies(string dimension)
167162
}
168163
else
169164
{
170-
#if UNITY_2022_2_OR_NEWER
171-
var allRb = Object.FindObjectsByType<Rigidbody>(FindObjectsSortMode.None);
172-
#else
173-
var allRb = Object.FindObjectsOfType<Rigidbody>();
174-
#endif
165+
var allRb = UnityFindObjectsCompat.FindAll<Rigidbody>();
175166
foreach (var rb in allRb)
176167
{
177168
if (results.Count >= maxResults) break;

0 commit comments

Comments
 (0)