From: How to get the Local Identifier In File for scene objects
PropertyInfo inspectorModeInfo =
typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
SerializedObject serializedObject = new SerializedObject(unityObject);
inspectorModeInfo.SetValue(serializedObject, InspectorMode.Debug, null);
SerializedProperty localIdProp =
serializedObject.FindProperty("m_LocalIdentfierInFile"); //note the misspelling!
int localId = localIdProp.intValue;