简体   繁体   English

UNITY 错误 CS0246:找不到类型或命名空间名称“MenuItem”。 您是否缺少程序集参考?

[英]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.

相关问题 错误 CS0246:找不到类型或命名空间名称“CsvHelper” - error CS0246: The type or namespace name 'CsvHelper' could not be found 错误CS0246:找不到类型或名称空间名称&#39;WebDriverWait&#39;? - Error CS0246: The type or namespace name 'WebDriverWait' could not be found? Visual Studio 2017 构建到 hololens 错误 CS0246“找不到类型或命名空间名称 &#39;UnityPlayer&#39;” - Visual studio 2017 building to hololens error CS0246 "The type or namespace name 'UnityPlayer' Could not be found" 易失性“错误CS0246无法找到类型或命名空间名称&#39;MyProject&#39;” - The volatile “Error CS0246 The type or namespace name 'MyProject' could not be found” 找不到类型或名称空间名称。 您是否缺少using指令或程序集引用? - The type or namespace name could not be found. Are you missing a using directive or an assembly reference? 错误1找不到类型或名称空间名称&#39;FPSTimer&#39;(您是否缺少using指令或程序集引用?) - Error 1 The type or namespace name 'FPSTimer' could not be found (are you missing a using directive or an assembly reference?) 在全局命名空间中找不到类型或命名空间名称“”Namespace“(您是否缺少程序集引用?) - The type or namespace name '“Namespace”' could not be found in the global namespace (are you missing an assembly reference?) 导入 UnityEngine.InputSystem 的问题。 找不到错误 CS0246 类型或命名空间 - issue importing UnityEngine.InputSystem. Error CS0246 type or namespace not found 错误 CS0234 命名空间“Microsoft”中不存在类型或命名空间名称“Reporting”(您是否缺少程序集引用?) - Error CS0234 The type or namespace name 'Reporting' does not exist in the namespace 'Microsoft' (Are you missing an assembly reference?) 找不到Visual Studio 2015的构建类型或名称空间cs0246 - visual studio 2015 build type or name space could not be found cs0246
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM