public IEnumerator BakingWithATrousFiltering_DoesNotFallback() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeATrous.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU; lightingSettings.mixedBakeMode = MixedLightingMode.IndirectOnly; lightingSettings.directionalityMode = LightmapsMode.NonDirectional; // Activate A-Trous filtering lightingSettings.filterTypeIndirect = LightingSettings.FilterType.ATrous; Lightmapping.Clear(); Lightmapping.Bake(); // Check that we did not fallback to CPULM Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
public IEnumerator TiledBaking_GPU_1k_lightmap_4_tiles() { EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; lightingSettings.lightmapResolution = 100; lightingSettings.lightmapMaxSize = 1024; Lightmapping.Clear(); Lightmapping.Bake(); LightmapConvergence lc = Lightmapping.GetLightmapConvergence(0); Assert.That(lc.GetTileCount(), Is.EqualTo(4), "Max tiling pass num should be 4"); while (Lightmapping.isRunning) { yield return(null); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
public IEnumerator TiledBaking_GPU_1k_lightmap_4_tiles_1_Empty_Tile() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/ThreePlanes.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; Lightmapping.Clear(); Lightmapping.Bake(); LightmapConvergence lc = Lightmapping.GetLightmapConvergence(0); Assert.That(lc.GetTileCount(), Is.EqualTo(4), "Max tiling pass num should be 4"); while (Lightmapping.isRunning) { yield return(null); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
public static void ClearLightmappingData() { Debug.Log("Clear Lighting Data Asset ..."); Lightmapping.ClearLightingDataAsset(); Lightmapping.Clear(); Debug.Log("Clear Lighting Data Asset Successfully!"); }
public IEnumerator ActivateDirectLighting_DuringABake_DoesNotFallback() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeRestartScene.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU; lightingSettings.mixedBakeMode = MixedLightingMode.IndirectOnly; lightingSettings.directionalityMode = LightmapsMode.NonDirectional; GameObject dirLightGO = GameObject.FindGameObjectsWithTag("TheLight")[0]; dirLightGO.SetActive(false); Light light = dirLightGO.GetComponent(typeof(Light)) as Light; light.lightmapBakeType = LightmapBakeType.Baked; Lightmapping.Clear(); Lightmapping.BakeAsync(); foreach (bool b in RunABake(0.2f)) { yield return(null); } // Make sure it is still baking before we // switch the light on and restart the bake Assert.IsTrue(Lightmapping.isBaking); // Activate the light, cause the bake to restart dirLightGO.SetActive(true); foreach (bool b in RunABake(0.2f)) { yield return(null); } // Check that baking is still running Assert.IsTrue(Lightmapping.isBaking); // Check that we did not fallback to CPULM Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU); Lightmapping.Cancel(); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
/// <inheritdoc /> protected override bool OnStepStart() { if (ClearDiskCache) { Lightmapping.ClearDiskCache(); } if (ClearLightingDataAsset) { Lightmapping.ClearLightingDataAsset(); } return(true); }
public IEnumerator Export_Training_Data_With_AO_And_Tiled_Baking_On() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/ExtractTrainingDataScene.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; lightingSettings.exportTrainingData = false; lightingSettings.ao = true; Lightmapping.Clear(); Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(!System.IO.Directory.Exists("Assets/TrainingData/Lightmap-0")); Assert.That(!System.IO.File.Exists("Assets/TrainingData/Lightmap-0/indirect.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); lightingSettings.exportTrainingData = true; Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(System.IO.Directory.Exists("Assets/TrainingData/Lightmap-0")); Assert.That(System.IO.File.Exists("Assets/TrainingData/Lightmap-0/indirect.exr")); Assert.That(System.IO.File.Exists("Assets/TrainingData/Lightmap-0/ambient_occlusion.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); System.IO.Directory.Delete("Assets/TrainingData", true); Assert.That(!System.IO.Directory.Exists("Assets/TrainingData")); }
public IEnumerator ActivateAO_DuringABake_DoesNotFallback() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/BakeRestartScene.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.lightmapper = LightingSettings.Lightmapper.ProgressiveGPU; GameObject dirLightGO = GameObject.FindGameObjectsWithTag("TheLight")[0]; dirLightGO.SetActive(false); lightingSettings.ao = false; Lightmapping.Clear(); Lightmapping.BakeAsync(); foreach (bool b in RunABake(0.2f)) { yield return(null); } // Make sure it is still baking before we // switch the AO on and restart the bake Assert.IsTrue(Lightmapping.isBaking); // Switch AO on, cause the bake to restart lightingSettings.ao = true; foreach (bool b in RunABake(0.2f)) { yield return(null); } // Check that baking is still running Assert.IsTrue(Lightmapping.isBaking); // Check that we did not fallback to CPULM Assert.AreEqual(lightingSettings.lightmapper, LightingSettings.Lightmapper.ProgressiveGPU); Lightmapping.Cancel(); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
/// <summary> /// クリアする /// </summary> void DoClear() { Lightmapping.ClearLightingDataAsset(); Lightmapping.Clear(); var instance = (LightmapSettingsPrefab)target; var go = instance.gameObject; instance.baked = default(bool); instance.unityVersion = default(string); instance.lightmaps = default(SerializableLightmapData[]); instance.lightmapsMode = default(LightmapsMode); instance.lightProbes = default(LightProbes); instance.reflectionProbes = default(Cubemap[]); instance.renderers = default(SerializableRenderer[]); instance.SetupLightmap(); DoApply(go); }
static void _Light() { SceneViewTools.ShowWindowButton(UnityTypes.UnityEditor_LightingWindow, "Lighting", EditorIcon.lighting); SceneViewTools.ShowWindowButton(UnityTypes.UnityEditor_LightingExplorerWindow, "Light Explorer", EditorIcon.lighting); if (Lightmapping.isRunning) { if (SceneViewTools.ShowSideButton("Cancel", EditorIcon.lighting)) { Lightmapping.Cancel(); } } else { if (SceneViewTools.ShowSideButton("Generate Lighting", EditorIcon.lighting)) { Lightmapping.ClearLightingDataAsset(); Lightmapping.Clear(); Lightmapping.BakeAsync(); } } }
public IEnumerator Extract_AO_With_Tiled_Baking_On() { EditorSceneManager.OpenScene("Assets/Tests/Editor/Tests_Unit_Editmode/AOTestScene.unity", OpenSceneMode.Single); yield return(null); LightingSettings lightingSettings = null; Lightmapping.TryGetLightingSettings(out lightingSettings); Assert.That(lightingSettings, !Is.EqualTo(null), "LightingSettings is null"); lightingSettings.tiledBaking = LightingSettings.TiledBaking.Quarter; lightingSettings.extractAO = false; Lightmapping.Clear(); Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(!System.IO.File.Exists("Assets/Tests/Editor/Tests_Unit_Editmode/AOTestScene/Lightmap-0_ao.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); lightingSettings.extractAO = true; Lightmapping.Bake(); while (Lightmapping.isRunning) { yield return(null); } Assert.That(System.IO.File.Exists("Assets/Tests/Editor/Tests_Unit_Editmode/AOTestScene/Lightmap-0_ao.exr")); Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); }
private static void ApplyAction(int option) { turnOffBakedLightsAfterBake = false; if (option == BakeScene) { Lightmapping.BakeAsync(); } else if (option == TurnOnAllLightsBakeSceneAndTurnOffBakedLights) { turnOffBakedLightsAfterBake = true; ActivateLights(true); Lightmapping.BakeAsync(); } else if (option == TurnOnBakedLightsBakeSceneAndTurnOffBakedLights) { turnOffBakedLightsAfterBake = true; ActivateLights(true, true); Lightmapping.BakeAsync(); } else if (option == ClearBakeData) { Lightmapping.Clear(); Lightmapping.ClearDiskCache(); Lightmapping.ClearLightingDataAsset(); } else if (option == CancelBake) { Lightmapping.Cancel(); } else { var enableComponent = option == ActivateAllLights || option == ActivateBakedLights || option == ActivateNotBakedLights; var justBaked = option == ActivateBakedLights || option == DeactivateBakedLights; var justNotBaked = option == ActivateNotBakedLights || option == DeactivateNotBakedLights; ActivateLights(enableComponent, justBaked, justNotBaked); } }
static void OnBakeComplete() { // 4. Clear progress & events BakeFinished( ); // 5. Fetch lightmaps, apply to prefab and save them in selected folder SaveLightmaps(); if (Window.AutoClean) { // 6. Delete scene lightmap data Lightmapping.ClearLightingDataAsset( ); Lightmapping.ClearDiskCache( ); Lightmapping.Clear( ); } // 7. Combine prefab lightmaps with scene lightmaps EditorUtils.GetAllPrefabs( ).ForEach(x => Utils.Apply(x)); }
public void LightingOptionHandler() { if (ClearCache) { Lightmapping.Clear(); Lightmapping.ClearDiskCache(); Lightmapping.ClearLightingDataAsset(); Debug.Log("PixelSpice - Cache Cleared"); Last_Clear = true; } else if (!HasBaked) { Debug.Log("PixelSpice - Prebakeing Lightmap"); Lightmapping.Bake(); HasBaked = true; Debug.Log("PixelSpice - Prebake Complete"); Last_Clear = false; } else { Debug.Log("PixelSpice - No Prebake Needed - Skipping"); Last_Clear = false; } }
static void clearAll() { Lightmapping.Clear(); Lightmapping.ClearDiskCache(); Lightmapping.ClearLightingDataAsset(); }
public static void ExportPackage(GameObject gameObject, string path, string typeName, PackageJSON packageJSON) { string fileName = Path.GetFileName(path); string folderPath = Path.GetDirectoryName(path); string androidFileName = Path.GetFileNameWithoutExtension(path) + "_android"; string pcFileName = Path.GetFileNameWithoutExtension(path) + "_pc"; string assetBundleScenePath = $"Assets/Editor/ExportScene.unity"; string oldScenePath = gameObject.scene.path; if (oldScenePath != null) { EditorSceneManager.SaveScene(gameObject.scene); } try { Selection.activeObject = gameObject; MapDescriptor mapDescriptor = gameObject.GetComponent <MapDescriptor>(); if (!mapDescriptor.ExportLighting) { Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); } //EditorSceneManager.MarkSceneDirty(gameObject.scene); EditorSceneManager.SaveScene(gameObject.scene, assetBundleScenePath, true); EditorSceneManager.OpenScene(assetBundleScenePath); MapDescriptor[] descriptorList = Object.FindObjectsOfType <MapDescriptor>(); foreach (MapDescriptor descriptor in descriptorList) { if (descriptor.MapName != mapDescriptor.MapName) { Object.DestroyImmediate(descriptor.gameObject); } else { mapDescriptor = descriptor; gameObject = descriptor.gameObject; Selection.activeObject = gameObject; } } // First, unpack all prefabs foreach (GameObject subObject in GameObject.FindObjectsOfType <GameObject>()) { if (PrefabUtility.GetPrefabInstanceStatus(subObject) != PrefabInstanceStatus.NotAPrefab) { PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetOutermostPrefabInstanceRoot(subObject), PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); } } // Skybox Stuff if (mapDescriptor.CustomSkybox != null) { // Create Fake Skybox GameObject skybox = GameObject.CreatePrimitive(PrimitiveType.Sphere); skybox.name = "Skybox"; skybox.transform.SetParent(gameObject.transform); skybox.transform.localScale = new Vector3(1000, 1000, 1000); skybox.transform.localPosition = Vector3.zero; skybox.transform.localRotation = Quaternion.identity; Object.DestroyImmediate(skybox.GetComponent <Collider>()); Material skyboxMaterial = new Material(Shader.Find("Bobbie/Outer")); skyboxMaterial.SetTexture("_Tex", mapDescriptor.CustomSkybox); skybox.GetComponent <Renderer>().material = skyboxMaterial; skybox.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } else { // Create Fake Skybox that represents the game's GameObject skyboxObject = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/FakeSkybox.prefab", typeof(GameObject)) as GameObject; GameObject fakeSkybox = PrefabUtility.InstantiatePrefab(skyboxObject) as GameObject; fakeSkybox.transform.SetParent(gameObject.transform); fakeSkybox.transform.localPosition = Vector3.zero; } // Remove meshes from prefabs/triggers if (!DebugPrefabs) { StripMeshes <ObjectTrigger>(gameObject); StripMeshes <Teleporter>(gameObject); StripMeshes <TagZone>(gameObject); foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.name.StartsWith("Teleport Point")) { Object.DestroyImmediate(renderer); } } StripMeshes <ObjectTrigger>(gameObject); } foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.name.StartsWith("Spawn Point")) { bool foundTransform = false; foreach (Transform spawnPoint in mapDescriptor.SpawnPoints) { if (spawnPoint == renderer.gameObject.transform) { foundTransform = true; } } if (!foundTransform) { List <Transform> spawnPointArray = new List <Transform>(mapDescriptor.SpawnPoints); spawnPointArray.Add(renderer.gameObject.transform); mapDescriptor.SpawnPoints = spawnPointArray.ToArray(); } if (!DebugPrefabs) { Collider spawnPointCollider = renderer.gameObject.GetComponent <Collider>(); if (spawnPointCollider) { Object.DestroyImmediate(spawnPointCollider); } Object.DestroyImmediate(renderer); } } } if (mapDescriptor.SpawnPoints.Length == 0) { throw new System.Exception("No spawn points found! Add some spawn points to your map."); } // Take Screenshots with the thumbnail camera Camera thumbnailCamera = gameObject.transform.Find("ThumbnailCamera")?.GetComponent <Camera>(); if (thumbnailCamera != null) { // Normal Screenshot Texture2D screenshot = CaptureScreenshot(thumbnailCamera, 512, 512); byte[] screenshotPNG = ImageConversion.EncodeToPNG(screenshot); File.WriteAllBytes(Application.temporaryCachePath + "/preview.png", screenshotPNG); packageJSON.config.imagePath = "preview.png"; // Cubemap Screenshot Texture2D screenshotCubemap = CaptureCubemap(thumbnailCamera, 1024, 1024); byte[] screenshotCubemapPNG = ImageConversion.EncodeToPNG(screenshotCubemap); File.WriteAllBytes(Application.temporaryCachePath + "/preview_cubemap.png", screenshotCubemapPNG); packageJSON.config.cubemapImagePath = "preview_cubemap.png"; packageJSON.config.mapColor = AverageColor(screenshotCubemap); /* quest stuff (disabled for now) * byte[] screenshotRaw = screenshot.GetRawTextureData(); * File.WriteAllBytes(Application.temporaryCachePath + "/preview_quest", screenshotRaw); */ } Object.DestroyImmediate(thumbnailCamera.gameObject); // Pre-Process stuff for both platforms - PC and Android. GameObject spawnPointContainer = new GameObject("SpawnPointContainer"); spawnPointContainer.transform.SetParent(gameObject.transform); spawnPointContainer.transform.localPosition = Vector3.zero; spawnPointContainer.transform.localRotation = Quaternion.identity; spawnPointContainer.transform.localScale = Vector3.one; List <string> spawnPointNames = new List <string>(); for (int i = 0; i < mapDescriptor.SpawnPoints.Length; i++) { Transform spawnPointTransform = mapDescriptor.SpawnPoints[i].gameObject.transform; Vector3 oldPos = spawnPointTransform.position; var oldRotation = spawnPointTransform.rotation; spawnPointTransform.SetParent(spawnPointContainer.transform); spawnPointTransform.rotation = oldRotation; spawnPointTransform.position = oldPos; string nameString = "SpawnPoint" + (i < 10 ? "0" + i : i.ToString()); mapDescriptor.SpawnPoints[i].gameObject.name = nameString; spawnPointNames.Add(nameString); } packageJSON.config.spawnPoints = spawnPointNames.ToArray(); // Replace tiling materials with baked versions foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.shader.name.Contains("Standard Tiling") && !renderer.sharedMaterial.shader.name.Contains("Baked")) { renderer.sharedMaterial = Object.Instantiate(renderer.sharedMaterial); renderer.sharedMaterial.shader = Shader.Find("Standard Tiling Baked"); Transform rendererTransform = renderer.gameObject.transform; Vector3 newVector = RotatePointAroundPivot(rendererTransform.lossyScale, new Vector3(0, 0, 0), rendererTransform.rotation.eulerAngles); renderer.sharedMaterial.SetVector("_ScaleVector", newVector); } } // Destroy all non-render cameras because people keep accidentally exporting them foreach (Camera camera in gameObject.GetComponentsInChildren <Camera>()) { if (camera.targetTexture == null && camera.gameObject != null) { Object.DestroyImmediate(camera.gameObject); } } // Lighting stuff. Make sure to set light stuff up and make it bigger, and bake if (mapDescriptor.ExportLighting) { foreach (Light light in Object.FindObjectsOfType <Light>()) { if (light.type == LightType.Directional) { light.intensity *= 11.54f; light.color = new Color(0.3215f, 0.3215f, 0.3215f); } else { light.intensity *= 10f; } } Lightmapping.Bake(); } else { foreach (Light light in Object.FindObjectsOfType <Light>()) { Object.DestroyImmediate(light); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); } gameObject.transform.localPosition = new Vector3(0, 5000, 0); // Save as prefab and build // PrefabUtility.SaveAsPrefabAsset(Selection.activeObject as GameObject, $"Assets/_{typeName}.prefab"); EditorSceneManager.SaveScene(gameObject.scene); AssetBundleBuild assetBundleBuild = default; assetBundleBuild.assetNames = new string[] { assetBundleScenePath }; assetBundleBuild.assetBundleName = pcFileName; // Build for PC BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, BuildTarget.StandaloneWindows64); // Do Android specific stuff here. Stripping MonoBehaviours and converting them to TextAssets, etc. // first we need to redo this bit of code because sometimes gameObject unreferences itself MapDescriptor[] descriptorList2 = Object.FindObjectsOfType <MapDescriptor>(); foreach (MapDescriptor descriptor in descriptorList2) { if (descriptor.MapName != mapDescriptor.MapName) { Object.DestroyImmediate(descriptor.gameObject); } else { mapDescriptor = descriptor; gameObject = descriptor.gameObject; Selection.activeObject = gameObject; } } foreach (TagZone zone in gameObject.GetComponentsInChildren <TagZone>(true)) { if (zone != null && zone.gameObject != null) { CreateQuestText("{\"TagZone\": true}", zone.gameObject); Object.DestroyImmediate(zone); } } foreach (SurfaceClimbSettings surfaceClimbSettings in gameObject.GetComponentsInChildren <SurfaceClimbSettings>(true)) { if (surfaceClimbSettings != null && surfaceClimbSettings.gameObject != null) { SurfaceClimbSettingsJSON settingsJson = new SurfaceClimbSettingsJSON(); settingsJson.Unclimbable = surfaceClimbSettings.Unclimbable; settingsJson.slipPercentage = surfaceClimbSettings.slipPercentage; CreateQuestText(JsonUtility.ToJson(settingsJson), surfaceClimbSettings.gameObject); Object.DestroyImmediate(surfaceClimbSettings); } } int triggerCount = 1; foreach (ObjectTrigger objectTrigger in gameObject.GetComponentsInChildren <ObjectTrigger>(true)) { if (objectTrigger != null && objectTrigger.gameObject != null) { string objectName = "ObjectTrigger" + triggerCount; if (objectTrigger.ObjectToTrigger != null) { CreateQuestText("{\"TriggeredBy\": \"" + objectName + "\"}", objectTrigger.ObjectToTrigger); } ObjectTriggerJSON triggerJSON = new ObjectTriggerJSON(); triggerJSON.ObjectTriggerName = objectName; triggerJSON.OnlyTriggerOnce = objectTrigger.OnlyTriggerOnce; triggerJSON.DisableObject = objectTrigger.DisableObject; CreateQuestText(JsonUtility.ToJson(triggerJSON), objectTrigger.gameObject); Object.DestroyImmediate(objectTrigger); triggerCount++; } } int teleporterCount = 1; foreach (Teleporter teleporter in gameObject.GetComponentsInChildren <Teleporter>(true)) { if (teleporter != null && teleporter.gameObject != null) { string teleporterName = "Teleporter" + teleporterCount; foreach (Transform teleportPoint in teleporter.TeleportPoints) { if (teleportPoint != null && teleportPoint.gameObject != null) { CreateQuestText("{\"TeleportPoint\": \"" + teleporterName + "\"}", teleportPoint.gameObject); } } teleporter.TeleportPoints = null; string teleporterJSON = JsonUtility.ToJson(teleporter); teleporterJSON = teleporterJSON.Replace("\"TeleportPoints\":[],", "\"TeleporterName\": \"" + teleporterName + "\","); CreateQuestText(teleporterJSON, teleporter.gameObject); Object.DestroyImmediate(teleporter); teleporterCount++; } } RoundEndActions roundEndActions = gameObject.GetComponentInChildren <RoundEndActions>(true); if (roundEndActions != null && roundEndActions.gameObject != null) { foreach (GameObject roundEndActionObject in roundEndActions.ObjectsToEnable) { if (roundEndActionObject != null) { CreateQuestText("{\"RoundEndAction\": \"Enable\"}", roundEndActionObject); } } foreach (GameObject roundEndActionObject in roundEndActions.ObjectsToDisable) { if (roundEndActionObject != null) { CreateQuestText("{\"RoundEndAction\": \"Disable\"}", roundEndActionObject); } } RoundEndActionsJSON actionsJSON = new RoundEndActionsJSON(); actionsJSON.RoundEndActions = true; actionsJSON.RespawnOnRoundEnd = roundEndActions.RespawnOnRoundEnd; CreateQuestText(JsonUtility.ToJson(actionsJSON), roundEndActions.gameObject); Object.DestroyImmediate(roundEndActions); } Object.DestroyImmediate(mapDescriptor); // Do it again for Android EditorSceneManager.SaveScene(gameObject.scene); // PrefabUtility.SaveAsPrefabAsset(Selection.activeObject as GameObject, $"Assets/_{typeName}.prefab"); // are these next 2 lines necessary? idk. probably test it. assetBundleBuild.assetNames = new string[] { assetBundleScenePath }; assetBundleBuild.assetBundleName = androidFileName; BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, BuildTarget.Android); EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath); // JSON stuff packageJSON.androidFileName = androidFileName; packageJSON.pcFileName = pcFileName; string json = JsonUtility.ToJson(packageJSON, true); File.WriteAllText(Application.temporaryCachePath + "/package.json", json); // AssetDatabase.DeleteAsset($"Assets/_{typeName}.prefab"); // Delete the zip if it already exists and re-zip List <string> files = new List <string> { Application.temporaryCachePath + "/" + pcFileName, Application.temporaryCachePath + "/" + androidFileName, Application.temporaryCachePath + "/package.json", Application.temporaryCachePath + "/preview.png", Application.temporaryCachePath + "/preview_cubemap.png" }; if (File.Exists(Application.temporaryCachePath + "/tempZip.zip")) { File.Delete(Application.temporaryCachePath + "/tempZip.zip"); } CreateZipFile(Application.temporaryCachePath + "/tempZip.zip", files); // After zipping, clear some assets from the temp folder if (File.Exists(path)) { File.Delete(path); } foreach (string file in files) { if (File.Exists(file)) { File.Delete(file); } } // Move the ZIP and finalize File.Move(Application.temporaryCachePath + "/tempZip.zip", path); //Object.DestroyImmediate(gameObject); AssetDatabase.Refresh(); // Open scene again EditorSceneManager.OpenScene(oldScenePath); } catch (System.Exception e) { Debug.Log("Something went wrong... let's load the old scene."); if (oldScenePath != null) { EditorSceneManager.OpenScene(oldScenePath); } else { throw new System.Exception("Something went wrong and you don't have your work saved in a scene! PLEASE save your work in a scene before trying to export."); } throw e; } }
public static void ClearBakeData() { Lightmapping.ClearLightingDataAsset(); Lightmapping.ClearDiskCache(); Lightmapping.Clear(); }
public static void ClearBakedData() { Lightmapping.ClearLightingDataAsset(); Lightmapping.Clear(); }
public static void ExportPackage(GameObject gameObject, string path, string typeName, PackageJSON packageJSON) { if (exporting) { return; } string fileName = Path.GetFileName(path); string folderPath = Path.GetDirectoryName(path); string androidFileName = Path.GetFileNameWithoutExtension(path) + "_android"; string pcFileName = Path.GetFileNameWithoutExtension(path) + "_pc"; string assetBundleScenePath = $"Assets/Editor/ExportScene.unity"; string oldScenePath = gameObject.scene.path; if (oldScenePath != null) { EditorSceneManager.SaveScene(gameObject.scene); } try { // Disable scene checking because it'll be loading the scene to export SceneChecker.disabled = true; exporting = true; Selection.activeObject = gameObject; MapDescriptor mapDescriptor = gameObject.GetComponent <MapDescriptor>(); // Compute Required Versions System.Version pcRequiredVersion = ComputePcVersion(mapDescriptor); System.Version androidRequiredVersion = ComputeAndroidVersion(mapDescriptor); if (!mapDescriptor.ExportLighting) { Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); } //Check if editor folder exists just in case, since some people move it accidentally or something if (!AssetDatabase.IsValidFolder("Assets/Editor")) { Debug.LogWarning("The Editor folder does not exist. You may have installed the project incorrectly, or dragged the Editor folder into a subfolder."); Debug.LogWarning("If you experience problems with exporting, make sure your Editor folder is in the right place. If it still doesn't work, reinstall this unity project and make sure to follow the install instructions."); Debug.LogWarning("Trying to export anyways..."); AssetDatabase.CreateFolder("Assets", "Editor"); } EditorSceneManager.SaveScene(gameObject.scene, assetBundleScenePath, true); EditorSceneManager.OpenScene(assetBundleScenePath); // Destroy other maps that exist MapDescriptor[] descriptorList = Object.FindObjectsOfType <MapDescriptor>(); foreach (MapDescriptor descriptor in descriptorList) { if (descriptor.MapName != mapDescriptor.MapName) { Object.DestroyImmediate(descriptor.gameObject); } else { mapDescriptor = descriptor; gameObject = descriptor.gameObject; Selection.activeObject = gameObject; } } // Move objects that aren't in the map parent to the map parent foreach (GameObject sceneRootObject in EditorSceneManager.GetActiveScene().GetRootGameObjects()) { if (sceneRootObject != gameObject) { sceneRootObject.transform.SetParent(gameObject.transform); } } // Unpack all prefabs foreach (GameObject subObject in GameObject.FindObjectsOfType <GameObject>()) { if (PrefabUtility.GetPrefabInstanceStatus(subObject) != PrefabInstanceStatus.NotAPrefab) { PrefabUtility.UnpackPrefabInstance(PrefabUtility.GetOutermostPrefabInstanceRoot(subObject), PrefabUnpackMode.Completely, InteractionMode.AutomatedAction); } } // Skybox Stuff if (mapDescriptor.CustomSkybox != null) { // Create Fake Skybox GameObject skybox = GameObject.CreatePrimitive(PrimitiveType.Sphere); skybox.name = "Skybox"; skybox.transform.SetParent(gameObject.transform); skybox.transform.localScale = new Vector3(1000, 1000, 1000); skybox.transform.localPosition = Vector3.zero; skybox.transform.localRotation = Quaternion.identity; Object.DestroyImmediate(skybox.GetComponent <Collider>()); Material skyboxMaterial = new Material(Shader.Find("Bobbie/Outer")); skyboxMaterial.SetTexture("_Tex", mapDescriptor.CustomSkybox); skybox.GetComponent <Renderer>().material = skyboxMaterial; skybox.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } else { // Create Fake Skybox that represents the game's GameObject skyboxObject = AssetDatabase.LoadAssetAtPath("Assets/Prefabs/FakeSkybox.prefab", typeof(GameObject)) as GameObject; GameObject fakeSkybox = PrefabUtility.InstantiatePrefab(skyboxObject) as GameObject; fakeSkybox.transform.SetParent(gameObject.transform); fakeSkybox.transform.localPosition = Vector3.zero; } // Remove meshes from prefabs/triggers if (!DebugPrefabs) { StripMeshes <ObjectTrigger>(gameObject); StripMeshes <Teleporter>(gameObject); StripMeshes <TagZone>(gameObject); foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.name.StartsWith("Teleport Point")) { Object.DestroyImmediate(renderer); } } StripMeshes <ObjectTrigger>(gameObject); } foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.name.StartsWith("Spawn Point")) { bool foundTransform = false; foreach (Transform spawnPoint in mapDescriptor.SpawnPoints) { if (spawnPoint == renderer.gameObject.transform) { foundTransform = true; } } if (!foundTransform) { List <Transform> spawnPointArray = new List <Transform>(mapDescriptor.SpawnPoints); spawnPointArray.Add(renderer.gameObject.transform); mapDescriptor.SpawnPoints = spawnPointArray.ToArray(); } if (!DebugPrefabs) { Collider spawnPointCollider = renderer.gameObject.GetComponent <Collider>(); if (spawnPointCollider) { Object.DestroyImmediate(spawnPointCollider); } Object.DestroyImmediate(renderer); } } } if (mapDescriptor.SpawnPoints.Length == 0) { throw new System.Exception("No spawn points found! Add some spawn points to your map."); } // Take Screenshots with the thumbnail camera Camera thumbnailCamera = GameObject.Find("ThumbnailCamera")?.GetComponent <Camera>(); if (thumbnailCamera != null) { // Normal Screenshot Texture2D screenshot = CaptureScreenshot(thumbnailCamera, 512, 512); byte[] screenshotPNG = ImageConversion.EncodeToPNG(screenshot); File.WriteAllBytes(Application.temporaryCachePath + "/preview.png", screenshotPNG); packageJSON.config.imagePath = "preview.png"; // Cubemap Screenshot Texture2D screenshotCubemap = CaptureCubemap(thumbnailCamera, 1024, 1024); byte[] screenshotCubemapPNG = ImageConversion.EncodeToPNG(screenshotCubemap); File.WriteAllBytes(Application.temporaryCachePath + "/preview_cubemap.png", screenshotCubemapPNG); packageJSON.config.cubemapImagePath = "preview_cubemap.png"; packageJSON.config.mapColor = AverageColor(screenshotCubemap); } else { throw new System.Exception("ThumbnailCamera is missing! Make sure to add a ThumbnailCamera to your map."); } Object.DestroyImmediate(thumbnailCamera.gameObject); // Pre-Process stuff for both platforms - PC and Android. GameObject spawnPointContainer = new GameObject("SpawnPointContainer"); spawnPointContainer.transform.SetParent(gameObject.transform); spawnPointContainer.transform.localPosition = Vector3.zero; spawnPointContainer.transform.localRotation = Quaternion.identity; spawnPointContainer.transform.localScale = Vector3.one; List <string> spawnPointNames = new List <string>(); for (int i = 0; i < mapDescriptor.SpawnPoints.Length; i++) { Transform spawnPointTransform = mapDescriptor.SpawnPoints[i].gameObject.transform; Vector3 oldPos = spawnPointTransform.position; var oldRotation = spawnPointTransform.rotation; spawnPointTransform.SetParent(spawnPointContainer.transform); spawnPointTransform.rotation = oldRotation; spawnPointTransform.position = oldPos; string nameString = "SpawnPoint" + (i < 10 ? "0" + i : i.ToString()); mapDescriptor.SpawnPoints[i].gameObject.name = nameString; spawnPointNames.Add(nameString); } packageJSON.config.spawnPoints = spawnPointNames.ToArray(); // Replace tiling materials with baked versions foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { if (renderer.sharedMaterial != null && renderer.sharedMaterial.shader.name.Contains("Standard Tiling") && !renderer.sharedMaterial.shader.name.Contains("Baked")) { renderer.sharedMaterial = Object.Instantiate(renderer.sharedMaterial); renderer.sharedMaterial.shader = Shader.Find("Standard Tiling Baked"); Transform rendererTransform = renderer.gameObject.transform; Vector3 newVector = RotatePointAroundPivot(rendererTransform.lossyScale, new Vector3(0, 0, 0), rendererTransform.rotation.eulerAngles); renderer.sharedMaterial.SetVector("_ScaleVector", newVector); } } // Destroy all non-render cameras because people keep accidentally exporting them foreach (Camera camera in gameObject.GetComponentsInChildren <Camera>()) { if (camera.targetTexture == null && camera.gameObject != null) { Object.DestroyImmediate(camera.gameObject); } } //Destroy Audio listeners too since they can break sound foreach (AudioListener listener in gameObject.GetComponentsInChildren <AudioListener>()) { if (listener != null) { Object.DestroyImmediate(listener); } } // Lighting stuff. Make sure to set light stuff up and make it bigger, and bake if (mapDescriptor.ExportLighting) { foreach (Light light in Object.FindObjectsOfType <Light>()) { // needs to be redone, colors are inconsistent and can probably be made better if (light.type == LightType.Directional) { light.intensity *= 11.54f; light.color = new Color(0.3215f, 0.3215f, 0.3215f); } else { light.intensity *= 10f; } } bool baking = Lightmapping.BakeAsync(); if (baking) { Lightmapping.bakeCompleted -= PostBake; Lightmapping.bakeCompleted += PostBake; } else { throw new System.Exception("Couldn't start lightmapping."); } } else { foreach (Light light in Object.FindObjectsOfType <Light>()) { Object.DestroyImmediate(light); } Lightmapping.Clear(); Lightmapping.ClearLightingDataAsset(); PostBake(); } void PostBake() { gameObject.transform.localPosition = new Vector3(0, 5000, 0); // Save as prefab and build // PrefabUtility.SaveAsPrefabAsset(Selection.activeObject as GameObject, $"Assets/_{typeName}.prefab"); EditorSceneManager.SaveScene(gameObject.scene); AssetBundleBuild assetBundleBuild = default; assetBundleBuild.assetNames = new string[] { assetBundleScenePath }; assetBundleBuild.assetBundleName = pcFileName; // Build for PC BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, BuildTarget.StandaloneWindows64); // Do Android specific stuff here. Stripping MonoBehaviours and converting them to TextAssets, etc. // first we need to redo this bit of code because sometimes gameObject unreferences itself MapDescriptor[] descriptorList2 = Object.FindObjectsOfType <MapDescriptor>(); foreach (MapDescriptor descriptor in descriptorList2) { if (descriptor.MapName != mapDescriptor.MapName) { Object.DestroyImmediate(descriptor.gameObject); } else { mapDescriptor = descriptor; gameObject = descriptor.gameObject; Selection.activeObject = gameObject; } } StripPrefabsForQuest(gameObject); Object.DestroyImmediate(mapDescriptor); // Do it again for Android EditorSceneManager.SaveScene(gameObject.scene); // PrefabUtility.SaveAsPrefabAsset(Selection.activeObject as GameObject, $"Assets/_{typeName}.prefab"); // are these next 2 lines necessary? idk. probably test it. assetBundleBuild.assetNames = new string[] { assetBundleScenePath }; assetBundleBuild.assetBundleName = androidFileName; BuildPipeline.BuildAssetBundles(Application.temporaryCachePath, new AssetBundleBuild[] { assetBundleBuild }, 0, BuildTarget.Android); EditorPrefs.SetString("currentBuildingAssetBundlePath", folderPath); // JSON stuff packageJSON.androidFileName = androidFileName; packageJSON.pcFileName = pcFileName; packageJSON.descriptor.pcRequiredVersion = pcRequiredVersion.ToString(); packageJSON.descriptor.androidRequiredVersion = androidRequiredVersion.ToString(); string json = JsonUtility.ToJson(packageJSON, true); File.WriteAllText(Application.temporaryCachePath + "/package.json", json); // AssetDatabase.DeleteAsset($"Assets/_{typeName}.prefab"); // Delete the zip if it already exists and re-zip List <string> files = new List <string> { Application.temporaryCachePath + "/" + pcFileName, Application.temporaryCachePath + "/" + androidFileName, Application.temporaryCachePath + "/package.json", Application.temporaryCachePath + "/preview.png", Application.temporaryCachePath + "/preview_cubemap.png" }; if (File.Exists(Application.temporaryCachePath + "/tempZip.zip")) { File.Delete(Application.temporaryCachePath + "/tempZip.zip"); } CreateZipFile(Application.temporaryCachePath + "/tempZip.zip", files); // After zipping, clear some assets from the temp folder if (File.Exists(path)) { File.Delete(path); } foreach (string file in files) { if (File.Exists(file)) { File.Delete(file); } } // Move the ZIP and finalize File.Move(Application.temporaryCachePath + "/tempZip.zip", path); //Object.DestroyImmediate(gameObject); AssetDatabase.Refresh(); // Open scene again EditorSceneManager.OpenScene(oldScenePath); // Re-enable scene checking SceneChecker.disabled = false; exporting = false; EditorUtility.DisplayDialog("Exportation Successful!", "Exportation Successful!", "OK"); EditorUtility.RevealInFinder(path); } } catch (System.Exception e) { exporting = false; SceneChecker.disabled = false; Debug.Log("Something went wrong... let's load the old scene."); EditorUtility.DisplayDialog("Error!", e.Message, "OK"); if (oldScenePath != null) { EditorSceneManager.OpenScene(oldScenePath); } else { throw new System.Exception("Something went wrong and you don't have your work saved in a scene! PLEASE save your work in a scene before trying to export."); } throw e; } }
public static void GenerateNormalScene() { if (!EditorUtility.DisplayDialog("Generate normal scene", "Doing this will cause the current scene to be overwritten. Do you still wish to proceed?", "Yes", "No")) { return; } // delete all old objects GameObject[] GameObjects = (FindObjectsOfType <GameObject>() as GameObject[]); for (int i = 0; i < GameObjects.Length; i++) { DestroyImmediate(GameObjects[i]); } // root GameObject _root = new GameObject("Root"); // dynamic GameObject _dynamic = new GameObject("Dynamic"); _dynamic.transform.parent = _root.transform; // static GameObject _static = new GameObject("Static"); _static.transform.parent = _root.transform; // GUI GameObject _GUI = new GameObject("GUI"); _GUI.transform.parent = _root.transform; #region dynamic // objects GameObject _objectsDynamic = new GameObject("Objects"); _objectsDynamic.transform.parent = _dynamic.transform; // camera GameObject _objectsDynamicCameraPivot = new GameObject("Camera pivot"); _objectsDynamicCameraPivot.transform.parent = _objectsDynamic.transform; _objectsDynamicCameraPivot.transform.position = new Vector3(0, 1, -10); GameObject _objectsDynamicCameraMain = new GameObject("Main Camera"); _objectsDynamicCameraMain.transform.parent = _objectsDynamicCameraPivot.transform; _objectsDynamicCameraMain.transform.position = _objectsDynamicCameraPivot.transform.position; _objectsDynamicCameraMain.tag = "MainCamera"; _objectsDynamicCameraMain.AddComponent <AudioListener>(); Camera _mainCamera = _objectsDynamicCameraMain.AddComponent <Camera>(); _mainCamera.backgroundColor = new Color(0.0f, 0.0f, 0.0f, 1.0f); _mainCamera.farClipPlane = 500.0f; _mainCamera.allowMSAA = false; PostProcessingBehaviour _mainCameraPost = _objectsDynamicCameraMain.AddComponent <PostProcessingBehaviour>(); _mainCameraPost.profile = (PostProcessingProfile)AssetDatabase.LoadAssetAtPath("Assets/Profiles/Default Post-Processing Profile.asset", typeof(PostProcessingProfile)); // lights GameObject _lightsDynamic = new GameObject("Lights"); _lightsDynamic.transform.parent = _dynamic.transform; // light types GameObject _lightsDynamicDirectional = new GameObject("Directional"); _lightsDynamicDirectional.transform.parent = _lightsDynamic.transform; GameObject _lightsDynamicPoint = new GameObject("Point"); _lightsDynamicPoint.transform.parent = _lightsDynamic.transform; GameObject _lightsDynamicSpot = new GameObject("Spot"); _lightsDynamicSpot.transform.parent = _lightsDynamic.transform; GameObject _lightsDynamicArea = new GameObject("Area"); _lightsDynamicArea.transform.parent = _lightsDynamic.transform; // probes GameObject _probesDynamic = new GameObject("Probes"); _probesDynamic.transform.parent = _dynamic.transform; // probe types GameObject _probesDynamicLight = new GameObject("Light"); _probesDynamicLight.transform.parent = _probesDynamic.transform; GameObject _probesDynamicReflection = new GameObject("Reflection"); _probesDynamicReflection.transform.parent = _probesDynamic.transform; // Audio GameObject _audioDynamic = new GameObject("Audio"); _audioDynamic.transform.parent = _dynamic.transform; // Audio types GameObject _audioDynamicAmbient = new GameObject("Ambient"); _audioDynamicAmbient.transform.parent = _audioDynamic.transform; GameObject _audioDynamicMusic = new GameObject("Music"); _audioDynamicMusic.transform.parent = _audioDynamic.transform; #endregion #region static // objects GameObject _objectsStatic = new GameObject("Objects"); _objectsStatic.transform.parent = _static.transform; // lights GameObject _lightsStatic = new GameObject("Lights"); _lightsStatic.transform.parent = _static.transform; // light types GameObject _lightsStaticDirectional = new GameObject("Directional"); _lightsStaticDirectional.transform.parent = _lightsStatic.transform; GameObject _lightsStaticDirectionalSun = new GameObject("Sun"); _lightsStaticDirectionalSun.transform.parent = _lightsStaticDirectional.transform; _lightsStaticDirectionalSun.transform.position = new Vector3(0, 3, 0); _lightsStaticDirectionalSun.transform.rotation = Quaternion.Euler(50, -30, 0); Light _sunLight = _lightsStaticDirectionalSun.AddComponent <Light>(); _sunLight.lightmapBakeType = LightmapBakeType.Baked; _sunLight.color = new Color(1.0f, 1.0f, 1.0f, 1.0f); _sunLight.type = LightType.Directional; _sunLight.intensity = 1.0f; GameObject _lightsStaticPoint = new GameObject("Point"); _lightsStaticPoint.transform.parent = _lightsStatic.transform; GameObject _lightsStaticSpot = new GameObject("Spot"); _lightsStaticSpot.transform.parent = _lightsStatic.transform; GameObject _lightsStaticArea = new GameObject("Area"); _lightsStaticArea.transform.parent = _lightsStatic.transform; // probes GameObject _probesStatic = new GameObject("Probes"); _probesStatic.transform.parent = _static.transform; // probe types GameObject _probesStaticLight = new GameObject("Light"); _probesStaticLight.transform.parent = _probesStatic.transform; GameObject _probesStaticReflection = new GameObject("Reflection"); _probesStaticReflection.transform.parent = _probesStatic.transform; #endregion #region GUI GameObject _canvas = new GameObject("Canvas"); _canvas.transform.parent = _GUI.transform; Canvas _canvasCanvas = _canvas.AddComponent <Canvas>(); _canvasCanvas.renderMode = RenderMode.ScreenSpaceOverlay; CanvasScaler _canvasScaler = _canvas.AddComponent <CanvasScaler>(); _canvasScaler.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; _canvasScaler.referenceResolution = new Vector2(1920, 1080); _canvas.AddComponent <GraphicRaycaster>(); _canvas.AddComponent <EventSystem>(); _canvas.AddComponent <StandaloneInputModule>(); #endregion #region Scene settings RenderSettings.sun = _sunLight; RenderSettings.defaultReflectionResolution = 2048; Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; Lightmapping.ClearLightingDataAsset(); Lightmapping.realtimeGI = true; Lightmapping.bakedGI = true; LightmapEditorSettings.reflectionCubemapCompression = ReflectionCubemapCompression.Uncompressed; LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveCPU; LightmapEditorSettings.textureCompression = false; LightmapEditorSettings.realtimeResolution = 8.0f; LightmapEditorSettings.padding = 4; #if UNITY_2018_1_OR_NEWER LightmapEditorSettings.maxAtlasSize = 2048; #else LightmapEditorSettings.maxAtlasWidth = 2048; LightmapEditorSettings.maxAtlasHeight = 2048; #endif LightmapEditorSettings.sampling = LightmapEditorSettings.Sampling.Auto; LightmapEditorSettings.enableAmbientOcclusion = true; LightmapEditorSettings.aoExponentDirect = 1.0f; #endregion }
public static void GenerateGUIlScene() { if (!EditorUtility.DisplayDialog("Generate gui scene", "Doing this will cause the current scene to be overwritten. Do you still wish to proceed?", "Yes", "No")) { return; } // delete all old objects GameObject[] GameObjects = (FindObjectsOfType <GameObject>() as GameObject[]); for (int i = 0; i < GameObjects.Length; i++) { DestroyImmediate(GameObjects[i]); } // root GameObject _root = new GameObject("Root"); // dynamic GameObject _dynamic = new GameObject("Dynamic"); _dynamic.transform.parent = _root.transform; // GUI GameObject _GUI = new GameObject("GUI"); _GUI.transform.parent = _root.transform; #region dynamic // objects GameObject _objectsDynamic = new GameObject("Objects"); _objectsDynamic.transform.parent = _dynamic.transform; // camera GameObject _objectsDynamicCameraPivot = new GameObject("Camera pivot"); _objectsDynamicCameraPivot.transform.parent = _objectsDynamic.transform; _objectsDynamicCameraPivot.transform.position = new Vector3(0, 0, 0); GameObject _objectsDynamicCameraMain = new GameObject("Main Camera"); _objectsDynamicCameraMain.transform.parent = _objectsDynamicCameraPivot.transform; _objectsDynamicCameraMain.transform.position = _objectsDynamicCameraPivot.transform.position; _objectsDynamicCameraMain.tag = "MainCamera"; _objectsDynamicCameraMain.AddComponent <AudioListener>(); Camera _mainCamera = _objectsDynamicCameraMain.AddComponent <Camera>(); _mainCamera.backgroundColor = new Color(0.0f, 0.0f, 0.0f, 1.0f); _mainCamera.farClipPlane = 1.0f; _mainCamera.allowMSAA = false; // Audio GameObject _audioDynamic = new GameObject("Audio"); _audioDynamic.transform.parent = _dynamic.transform; // Audio types GameObject _audioDynamicAmbient = new GameObject("Ambient"); _audioDynamicAmbient.transform.parent = _audioDynamic.transform; GameObject _audioDynamicMusic = new GameObject("Music"); _audioDynamicMusic.transform.parent = _audioDynamic.transform; #endregion #region GUI // canvas GameObject _canvas = new GameObject("Canvas"); _canvas.transform.parent = _GUI.transform; Canvas _canvasCanvas = _canvas.AddComponent <Canvas>(); _canvasCanvas.renderMode = RenderMode.ScreenSpaceOverlay; CanvasScaler _canvasScaler = _canvas.AddComponent <CanvasScaler>(); _canvasScaler.uiScaleMode = UnityEngine.UI.CanvasScaler.ScaleMode.ScaleWithScreenSize; _canvasScaler.referenceResolution = new Vector2(1920, 1080); _canvas.AddComponent <GraphicRaycaster>(); _canvas.AddComponent <EventSystem>(); _canvas.AddComponent <StandaloneInputModule>(); // background GameObject _backgound = new GameObject("Background"); _backgound.transform.parent = _canvas.transform; RectTransform _backgroundTransform = _backgound.AddComponent <RectTransform>(); _backgroundTransform.anchoredPosition = new Vector2(0, 0); _backgroundTransform.sizeDelta = new Vector2(1920, 1080); Image _backgoundImage = _backgound.AddComponent <Image>(); _backgoundImage.sprite = (Sprite)AssetDatabase.LoadAssetAtPath("Assets/Sprites/White_32.png", typeof(Sprite)); _backgoundImage.color = new Color(0.0f, 0.0f, 0.0f, 1.0f); _backgoundImage.raycastTarget = false; #endregion #region Scene settings RenderSettings.defaultReflectionResolution = 16; Lightmapping.giWorkflowMode = Lightmapping.GIWorkflowMode.OnDemand; Lightmapping.ClearLightingDataAsset(); Lightmapping.realtimeGI = false; Lightmapping.bakedGI = false; LightmapEditorSettings.reflectionCubemapCompression = ReflectionCubemapCompression.Uncompressed; LightmapEditorSettings.lightmapper = LightmapEditorSettings.Lightmapper.ProgressiveCPU; LightmapEditorSettings.textureCompression = false; LightmapEditorSettings.realtimeResolution = 8.0f; LightmapEditorSettings.padding = 4; #if UNITY_2018_1_OR_NEWER LightmapEditorSettings.maxAtlasSize = 2048; #else LightmapEditorSettings.maxAtlasWidth = 2048; LightmapEditorSettings.maxAtlasHeight = 2048; #endif LightmapEditorSettings.sampling = LightmapEditorSettings.Sampling.Auto; LightmapEditorSettings.enableAmbientOcclusion = true; LightmapEditorSettings.aoExponentDirect = 1.0f; #endregion }