Unity中出现“MinAttribute”错误如何解决?我来教你!

一、报错原因分析

错误  CS0104   “MinAttribute”是“UnityEngine.PostProcessing.MinAttribute”和“UnityEngine.MinAttribute”之间的不明确的引用    

这是一种很常见的Unity报错信息提示:

具体原因是因为:MinAttribute在UnityEngine和UnityEngine.PostProcessing中都有定义,导致命名冲突。一般是因为版本更换问题导致的这一情况出现,可以通过明确指定命名空间来解决这个问题。

二、报错问题解决

做如下代码块替换即可:

using UnityEngine;
using UnityEngine.PostProcessing;
using UnityEditor;

namespace UnityEditor.PostProcessing
{
    [CustomPropertyDrawer(typeof(UnityEngine.PostProcessing.MinAttribute))] // 指定完整命名空间
    sealed class MinDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var attribute = (UnityEngine.PostProcessing.MinAttribute)base.attribute; // 指定完整命名空间

            if (property.propertyType == SerializedPropertyType.Integer)
            {
                int v = EditorGUI.IntField(position, label, property.intValue);
                property.intValue = (int)Mathf.Max(v, attribute.min);
            }
            else if (property.propertyType == SerializedPropertyType.Float)
            {
                float v = EditorGUI.FloatField(position, label, property.floatValue);
                property.floatValue = Mathf.Max(v, attribute.min);
            }
            else
            {
                EditorGUI.LabelField(position, label.text, "Use Min with float or int.");
            }
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值