using UnityEditor;
using System.Reflection;

namespace AssetBank.Editor.SceneSchema.Internal
{
    public static class EditorUtilities
    {
        public static int GetLocalFileID(UnityEngine.Object obj)
        {
            if (obj == null) return 0;

            var inspectorModeInfo =
                typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);

            var serializedObject = new SerializedObject(obj);
            if (inspectorModeInfo != null) inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);

            var localIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile");
            return localIdProp.intValue;
        }
    }
}
