如何修复(29,20):错误CS1519:类,结构或接口成员声明中的无效令牌'}'

时间:2019-04-15 10:38:36

标签: c# unity3d

无论我做什么,我都无法编译

我尝试了所有可能的更改 帮助我进行编译,对我来说代码很完美,但仍然无法正常工作

 [System.Serializable]
public class UnderWaterParameters {
    [Header("The following parameters apply for underwater only!")]
    [Space(5)]
    public float fogDensity = 0.1f;
    public Color fogColor;
#if UNITY_POST_PROCESSING_STACK_V1 && AQUAS_PRESENT
    [Space(5)]
    [Header("Post Processing Profiles (Must NOT be empty!)")]
    [Space(5)]
    public PostProcessingProfile underwaterProfile;
    public PostProcessingProfile defaultProfile;
#endif

#if UNITY_POST_PROCESSING_STACK_V2 && AQUAS_PRESENT
    [Space(5)]
    [Header("Post Processing Profiles (Must NOT be empty!)")]
    [Space(5)]
    public PostProcessingProfile underwaterProfile;
    public PostProcessingProfile defaultProfile;
#endif
}

1 个答案:

答案 0 :(得分:2)

Attribute(这就是您使用[...]定义的内容)提供有关类或类成员的元数据。换句话说,它不能完全站立,它必须在某些符号之前。这就是为什么它不能编译的原因:

#if UNITY_POST_PROCESSING_STACK_V2 && AQUAS_PRESENT
    [Space(5)]
    [Header("Post Processing Profiles (Must NOT be empty!)")]
    [Space(5)] } <-- attribute must preceed a member or class
#endif

在我看来,您想要的只是基于两个条件中哪个适用的不同属性,因此您应该仅将应该不同的那些行包装到#if #elif中,不要将那些不常见的行包装 strong>。

[System.Serializable]
public class UnderWaterParameters {
    [Header("The following parameters apply for underwater only!")]
    [Space(5)]
    public float fogDensity = 0.1f;
    public Color fogColor;
#if UNITY_POST_PROCESSING_STACK_V1 && AQUAS_PRESENT
    [Space(5)]
    [Header("Post Processing Profiles (Must NOT be empty!)")]
    [Space(5)]
#elif UNITY_POST_PROCESSING_STACK_V2 && AQUAS_PRESENT
    [Space(5)]
    [Header("Post Processing Profiles (Must NOT be empty!)")]
    [Space(5)] }
#endif
    public PostProcessingProfile underwaterProfile;
    public PostProcessingProfile defaultProfile;
}

上面的内容当然没有多大意义,因为在两种情况下都应用了完全相同的属性。但这对我来说是另一个问题。

另请参阅MSDN上的文档:https://docs.microsoft.com/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-elif