Skip to content

Commit

Permalink
Make use of FindObjectsByType consistent. (#328)
Browse files Browse the repository at this point in the history
* Make use of FindObjectsByType consistent. Anything beyond 2021.3 supports the ByType API.

* Update AudioLinkEditor.cs

---------

Co-authored-by: hill <hill@hilll.dev>
  • Loading branch information
techanon and float3 authored Dec 22, 2024
1 parent de4e2cf commit 5dae16f
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using System.Reflection;

#if UDONSHARP
using UdonSharp;
using UdonSharpEditor;
using BehaviourType = UdonSharpBehaviour;
using BehaviourType = UdonSharp.UdonSharpBehaviour;
#else
using BehaviourType = MonoBehaviour;
#endif
Expand Down Expand Up @@ -88,11 +87,12 @@ public void LinkAll()
public static void LinkAll(AudioLink target)
{
BehaviourType[] allBehaviours = FindObjectsByType<BehaviourType>(
#if UNITY_6000_0_OR_NEWER
#if UNITY_2021_3_OR_NEWER
FindObjectsInactive.Include, FindObjectsSortMode.InstanceID
#endif
#else
true
#endif
);

// this handles all reasonable cases of referencing audiolink
// (it doesn't handle referencing it multiple times in one monobehaviour, or referencing it as it's Base type)
foreach (BehaviourType behaviour in allBehaviours)
Expand All @@ -110,6 +110,7 @@ public static void LinkAll(AudioLink target)
}
}
}

if (fieldInfo != null && fieldInfo.FieldType == typeof(AudioLink))
{
fieldInfo.SetValue(behaviour, target);
Expand Down

0 comments on commit 5dae16f

Please sign in to comment.