private void SetupSceneWithPreset(ProfilePreset preset) { ClearSkyControllers(); Scene currentScene = SceneManager.GetActiveScene(); string sceneDir = Path.GetDirectoryName(currentScene.path); string profileContainerName = currentScene.name + " - Sky Data"; string profileContainerDir = SkyEditorUtility.GenerateUniqueFolder(sceneDir, profileContainerName, true); // Create new sky controller. GameObject skySystemPrefab = SkyEditorUtility.LoadEditorPrefab(SKY_CONTROLLER_PREFAB); if (skySystemPrefab == null) { Debug.LogError("Failed to locate sky controller prefab"); return; } TimeOfDayController tc = Instantiate(skySystemPrefab).GetComponent <TimeOfDayController>(); tc.name = SKY_CONTROLLER_PREFAB; // Create a new sky profile. string profileAssetPath = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyProfile", ".asset"); AssetDatabase.CopyAsset(preset.assetPath, profileAssetPath); // Load the new SKy Profile. SkyProfile profile = AssetDatabase.LoadAssetAtPath(profileAssetPath, typeof(SkyProfile)) as SkyProfile; if (profile == null) { Debug.LogError("Failed to duplicate profile"); return; } // Create the skybox material. Material skyboxMaterial = new Material(GetBestShaderForSkyProfile(profile)); string skyboxPath = SkyEditorUtility.GenerateUniqueFilename(profileContainerDir, "SkyboxMaterial", ".mat"); AssetDatabase.CreateAsset(skyboxMaterial, skyboxPath); profile.skyboxMaterial = skyboxMaterial; // Link things together. tc.skyProfile = profile; tc.skyProfile.skyboxMaterial = skyboxMaterial; tc.skyTime = .22f; // Configure the profile a bit and setup in the current scene. SkyProfileEditor.ApplyKeywordsToMaterial(tc.skyProfile, skyboxMaterial); SkyProfileEditor.forceRebuildProfileId = profile.GetInstanceID(); RenderSettings.skybox = skyboxMaterial; ApplyDefaultSettings(profile); // Drop a lightning spawn area into the scene in case user enables the feature. if (!ContainsLightningSpawnArea()) { CreateLightningSpawnArea(); } EditorUtility.SetDirty(skyboxMaterial); EditorUtility.SetDirty(tc.skyProfile); EditorUtility.SetDirty(tc); EditorSceneManager.MarkSceneDirty(SceneManager.GetActiveScene()); Selection.activeObject = tc.skyProfile; }