找不到类型或命名空间名称“描述”

时间:2017-11-08 07:27:48

标签: c# unity3d uwp

我目前正在为UWP开发MR应用程序。我正在unity3d中构建应用程序(在5.5.2和2017.1.2中测试),当我在团结内按播放时,一切正常,没有编译错误,但是当我去构建应用程序时,我得到错误Assets\Script\DMEWebRequest.cs(35,10): error CS0246: The type or namespace name 'DescriptionAttribute' could not be found (are you missing a using directive or an assembly reference?)Assets\Script\DMEWebRequest.cs(35,10): error CS0246: The type or namespace name 'Description' could not be found (are you missing a using directive or an assembly reference?)

据我所知,DescriptionAttribute是System.ComponentModel

的一部分

我的C#脚本中的代码段

using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;


//Makes a dropdown menu in the inspector
public enum EGU {
    [Description("")] None,
    [Description("ºC")] DegreesCelcius,
    [Description("kW")] KiloWatts,
    [Description("kW/h")] KiloWattsPerHour,
    [Description("MW")] MegaWatts,
    [Description("MW/h")] MegaWattsPerHour,
    [Description("M³")] CubicMeters,
    [Description("M³/h")] CubicMetersPerHour,
    [Description("%")] Procentage,
    [Description("º")] Degrees,
    [Description("l/s")] LiterPerSecond,
    [Description("cm")] CentiMeters,
    [Description("m")] Meters,
    [Description("mg/l")] MiliGramPerLiter,
    [Description("g/l")] GramPerLiter
    }

希望有人可以帮我弄清楚我缺少的指令或参考。

/ T

2 个答案:

答案 0 :(得分:4)

构建PC,Mac和Mac时,您的代码应该可以正常工作和Linux Standalone。将平台切换到通用Windows平台时,它不起作用,因为System.ComponentModel.Description使用UWP不支持的DescriptionAttribute。 UWP删除了对许多.NET API的支持。在制作UWP应用程序时,您应该记住一件事。

答案 1 :(得分:0)

它与IL2CPP一起用作脚本后端。如果您需要Unity 2018 LTS中已弃用的.NET脚本后端(已在2019中删除),则可以尝试从Mono或反编译的代码中添加DescriptionAttribute.cs,如@Programmer建议。在某些情况下可能会起作用,但就我而言,我遇到了更多错误。

最后,当我尝试为UWP(.NET)的ARSubsystem软件包进行编译时,我放弃了,这是同一项目的iOS / Android版本所需要的。相反,我根据平台操纵软件包清单以排除/包括软件包。有InitializeOnLoad attributeIPreprocessBuildWithReport界面之类的几种方法。