包括只读,滑条,多选框
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
/****************************************************
作者:cg
功能:
*****************************************************/
#region 只读
public class MyReadOnlyAttribute:PropertyAttribute
{
}
[CustomPropertyDrawer(typeof(MyReadOnlyAttribute))]
public class MyReadOnlyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return base.GetPropertyHeight(property, label);
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false;
EditorGUI.PropertyField(position, property, label,true);
GUI.enabled = true;
}
}
#endregion
#region 滑条
public class MyRangeAttribute : PropertyAttribute
{
public float Min;//最小值
public float Max;//最大值
public MyRangeAttribute(float min, float

本文介绍如何使用Unity定制属性 drawers,包括实现只读属性、滑动条控件和多选框功能,提升UI自定义性。
最低0.47元/天 解锁文章
1194

被折叠的 条评论
为什么被折叠?



