private static void ReconcileContextsBasedOnSelection() { currentContexts.Clear(); #if (UNITY_2_6 || UNITY_2_6_1 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4) List <GameObject> selectedGameObjects = new List <GameObject>(); if (Selection.activeGameObject != null) { selectedGameObjects.Add(Selection.activeGameObject); } #else List <GameObject> selectedGameObjects = Selection.gameObjects.Where(g => !currentContexts.Any(c => c.GameObj == g)).ToList(); #endif foreach (GameObject gameObject in selectedGameObjects) { PPCurrentContext context = allContexts.SingleOrDefault(c => c.GameObj == gameObject); if (context == null) { context = CreateContext(gameObject.transform); } currentContexts.Add(context); } }
private static PPCurrentContext CreateContext(Transform transform) { PPCurrentContext context = new PPCurrentContext(); allContexts.Add(context); context.SetContext(transform); return(context); }
public static void SetPersistanceForAllExistingContextObjects(string typeName, bool isSaveSetting) { foreach (PPCurrentContext context in allContexts.Where(c => c.GameObj != null)) { PPComponentSetting componentSetting = context.GameObjectSetting.ComponentSettings.FirstOrDefault(cs => cs.ComponentName == typeName); if (componentSetting != null) { componentSetting.IsSavingSettings = isSaveSetting; PPCurrentContext currentContext = currentContexts.FirstOrDefault(c => c.GameObj == context.GameObj); // If current context is changed and the PlayModePersist panel is open, update the checkboxes if (currentContext != null && currentContext.GameObjectSetting.Expanded) { EditorUtility.SetDirty(context.GameObj); } } } }
private static PPCurrentContext CreateContext(Transform transform) { PPCurrentContext context = new PPCurrentContext(); allContexts.Add(context); context.SetContext(transform); return context; }
public override void OnInspectorGUI() { if (EditorApplication.isPlaying || EditorApplication.isPaused) { if (context == null) { context = new PPCurrentContext(); allContexts.Add(context); context.SetContext(target as Transform); } else if (context.GameObj != ((Transform)target).gameObject) { bool isFound = false; for (int n = 0; n < allContexts.Count; n++) { if (allContexts[n].GameObj == ((Transform)target).gameObject) { isFound = true; context = allContexts[n]; break; } } if (!isFound) { context = new PPCurrentContext(); allContexts.Add(context); context.SetContext(target as Transform); } } } if (context != null && null != context.GameObj) { PrefabType contextPrefabType = EditorUtility.GetPrefabType(context.GameObj); if (contextPrefabType != PrefabType.Prefab && contextPrefabType != PrefabType.ModelPrefab) { if (EditorApplication.isPlaying || EditorApplication.isPaused) { PPGOSetting setting = context.GameObjectSetting; setting.Expanded = EditorGUILayout.Foldout(setting.Expanded, "PlayModePersist"); if (setting.Expanded) { EditorGUILayout.BeginVertical("box", GUILayout.ExpandWidth(true)); EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(150f)); if (setting.ComponentSettings.Any(s => !s.IsSavingSettings)) { setting.SaveAll = false; } bool wasSaveAll = setting.SaveAll; setting.SaveAll = GUILayout.Toggle(setting.SaveAll, "Save All"); EditorGUILayout.EndHorizontal(); GUILayout.Box("", GUILayout.Height(1f), GUILayout.ExpandWidth(true)); if (setting.SaveAll && !wasSaveAll) { setting.ComponentSettings.ForEach(s => s.IsSavingSettings = true); } else if (!setting.SaveAll && wasSaveAll) { setting.ComponentSettings.ForEach(s => s.IsSavingSettings = false); } foreach (PPComponentSetting childSetting in setting.ComponentSettings) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(childSetting.ComponentName, GUILayout.Width(150f)); childSetting.IsSavingSettings = GUILayout.Toggle(childSetting.IsSavingSettings, "Save"); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } EditorApplication.playmodeStateChanged = Application_PlaymodeStateChanged; } } transformInspector.DrawDefaultInspector(target as Transform); } else { transformInspector.DrawDefaultInspector(target as Transform); } }
private void AddMissingGameObjectsByType(System.Type t) { bool isFound; GameObject tempGO; Object[] objs = Object.FindObjectsOfType(t); PPCurrentContext newContext; foreach (Object obj in objs) { isFound = false; if (obj as Component != null && ((Component)obj).gameObject != null) { tempGO = ((Component)obj).gameObject; foreach (PPCurrentContext currContext in allContexts) { if (currContext.GameObj == tempGO) { isFound = true; break; } } if (!isFound) { newContext = new PPCurrentContext(); allContexts.Add(newContext); newContext.SetContext(tempGO.transform); } } } }