一、报错原因分析
错误 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.");
}
}
}
}