public void CreateComponentSettings() { componentSettings = new List <PPComponentSetting>(); Component[] components = GameObj.GetComponents(typeof(Component)); foreach (Component c in components) { PPComponentSetting setting = new PPComponentSetting(c); if (c != null) { if (PPLocalStorageManager.IsTypeDefaulted(c.GetType())) { setting.IsSavingSettings = true; } } componentSettings.Add(setting); } }
public void OnGUI() { GUILayout.Label("PlayModePersist - Auto Persist", EditorStyles.boldLabel); EditorGUILayout.Space(); autoPersistSearch = EditorGUILayout.TextField(new GUIContent("Filter"), autoPersistSearch, GUILayout.Width(300.0f)); EditorGUILayout.Space(); scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, false, GUILayout.Width(300), GUILayout.Height(this.position.height - 140)); int listCount = 0; foreach (PPAutoPersistObject autoPersistObj in defaultTypes) { if (autoPersistSearch == "" || autoPersistObj.TypeName.ToLower().StartsWith(autoPersistSearch.ToLower())) { if (!isShowOnlyEnabled || autoPersistObj.IsDefaulted) { GUILayout.BeginHorizontal(GUILayout.Width(250)); GUILayout.Label(autoPersistObj.TypeName, GUILayout.Width(200)); if (!autoPersistObj.IsDefaulted) { if (GUILayout.Button("Add")) { PPLocalStorageManager.AddDefault(autoPersistObj.GetFullClassName()); autoPersistObj.IsDefaulted = true; if (EditorApplication.isPlaying || EditorApplication.isPaused) { if (PPEditorWindow.currentWindow != null) { PPEditorWindow.SetPersistanceForAllExistingContextObjects(autoPersistObj.TypeName, true); PPEditorWindow.currentWindow.Repaint(); } } } } else { if (GUILayout.Button("Remove")) { PPLocalStorageManager.RemoveDefault(autoPersistObj.GetFullClassName()); autoPersistObj.IsDefaulted = false; if (EditorApplication.isPlaying || EditorApplication.isPaused) { if (PPEditorWindow.currentWindow != null) { PPEditorWindow.SetPersistanceForAllExistingContextObjects(autoPersistObj.TypeName, false); PPEditorWindow.currentWindow.Repaint(); } } //add logic to deselect all active object of this type if in PlayMode } } GUILayout.EndHorizontal(); listCount++; } } } if (listCount == 0) { if (isShowOnlyEnabled && autoPersistSearch == "") { GUILayout.Label("No Components Are Auto Persisting"); } else { GUILayout.Label("Please Broaden Your Search"); } } EditorGUILayout.EndScrollView(); EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Show Only Enabled"); isShowOnlyEnabled = EditorGUILayout.Toggle(isShowOnlyEnabled, GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); // GUILayout.Label("Note:You will need to have selected a GameObject\nwhile in Playmode for components to auto persist"); //Experimental Start /* * EditorGUILayout.BeginHorizontal(); * if (GUILayout.Button("Add All")) * { * foreach (PPAutoPersistObject autoPersistObj in defaultTypes) * { * PPLocalStorageManager.AddDefault(autoPersistObj.GetFullClassName()); * autoPersistObj.IsDefaulted = true; * if (EditorApplication.isPlaying || EditorApplication.isPaused) * { * PPInspector.SetPersistanceForAllExistingContextObjects(autoPersistObj.TypeName, true); * } * } * } * * if (GUILayout.Button("Remove All")) * { * foreach (PPAutoPersistObject autoPersistObj in defaultTypes) * { * PPLocalStorageManager.RemoveDefault(autoPersistObj.GetFullClassName()); * autoPersistObj.IsDefaulted = false; * if (EditorApplication.isPlaying || EditorApplication.isPaused) * { * PPInspector.SetPersistanceForAllExistingContextObjects(autoPersistObj.TypeName, false); * } * } * } * EditorGUILayout.EndHorizontal(); * EditorGUILayout.Space(); * EditorGUILayout.Space(); */ //Experimental End }