Improve diapason
This commit is contained in:
@@ -1,181 +0,0 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using Unheimlich.Audio;
|
||||
|
||||
namespace Unheimlich.Editor
|
||||
{
|
||||
public class AudioListenableBatchSetup : EditorWindow
|
||||
{
|
||||
private AudioEmitterType _selectedType = AudioEmitterType.Wall;
|
||||
private LayerMask _targetLayer;
|
||||
private bool _overwriteExisting = false;
|
||||
|
||||
[MenuItem("Tools/Unheimlich/Audio Listenable Batch Setup")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
GetWindow<AudioListenableBatchSetup>("Audio Batch Setup");
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
GUILayout.Label("Batch Audio Listenable Setup", EditorStyles.boldLabel);
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
EditorGUILayout.HelpBox(
|
||||
"This tool adds AudioListenable components to all selected GameObjects in the scene.",
|
||||
MessageType.Info
|
||||
);
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
_selectedType = (AudioEmitterType)EditorGUILayout.EnumPopup("Emitter Type", _selectedType);
|
||||
_overwriteExisting = EditorGUILayout.Toggle("Overwrite Existing", _overwriteExisting);
|
||||
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
if (GUILayout.Button("Add to Selected Objects", GUILayout.Height(30)))
|
||||
{
|
||||
AddToSelectedObjects();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
EditorGUILayout.LabelField("Quick Presets", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Setup All Walls in Scene"))
|
||||
{
|
||||
SetupObjectsByName("wall", AudioEmitterType.Wall);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Setup All Doors in Scene"))
|
||||
{
|
||||
SetupObjectsByName("door", AudioEmitterType.Wood);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddToSelectedObjects()
|
||||
{
|
||||
GameObject[] selectedObjects = Selection.gameObjects;
|
||||
|
||||
if (selectedObjects.Length == 0)
|
||||
{
|
||||
EditorUtility.DisplayDialog("No Selection", "Please select at least one GameObject in the scene.", "OK");
|
||||
return;
|
||||
}
|
||||
|
||||
int addedCount = 0;
|
||||
int skippedCount = 0;
|
||||
|
||||
foreach (GameObject obj in selectedObjects)
|
||||
{
|
||||
AudioListenable existing = obj.GetComponent<AudioListenable>();
|
||||
|
||||
if (existing != null && !_overwriteExisting)
|
||||
{
|
||||
skippedCount++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (existing == null)
|
||||
{
|
||||
Undo.AddComponent<AudioListenable>(obj);
|
||||
existing = obj.GetComponent<AudioListenable>();
|
||||
}
|
||||
|
||||
ConfigureListenable(existing, _selectedType);
|
||||
addedCount++;
|
||||
}
|
||||
|
||||
EditorUtility.DisplayDialog(
|
||||
"Batch Setup Complete",
|
||||
$"Added/Updated: {addedCount}\nSkipped: {skippedCount}",
|
||||
"OK"
|
||||
);
|
||||
}
|
||||
|
||||
private void SetupObjectsByName(string nameContains, AudioEmitterType type)
|
||||
{
|
||||
GameObject[] allObjects = FindObjectsByType<GameObject>(FindObjectsSortMode.None);
|
||||
int count = 0;
|
||||
|
||||
foreach (GameObject obj in allObjects)
|
||||
{
|
||||
if (obj.name.ToLower().Contains(nameContains.ToLower()))
|
||||
{
|
||||
AudioListenable existing = obj.GetComponent<AudioListenable>();
|
||||
|
||||
if (existing == null)
|
||||
{
|
||||
Undo.AddComponent<AudioListenable>(obj);
|
||||
existing = obj.GetComponent<AudioListenable>();
|
||||
}
|
||||
|
||||
ConfigureListenable(existing, type);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
EditorUtility.DisplayDialog(
|
||||
"Setup Complete",
|
||||
$"Configured {count} objects containing '{nameContains}' as {type}",
|
||||
"OK"
|
||||
);
|
||||
}
|
||||
|
||||
private void ConfigureListenable(AudioListenable listenable, AudioEmitterType type)
|
||||
{
|
||||
SerializedObject so = new SerializedObject(listenable);
|
||||
|
||||
so.FindProperty("_emitterType").enumValueIndex = (int)type;
|
||||
so.FindProperty("_useProceduralAudio").boolValue = true;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case AudioEmitterType.Wall:
|
||||
so.FindProperty("_baseFrequency").floatValue = 200f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 20f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.2f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.4f;
|
||||
break;
|
||||
|
||||
case AudioEmitterType.Metal:
|
||||
so.FindProperty("_baseFrequency").floatValue = 800f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 100f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.4f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.7f;
|
||||
break;
|
||||
|
||||
case AudioEmitterType.Wood:
|
||||
so.FindProperty("_baseFrequency").floatValue = 300f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 50f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.3f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.6f;
|
||||
break;
|
||||
|
||||
case AudioEmitterType.Glass:
|
||||
so.FindProperty("_baseFrequency").floatValue = 1200f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 150f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.3f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.6f;
|
||||
break;
|
||||
|
||||
case AudioEmitterType.Stone:
|
||||
so.FindProperty("_baseFrequency").floatValue = 250f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 30f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.3f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.5f;
|
||||
break;
|
||||
|
||||
case AudioEmitterType.Mechanical:
|
||||
so.FindProperty("_baseFrequency").floatValue = 500f;
|
||||
so.FindProperty("_frequencyVariation").floatValue = 80f;
|
||||
so.FindProperty("_volumeMin").floatValue = 0.4f;
|
||||
so.FindProperty("_volumeMax").floatValue = 0.7f;
|
||||
break;
|
||||
}
|
||||
|
||||
so.ApplyModifiedProperties();
|
||||
EditorUtility.SetDirty(listenable);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d813501fc2b446419db87d892d79ce3
|
||||
Reference in New Issue
Block a user