public void CacheRecordedComponents()
        {
            SerializedObject so = new SerializedObject(this);

            so.FindProperty("_cachedInstance").intValue = GetInstanceID();

            SerializedProperty spIds     = so.FindProperty("_cachedComponentIds");
            SerializedProperty spObjects = so.FindProperty("_cachedComponentObjects");

            spIds.ClearArray();
            spObjects.ClearArray();

            // Add GameObject for name/ active ect.
            spIds.InsertArrayElementAtIndex(0);
            spIds.GetArrayElementAtIndex(0).intValue = gameObject.GetInstanceID();
            spObjects.InsertArrayElementAtIndex(0);
            spObjects.GetArrayElementAtIndex(0).objectReferenceValue = gameObject;

            foreach (Object component in PlayModeEdit_System.PlayModeEditComponents(this, includePlayModeEdit: false, recordedComponentsOnly: true))
            {
                int i = spIds.arraySize;
                spIds.InsertArrayElementAtIndex(i);
                spIds.GetArrayElementAtIndex(i).intValue = component.GetInstanceID();
                spObjects.InsertArrayElementAtIndex(i);
                spObjects.GetArrayElementAtIndex(i).objectReferenceValue = component;
            }

            so.ApplyModifiedPropertiesWithoutUndo();
        }
 private static void LogPlayModeState(PlayModeStateChange state)
 {
     if (state == PlayModeStateChange.EnteredPlayMode)
     {
         _isRecording = false;
         SceneView.onSceneGUIDelegate += OnScene;
     }
     else if (state == PlayModeStateChange.ExitingPlayMode)
     {
         if (_isRecording)
         {
             PlayModeEdit_System.CacheCurrentState();
         }
         SceneView.onSceneGUIDelegate -= OnScene;
     }
     else if (state == PlayModeStateChange.EnteredEditMode)
     {
         if (_isRecording)
         {
             PlayModeEdit_System.ApplyCache();
         }
     }
     else if (state == PlayModeStateChange.ExitingEditMode)
     {
         foreach (PlayModeEdit playModeEdit in GameObject.FindObjectsOfType <PlayModeEdit>())
         {
             playModeEdit.CacheRecordedComponents();
         }
     }
 }