You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
/// <summary>
/// Class for the Hide in Prefab Attribute
/// </summary>
/// <remarks>
/// Class is empty because we have no parameters needed for this attribute
/// </remarks>
public class HideInPrefabAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
/// <summary>
/// Override for the Property Drawer which draws the GUI
/// </summary>
[CustomPropertyDrawer(typeof(HideInPrefabAttribute))]
public class HideInPrefabDrawer : PropertyDrawer
{
//On GUI override
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
//get the type of the object this property is attched to
PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
//if the type isn't a perfab then draw the property
if (type != PrefabType.Prefab)
EditorGUI.PropertyField(position, property, label);
}
//Override GetPropertyHeight
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
//get the type of the object this property is attched to
PrefabType type = PrefabUtility.GetPrefabType(property.serializedObject.targetObject);
//if type prefab return zero height (because it won't be drawn)
if (type == PrefabType.Prefab)
return 0;
//else return normal height
return base.GetPropertyHeight(property, label);
}
}
#endif