using UnityEditor;
using UnityEngine;

namespace VOID.Editor.PropertyDrawers
{
    [CustomPropertyDrawer(typeof(SceneReference))]
    public class SceneFieldPropertyDrawer : PropertyDrawer
    {
        public override void OnGUI(Rect rect, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(rect, GUIContent.none, property);
            
            var sceneAsset = property.FindPropertyRelative("_sceneAsset");
            var scenePath = property.FindPropertyRelative("_scenePath");
            
            // Label + Field
            rect = EditorGUI.PrefixLabel(rect, GUIUtility.GetControlID(FocusType.Passive), label);
            var obj = EditorGUI.ObjectField(rect, sceneAsset.objectReferenceValue, typeof(SceneAsset), false);

            // Value setter
            sceneAsset.objectReferenceValue = obj;
            scenePath.stringValue = obj ? AssetDatabase.GetAssetPath(obj) : "";
            
            EditorGUI.EndProperty();
        }
    }
}
    
