Created
November 9, 2021 02:02
-
-
Save PhantasmicDev/4a91afa15c5c0786ec18b46566661bfa to your computer and use it in GitHub Desktop.
An attribute that allows referencing only prefabs in the editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
#endif | |
[AttributeUsage(AttributeTargets.Field)] | |
public class PrefabOnlyAttribute : PropertyAttribute | |
{ | |
} | |
#if UNITY_EDITOR | |
[CustomPropertyDrawer(typeof(PrefabOnlyAttribute))] | |
public class PrefabOnlyDrawer : PropertyDrawer | |
{ | |
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) | |
{ | |
property.objectReferenceValue = EditorGUI.ObjectField(position, label, property.objectReferenceValue, fieldInfo.FieldType, false); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment