private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath) { string path = ""; if (usePreviousAssetPath) { path = AssetDatabase.GetAssetPath(probe.customBakedTexture); } string targetExtension = probe.hdr ? "exr" : "png"; if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension) { // We use the path of the active scene as the target path string targetPath = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path); if (string.IsNullOrEmpty(targetPath)) { targetPath = "Assets"; } else if (Directory.Exists(targetPath) == false) { Directory.CreateDirectory(targetPath); } string fileName = probe.name + (probe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension; fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName))); path = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileName, targetExtension, "", targetPath); if (string.IsNullOrEmpty(path)) { return; } ReflectionProbe collidingProbe; if (IsCollidingWithOtherProbes(path, probe, out collidingProbe)) { if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", path, collidingProbe.name), "Yes", "No")) { return; } } } EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + path, 0.5f); if (!Lightmapping.BakeReflectionProbe(probe, path)) { Debug.LogError("Failed to bake reflection probe to " + path); } EditorUtility.ClearProgressBar(); }
private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath) { string text = ""; if (usePreviousAssetPath) { text = AssetDatabase.GetAssetPath(probe.customBakedTexture); } string text2 = (!probe.hdr) ? "png" : "exr"; if (string.IsNullOrEmpty(text) || Path.GetExtension(text) != "." + text2) { string text3 = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path); if (string.IsNullOrEmpty(text3)) { text3 = "Assets"; } else if (!Directory.Exists(text3)) { Directory.CreateDirectory(text3); } string text4 = probe.name + ((!probe.hdr) ? "-reflection" : "-reflectionHDR") + "." + text2; text4 = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(text3, text4))); text = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", text4, text2, "", text3); if (string.IsNullOrEmpty(text)) { return; } ReflectionProbe reflectionProbe; if (this.IsCollidingWithOtherProbes(text, probe, out reflectionProbe)) { if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", text, reflectionProbe.name), "Yes", "No")) { return; } } } EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + text, 0.5f); if (!Lightmapping.BakeReflectionProbe(probe, text)) { Debug.LogError("Failed to bake reflection probe to " + text); } EditorUtility.ClearProgressBar(); }
private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath) { string assetPath = string.Empty; if (usePreviousAssetPath) { assetPath = AssetDatabase.GetAssetPath(probe.customBakedTexture); } string extension = !probe.hdr ? "png" : "exr"; if (string.IsNullOrEmpty(assetPath) || (Path.GetExtension(assetPath) != ("." + extension))) { ReflectionProbe probe2; string pathWithoutExtension = FileUtil.GetPathWithoutExtension(EditorApplication.currentScene); if (string.IsNullOrEmpty(pathWithoutExtension)) { pathWithoutExtension = "Assets"; } else if (!Directory.Exists(pathWithoutExtension)) { Directory.CreateDirectory(pathWithoutExtension); } string fileNameWithoutExtension = probe.name + (!probe.hdr ? "-reflection" : "-reflectionHDR") + "." + extension; fileNameWithoutExtension = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(pathWithoutExtension, fileNameWithoutExtension))); assetPath = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileNameWithoutExtension, extension, string.Empty, pathWithoutExtension); if (string.IsNullOrEmpty(assetPath)) { return; } if (this.IsCollidingWithOtherProbes(assetPath, probe, out probe2) && !EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", assetPath, probe2.name), "Yes", "No")) { return; } } EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + assetPath, 0.5f); if (!Lightmapping.BakeReflectionProbe(probe, assetPath)) { Debug.LogError("Failed to bake reflection probe to " + assetPath); } EditorUtility.ClearProgressBar(); }
private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath) { string text = string.Empty; if (usePreviousAssetPath) { text = AssetDatabase.GetAssetPath(probe.customBakedTexture); } string text2 = (!probe.hdr) ? "png" : "exr"; if (string.IsNullOrEmpty(text) || Path.GetExtension(text) != "." + text2) { string text3 = FileUtil.GetPathWithoutExtension(EditorApplication.currentScene); if (string.IsNullOrEmpty(text3)) { text3 = "Assets"; } else { if (!Directory.Exists(text3)) { Directory.CreateDirectory(text3); } } string text4 = probe.name + ((!probe.hdr) ? "-reflection" : "-reflectionHDR") + "." + text2; text4 = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(text3, text4))); text = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", text4, text2, string.Empty, text3); if (string.IsNullOrEmpty(text)) { return; } } EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + text, 0.5f); if (!Lightmapping.BakeReflectionProbe(probe, text)) { Debug.LogError("Failed to bake reflection probe to " + text); } EditorUtility.ClearProgressBar(); }
private void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath) { string str1 = string.Empty; if (usePreviousAssetPath) { str1 = AssetDatabase.GetAssetPath((UnityEngine.Object)probe.customBakedTexture); } string extension = !probe.hdr ? "png" : "exr"; if (string.IsNullOrEmpty(str1) || Path.GetExtension(str1) != "." + extension) { string str2 = FileUtil.GetPathWithoutExtension(SceneManager.GetActiveScene().path); if (string.IsNullOrEmpty(str2)) { str2 = "Assets"; } else if (!Directory.Exists(str2)) { Directory.CreateDirectory(str2); } string path2 = probe.name + (!probe.hdr ? "-reflection" : "-reflectionHDR") + "." + extension; str1 = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(str2, path2))), extension, string.Empty, str2); ReflectionProbe collidingProbe; if (string.IsNullOrEmpty(str1) || this.IsCollidingWithOtherProbes(str1, probe, out collidingProbe) && !EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", (object)str1, (object)collidingProbe.name), "Yes", "No")) { return; } } EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + str1, 0.5f); if (!Lightmapping.BakeReflectionProbe(probe, str1)) { Debug.LogError((object)("Failed to bake reflection probe to " + str1)); } EditorUtility.ClearProgressBar(); }
private void DoPrefabButtons(PrefabType prefabType, GameObject go) { // @TODO: If/when we support multi-editing of prefab/model instances, // handle it here. Only show prefab bar if all are same type? if (!m_HasInstance) { return; } using (new EditorGUI.DisabledScope(EditorApplication.isPlayingOrWillChangePlaymode)) { EditorGUILayout.BeginHorizontal(); // Prefab information GUIContent prefixLabel = targets.Length > 1 ? s_Styles.goTypeLabelMultiple : s_Styles.goTypeLabel[(int)prefabType]; if (prefixLabel != null) { EditorGUILayout.BeginHorizontal(GUILayout.Width(kIconSize + s_Styles.tagFieldWidth)); GUILayout.FlexibleSpace(); if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.MissingPrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GUI.contentColor = GUI.skin.GetStyle("CN StatusWarn").normal.textColor; GUILayout.Label(prefixLabel, EditorStyles.whiteLabel, GUILayout.ExpandWidth(false)); GUI.contentColor = Color.white; } else { GUILayout.Label(prefixLabel, GUILayout.ExpandWidth(false)); } EditorGUILayout.EndHorizontal(); } if (targets.Length > 1) { GUILayout.Label("Instance Management Disabled", s_Styles.instanceManagementInfo); } else { // Select prefab if (prefabType != PrefabType.MissingPrefabInstance) { if (GUILayout.Button("Select", "MiniButtonLeft")) { Selection.activeObject = PrefabUtility.GetCorrespondingObjectFromSource(target); EditorGUIUtility.PingObject(Selection.activeObject); } } using (new EditorGUI.DisabledScope(AnimationMode.InAnimationMode())) { if (prefabType != PrefabType.MissingPrefabInstance) { // Revert this gameobject and components to prefab if (GUILayout.Button("Revert", "MiniButtonMid")) { PrefabUtility.RevertPrefabInstanceWithUndo(go); // case931300 - The selected gameobject might get destroyed by RevertPrefabInstance if (go != null) { CalculatePrefabStatus(); } // This is necessary because Revert can potentially destroy game objects and components // In that case the Editor classes would be destroyed but still be invoked. (case 837113) GUIUtility.ExitGUI(); } // Apply to prefab if (prefabType == PrefabType.PrefabInstance || prefabType == PrefabType.DisconnectedPrefabInstance) { GameObject rootUploadGameObject = PrefabUtility.FindValidUploadPrefabInstanceRoot(go); GUI.enabled = rootUploadGameObject != null && !AnimationMode.InAnimationMode(); if (GUILayout.Button("Apply", "MiniButtonRight")) { UnityObject correspondingAssetObject = PrefabUtility.GetCorrespondingObjectFromSource(rootUploadGameObject); string prefabAssetPath = AssetDatabase.GetAssetPath(correspondingAssetObject); bool isRootFolder, isReadonly; bool validPath = AssetDatabase.GetAssetFolderInfo(prefabAssetPath, out isRootFolder, out isReadonly); if (validPath && isReadonly) { string prefabName = FileUtil.GetLastPathNameComponent(FileUtil.GetPathWithoutExtension(prefabAssetPath)); EditorUtility.DisplayDialog("Cannot apply changes", string.Format("Original prefab \"{0}\" is immutable.", prefabName), "Close"); } else { bool editablePrefab = Provider.PromptAndCheckoutIfNeeded( new string[] { prefabAssetPath }, "The version control requires you to check out the prefab before applying changes."); if (editablePrefab) { PrefabUtility.ReplacePrefabWithUndo(rootUploadGameObject); CalculatePrefabStatus(); // This is necessary because ReplacePrefab can potentially destroy game objects and components // In that case the Editor classes would be destroyed but still be invoked. (case 468434) GUIUtility.ExitGUI(); } } } } } } // Edit model prefab if (prefabType == PrefabType.DisconnectedModelPrefabInstance || prefabType == PrefabType.ModelPrefabInstance) { if (GUILayout.Button("Open", "MiniButtonRight")) { AssetDatabase.OpenAsset(PrefabUtility.GetCorrespondingObjectFromSource(target)); GUIUtility.ExitGUI(); } } } EditorGUILayout.EndHorizontal(); } }