Write me a Unity editor script that lists all the AudioSources in the scene and has a way to play them. Please comment the code, including the llm model used to generate this.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here is a sample script that lists all the AudioSources in the scene and has a way to play them:
code
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class AudioSourceSelector : EditorWindow
{
public static AudioSourceSelector current;
[MenuItem("Tools/Audio Source Selector")]
static void ShowWindow()
{
if (current != null)
{
current.Close();
}
current = new AudioSourceSelector();
current.Show();
}
private void OnSelectAudioSource()
{
// Clear the audio sources list
audioSourceList.Clear();
// Get all the AudioSources in the scene
AudioSource[] audioSources = FindObjectsOfType<AudioSource>();
// Add all the AudioSources to the list
foreach (AudioSource audioSource in audioSources)
{
audioSourceList.Add(audioSource);
}
}
private void OnPlayAudioSource()
{
// Select the currently highlighted audio source
Selection.activeGameObject = audioSourceList[currentSelection];
// Play the audio source
audioSourceList[currentSelection].Play();
}
[MenuItem("Tools/Audio Source Selector")]
static void ShowWindow()
{
if (current != null)
{
current.Close();
}
current = new AudioSourceSelector();
current.Show();
}
}
This script uses the EditorWindow class to create a custom Unity editor window that allows the user to select an audio source and play it. The ShowWindow() function is used to show the window and the Show() function is used to close it.
The OnSelectAudioSource() function is called when the user selects an audio source from the list. It gets all the AudioSources in the scene, adds them to the audioSourceList list, and clears the list.
The OnPlayAudioSource() function is called when the user clicks the "Play" button. It selects the currently highlighted audio source, plays it, and updates the currentSelection variable to reflect the new selection.
User
Write me a Unity editor script that lists all the AudioSources in the scene and has a way to play them. Please comment the code, including the llm model used to generate this. Return only code, no explanation.
Assistant
code
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class AudioSourceSelector : EditorWindow
{
public static AudioSourceSelector current;
[MenuItem("Tools/Audio Source Selector")]
static void ShowWindow()
{
if (current != null)
{
current.Close();
}
current = new AudioSourceSelector();
current.Show();
}
private void OnSelectAudioSource()
{
// Clear the audio sources list
audioSourceList.Clear();
// Get all the AudioSources in the scene
AudioSource[] audioSources = FindObjectsOfType<AudioSource>();
// Add all the AudioSources to the list
foreach (AudioSource audioSource in audioSources)
{
audioSourceList.Add(audioSource);
}
}
private void OnPlayAudioSource()
{
// Select the currently highlighted audio source
Selection.activeGameObject = audioSourceList[currentSelection];
// Play the audio source
audioSourceList[currentSelection].Play();
}
[MenuItem("Tools/Audio Source Selector")]
static void ShowWindow()
{
if (current != null)
{
current.Close();
}
current = new AudioSourceSelector();
current.Show();
}
}