Skip to content

Commit

Permalink
make behaviour handling code more concise (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
float3 authored Dec 15, 2024
1 parent da57703 commit 88a8496
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Packages/com.llealloo.audiolink/Editor/Scripts/AudioLinkEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#if UDONSHARP
using UdonSharp;
using UdonSharpEditor;
using BehaviourType = UdonSharpBehaviour;
#else
using BehaviourType = MonoBehaviour;
#endif

using UnityEditor;
Expand Down Expand Up @@ -84,21 +87,15 @@ public void LinkAll()

public static void LinkAll(AudioLink target)
{
BehaviourType[] allBehaviours = FindObjectsByType<BehaviourType>(
#if UNITY_6000_0_OR_NEWER
#if UDONSHARP
MonoBehaviour[] allBehaviours = FindObjectsByType<UdonSharpBehaviour>(FindObjectsInactive.Include, FindObjectsSortMode.InstanceID);
#endif
MonoBehaviour[] allBehaviours = FindObjectsByType<MonoBehaviour>(FindObjectsInactive.Include, FindObjectsSortMode.InstanceID);
#else
#if UDONSHARP
UdonSharpBehaviour[] allBehaviours = FindObjectsOfType<UdonSharpBehaviour>();
#else
MonoBehaviour[] allBehaviours = FindObjectsOfType<MonoBehaviour>();
#endif
#endif
FindObjectsInactive.Include, FindObjectsSortMode.InstanceID
#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 (var behaviour in allBehaviours)
foreach (BehaviourType behaviour in allBehaviours)
{
FieldInfo fieldInfo = behaviour.GetType().GetField("audioLink");
// in case the field isn't called "audioLink"
Expand Down

0 comments on commit 88a8496

Please sign in to comment.