Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 463
chore: update usage of deprecated FindObjectsByType<T>(FindObjectsSortMode) and enum FindObjectSortMode#3857
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
b5bff02793badec8f54c9a5719dbfec5e65db390f59a5d04ba5983f7b52e9071f7e70c01dd8c0b53de7a1a5bb4af5f5cf29939aa65b4f42dc2211568cf8de6ad9aafe3719d79929dba53db3a40File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #if NGO_FINDOBJECTS_NOSORTING | ||
| using System; | ||
| #endif | ||
| using System.Runtime.CompilerServices; | ||
| using Object = UnityEngine.Object; | ||
| namespace Unity.Netcode | ||
| { | ||
| /// <summary> | ||
| /// Helper class to handle the variations of FindObjectsByType. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// It is intentional that we do not include the UnityEngine namespace in order to avoid | ||
| /// over-complicatd define wrapping between versions that do or don't support FindObjectsSortMode. | ||
| /// </remarks> | ||
| internal static class FindObjects | ||
| { | ||
| /// <summary> | ||
| /// Replaces <see cref="Object.FindObjectsByType"/> to have one place where these changes are applied. | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="includeInactive">When true, inactive objects will be included.</param> | ||
| /// <param name="orderByIdentifier">When true, the array returned will be sorted by identifier.</param> | ||
| /// <returns>Resulst as an <see cref="Array"/> of type T</returns> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static T[] ByType<T>(bool includeInactive = false, bool orderByIdentifier = false) where T : Object | ||
| { | ||
| var inactive = includeInactive ? UnityEngine.FindObjectsInactive.Include : UnityEngine.FindObjectsInactive.Exclude; | ||
| #if NGO_FINDOBJECTS_NOSORTING | ||
| var results = Object.FindObjectsByType<T>(inactive); | ||
| if (orderByIdentifier) | ||
| { | ||
| Array.Sort(results, (a, b) => a.GetEntityId().CompareTo(b.GetEntityId())); | ||
| } | ||
| #else | ||
| var results = Object.FindObjectsByType<T>(inactive, orderByIdentifier ? UnityEngine.FindObjectsSortMode.InstanceID : UnityEngine.FindObjectsSortMode.None); | ||
| #endif | ||
| return results; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,6 +87,16 @@ | ||
| "name": "Unity", | ||
| "expression": "6000.5.0a1", | ||
| "define": "SCENE_MANAGEMENT_SCENE_HANDLE_MUST_USE_ULONG" | ||
| }, | ||
| { | ||
| "name": "Unity", | ||
| "expression": "[6000.4.0b5,6000.5.0a1)", | ||
| "define": "NGO_FINDOBJECTS_NOSORTING" | ||
| }, | ||
| { | ||
| "name": "Unity", | ||
| "expression": "6000.5.0a7", | ||
| "define": "NGO_FINDOBJECTS_NOSORTING" | ||
NoelStephensUnity marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| ], | ||
| "noEngineReferences": false | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.