
propertydrawer에서 수정 할수 있는 방법으로 수정 하였습니다.
#if UNITY_EDITOR
namespace UnityEditor
{
[CustomPropertyDrawer(typeof(GetComponent), true)]
public class GetComponentDrawer : PropertyDrawer
{
// Necessary since some properties tend to collapse smaller than their content
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
// Draw a disabled property field
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var target = property.serializedObject.targetObject as MonoBehaviour;
property.serializedObject.Update();
GUI.enabled = !Application.isPlaying && ((GetComponent)attribute).runtimeOnly;
EditorGUI.PropertyField(position, property, label, true);
object value = (object)target.GetComponent(fieldInfo.FieldType);
fieldInfo.SetValue(target, value);
property.serializedObject.ApplyModifiedProperties();
GUI.enabled = true;
}
}
}
#endif
[AttributeUsage(AttributeTargets.Field)]
public class GetComponent : PropertyAttribute
{
public readonly bool runtimeOnly;
public GetComponent(bool runtimeOnly = false)
{
this.runtimeOnly = runtimeOnly;
}
}