[英]UNITY error CS0246: The type or namespace name `MenuItem' could not be found. Are you missing an assembly reference?
For some reason i keep getting a referencing error for:出于某种原因,我不断收到以下引用错误:
(8,6): error CS0246: The type or namespace name `MenuItem' could not be found. (8,6):错误 CS0246:找不到类型或命名空间名称“MenuItem”。 Are you missing an assembly reference?
您是否缺少程序集参考?
(24,26): error CS0246: The type or namespace name `SerializedObject' could not be found. (24,26):错误 CS0246:找不到类型或命名空间名称“SerializedObject”。 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;
}
}
}
This might happen because you didn't put this script inside an 'Editor' folder.这可能是因为您没有将此脚本放在“编辑器”文件夹中。 It's one of these Special Folders .
它是这些特殊文件夹之一。
You have to put your script inside your "Editor" folder.您必须将脚本放在“编辑器”文件夹中。 "Assets/Editor/AudioSourceReplacement.cs" should do the trick.
“Assets/Editor/AudioSourceReplacement.cs”应该可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.