For some reason i keep getting a referencing error for:
(8,6): error CS0246: The type or namespace name `MenuItem' could not be found. Are you missing an assembly reference?
(24,26): error CS0246: The type or namespace name `SerializedObject' could not be found. Are you missing an assembly reference?
Code:
using UnityEngine;
using UnityEditor;
using System.Collections;
public class AudioSourceReplacement {
[MenuItem("FMOD Tools/Replace Audio Emitters")]
private static void ReplaceEmitters()
{
AudioSource[] audioSources = Object.FindObjectsOfType<AudioSource>();
foreach (AudioSource audioSource in audioSources)
{
if (audioSource.clip == null)
{
continue;
}
string eventName = audioSource.clip.name;
string eventPath = (audioSource.spatialBlend < 0.5f ? "event:/Ambience/2D/" : "event:/Ambience/3D/") eventName;
FMODUnity.StudioEventEmitter emitter = audioSource.gameObject.AddComponent<FMODUnity.StudioEventEmitter>();
emitter.Event = eventPath;
var so = new SerializedObject(emitter);
so.ApplyModifiedProperties();
}
for (int i=0;i<audioSources.Length;i )
{
GameObject.DestroyImmediate(audioSources[i]);
}
}
[MenuItem("FMOD Tools/Force All Emitters Play On Start")]
private static void EmittersPlayOnStart()
{
FMODUnity.StudioEventEmitter[] audioSources = Object.FindObjectsOfType<FMODUnity.StudioEventEmitter>();
foreach (FMODUnity.StudioEventEmitter audioSource in audioSources)
{
audioSource.PlayEvent = FMODUnity.EmitterGameEvent.ObjectStart;
}
}
}
CodePudding user response:
This might happen because you didn't put this script inside an 'Editor' folder. It's one of these Special Folders.
CodePudding user response:
You have to put your script inside your "Editor" folder. "Assets/Editor/AudioSourceReplacement.cs" should do the trick.