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

make behaviour handling code more concise #327

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
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
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
Loading