private void Draw(SerializedProperty fieldsArray, List <Scene> openScenes, PropertyInfo inspectorModeInfo)
            {
                EditorGUILayout.PropertyField(fieldsArray, false);

                if (fieldsArray.isExpanded)
                {
                    GUI.enabled           = false;
                    fieldsArray.arraySize = EditorGUILayout.IntField(new GUIContent("Size"), fieldsArray.arraySize);
                    GUI.enabled           = true;

                    for (int arrayIndex = fieldsArray.arraySize - 1; arrayIndex >= 0; arrayIndex--)
                    {
                        string scenePath    = string.Empty;
                        var    sceneGuid    = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_sceneGuid");
                        var    usedInScript = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_usedInScript");
                        var    objectID     = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_objectID");
                        var    fieldName    = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_fieldName");

                        EditorGUI.indentLevel++;

                        EditorGUILayout.PropertyField(fieldsArray.GetArrayElementAtIndex(arrayIndex), new GUIContent("Element"), false);

                        if (fieldsArray.GetArrayElementAtIndex(arrayIndex).isExpanded)
                        {
                            if (sceneGuid.stringValue != "None")
                            {
                                scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid.stringValue);

                                if (openScenes.Any(s => s.path == scenePath))
                                {
                                    var  rootObjects = openScenes.Find(s => s.path == scenePath).GetRootGameObjects();
                                    bool found       = false;

                                    for (int rootObjectIndex = 0; rootObjectIndex < rootObjects.Length; rootObjectIndex++)
                                    {
                                        var components = rootObjects[rootObjectIndex].GetComponents((usedInScript.objectReferenceValue as MonoScript).GetClass()).ToList();

                                        components.AddRange(rootObjects[rootObjectIndex].GetComponentsInChildren((usedInScript.objectReferenceValue as MonoScript).GetClass()));

                                        for (int componentIndex = 0; componentIndex < components.Count; componentIndex++)
                                        {
                                            if (objectID.intValue == components[componentIndex].GetLocalID())
                                            {
                                                GUI.enabled = false;

                                                EditorGUILayout.TextField(new GUIContent("FieldName"), fieldName.stringValue);

                                                EditorGUILayout.ObjectField(new GUIContent("Reference"), components[componentIndex],
                                                                            (usedInScript.objectReferenceValue as MonoScript).GetClass(), true);

                                                GUI.enabled = true;
                                                found       = true;
                                                break;
                                            }
                                        }

                                        if (found)
                                        {
                                            break;
                                        }
                                    }
                                }
                                else
                                {
                                    GUI.enabled = false;

                                    EditorGUILayout.TextField(new GUIContent("FieldName"), fieldName.stringValue);

                                    var sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);

                                    if (sceneAsset)
                                    {
                                        EditorGUILayout.ObjectField(new GUIContent("Reference"), sceneAsset, typeof(SceneAsset), true);
                                    }

                                    GUI.enabled = true;
                                }
                            }
                            else
                            {
                                UnityEngine.Object obj = UnityEngineObjectExtensions.GetObjectByInstanceID(objectID.intValue);

                                if (obj)
                                {
                                    GUI.enabled = false;
                                    EditorGUILayout.TextField(new GUIContent("FieldName"), fieldName.stringValue);
                                    EditorGUILayout.ObjectField(new GUIContent("Reference"), obj, typeof(UnityEngine.Object), true);
                                    GUI.enabled = true;
                                }
                            }
                        }

                        EditorGUI.indentLevel--;
                    }
                }
            }
            private void CheckForRemove(SerializedProperty fieldsArray, List <Scene> openScenes, List <int> indexesToClear, PropertyInfo inspectorModeInfo, ref bool removedSomething)
            {
                for (int arrayIndex = fieldsArray.arraySize - 1; arrayIndex >= 0; arrayIndex--)
                {
                    string scenePath    = string.Empty;
                    var    sceneGuid    = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_sceneGuid");
                    var    usedInScript = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_usedInScript");
                    var    objectID     = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_objectID");
                    var    fieldName    = fieldsArray.GetArrayElementAtIndex(arrayIndex).FindPropertyRelative("_fieldName");

                    bool exists = false;

                    if (sceneGuid.stringValue != "None")
                    {
                        scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid.stringValue);

                        if (openScenes.Any(s => s.path == scenePath))
                        {
                            var rootObjects = openScenes.Find(s => s.path == scenePath).GetRootGameObjects();

                            for (int rootObjectIndex = 0; rootObjectIndex < rootObjects.Length; rootObjectIndex++)
                            {
                                var components = rootObjects[rootObjectIndex].GetComponents((usedInScript.objectReferenceValue as MonoScript).GetClass()).ToList();

                                components.AddRange(rootObjects[rootObjectIndex].GetComponentsInChildren((usedInScript.objectReferenceValue as MonoScript).GetClass()));

                                for (int componentIndex = 0; componentIndex < components.Count; componentIndex++)
                                {
                                    if (objectID.intValue == components[componentIndex].GetLocalID())
                                    {
                                        exists = true;
                                        break;
                                    }
                                }

                                if (exists)
                                {
                                    break;
                                }
                            }
                        }
                        else
                        {
                            exists = AssetDatabase.LoadAssetAtPath <SceneAsset>(scenePath);
                        }
                    }
                    else
                    {
                        exists = UnityEngineObjectExtensions.GetObjectByInstanceID(objectID.intValue);
                    }

                    if (!exists)
                    {
                        indexesToClear.Add(arrayIndex);
                    }
                }

                List <int> indexesInAllFieldsToClear = new List <int>();
                var        allFieldsProperty         = _serializedTarget.FindProperty("_allFields");

                for (int i = 0; i < indexesToClear.Count; i++)
                {
                    if (allFieldsProperty.FindInArray(s => s.FindPropertyRelative("_fieldID").stringValue ==
                                                      fieldsArray.GetArrayElementAtIndex(indexesToClear[i]).FindPropertyRelative("_fieldID").stringValue, out int indexToDelete) != null)
                    {
                        indexesInAllFieldsToClear.Add(indexToDelete);
                    }

                    removedSomething = true;
                    fieldsArray.DeleteArrayElementAtIndex(indexesToClear[i]);
                }

                indexesInAllFieldsToClear.OrderByDescending(i => i);

                for (int i = 0; i < indexesInAllFieldsToClear.Count; i++)
                {
                    allFieldsProperty.DeleteArrayElementAtIndex(indexesInAllFieldsToClear[i]);
                }

                indexesToClear.Clear();
            }