static void CreateSceneSettingsGameObject(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var settings = CoreEditorUtils.CreateGameObject(parent, "Sky and Fog Volume"); GameObjectUtility.SetParentAndAlign(settings, menuCommand.context as GameObject); Undo.RegisterCreatedObjectUndo(settings, "Create " + settings.name); Selection.activeObject = settings; var profile = VolumeProfileFactory.CreateVolumeProfile(settings.scene, "Sky and Fog Settings"); var visualEnv = VolumeProfileFactory.CreateVolumeComponent <VisualEnvironment>(profile, true, false); visualEnv.skyType.value = SkySettings.GetUniqueID <PhysicallyBasedSky>(); visualEnv.skyAmbientMode.overrideState = false; VolumeProfileFactory.CreateVolumeComponent <PhysicallyBasedSky>(profile, false, false); var fog = VolumeProfileFactory.CreateVolumeComponent <Fog>(profile, false, true); fog.enabled.Override(true); fog.enableVolumetricFog.Override(true); var volume = settings.AddComponent <Volume>(); volume.isGlobal = true; volume.sharedProfile = profile; }
public override void Action(int instanceId, string pathName, string resourceFile) { var profile = VolumeProfileFactory.CreateVolumeProfileAtPath(pathName); ProjectWindowUtil.ShowCreatedAsset(profile); Assign(profile); }
static void CreateSceneSettingsGameObject(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var sceneSettings = CoreEditorUtils.CreateGameObject(parent, "Scene Settings"); GameObjectUtility.SetParentAndAlign(sceneSettings, menuCommand.context as GameObject); Undo.RegisterCreatedObjectUndo(sceneSettings, "Create " + sceneSettings.name); Selection.activeObject = sceneSettings; var profile = VolumeProfileFactory.CreateVolumeProfile(sceneSettings.scene, "Scene Settings"); VolumeProfileFactory.CreateVolumeComponent <HDShadowSettings>(profile, true, false); var visualEnv = VolumeProfileFactory.CreateVolumeComponent <VisualEnvironment>(profile, true, false); visualEnv.skyType.value = SkySettings.GetUniqueID <ProceduralSky>(); visualEnv.fogType.value = FogType.Exponential; VolumeProfileFactory.CreateVolumeComponent <ProceduralSky>(profile, true, false); VolumeProfileFactory.CreateVolumeComponent <ExponentialFog>(profile, true, true); var volume = sceneSettings.AddComponent <Volume>(); volume.isGlobal = true; volume.sharedProfile = profile; var bakingSky = sceneSettings.AddComponent <BakingSky>(); bakingSky.profile = volume.sharedProfile; bakingSky.bakingSkyUniqueID = SkySettings.GetUniqueID <ProceduralSky>(); }
static void CreateSceneSettingsGameObject(MenuCommand menuCommand) { var parent = menuCommand.context as GameObject; var settings = CoreEditorUtils.CreateGameObject("Sky and Fog Global Volume", parent); var profile = VolumeProfileFactory.CreateVolumeProfile(settings.scene, "Sky and Fog Settings"); var visualEnv = VolumeProfileFactory.CreateVolumeComponent <VisualEnvironment>(profile, true, false); visualEnv.skyType.value = SkySettings.GetUniqueID <PhysicallyBasedSky>(); visualEnv.skyAmbientMode.overrideState = false; VolumeProfileFactory.CreateVolumeComponent <PhysicallyBasedSky>(profile, false, false); var fog = VolumeProfileFactory.CreateVolumeComponent <Fog>(profile, false, true); fog.enabled.Override(true); fog.enableVolumetricFog.Override(true); var volume = settings.AddComponent <Volume>(); volume.isGlobal = true; volume.sharedProfile = profile; }
static void CreateCustomGameObject(MenuCommand menuCommand) { //var sceneSettings = new GameObject("Scene Settings"); //GameObjectUtility.SetParentAndAlign(sceneSettings, menuCommand.context as GameObject); //Undo.RegisterCreatedObjectUndo(sceneSettings, "Create " + sceneSettings.name); //Selection.activeObject = sceneSettings; //sceneSettings.AddComponent<SceneSettings>(); var parent = menuCommand.context as GameObject; var scenesettings = CoreEditorUtils.CreateGameObject(parent, "Scene Settings"); GameObjectUtility.SetParentAndAlign(scenesettings, menuCommand.context as GameObject); Selection.activeObject = scenesettings; var profile = VolumeProfileFactory.CreateVolumeProfile(scenesettings.scene, "Scene Settings"); VolumeProfileFactory.CreateVolumeComponent <CommonSettings>(profile, true, false); var volume = scenesettings.AddComponent <Volume>(); volume.isGlobal = true; volume.sharedProfile = profile; }
static void UpgradeFogVolumeComponents(MenuCommand menuCommand) { void OverrideCommonParameters(AtmosphericScattering input, Fog output) { if (input.colorMode.overrideState) { output.colorMode.Override(input.colorMode.value); } if (input.color.overrideState) { output.color.Override(input.color.value); } if (input.maxFogDistance.overrideState) { output.maxFogDistance.Override(input.maxFogDistance.value); } if (input.mipFogMaxMip.overrideState) { output.mipFogMaxMip.Override(input.mipFogMaxMip.value); } if (input.mipFogNear.overrideState) { output.mipFogNear.Override(input.mipFogNear.value); } if (input.mipFogFar.overrideState) { output.mipFogFar.Override(input.mipFogFar.value); } if (input.tint.overrideState) { output.tint.Override(input.tint.value); } } Fog CreateFogComponentIfNeeded(VolumeProfile profile) { Fog fogComponent = null; if (!profile.TryGet(out fogComponent)) { fogComponent = VolumeProfileFactory.CreateVolumeComponent <Fog>(profile, false, false); } return(fogComponent); } if (!EditorUtility.DisplayDialog(DialogText.title, "This will upgrade all Volume Profiles containing Exponential or Volumetric Fog components to the new Fog component. " + DialogText.projectBackMessage, DialogText.proceed, DialogText.cancel)) { return; } var profilePathList = AssetDatabase.FindAssets("t:VolumeProfile", new string[] { "Assets" }); int profileCount = profilePathList.Length; int profileIndex = 0; foreach (string guid in profilePathList) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); profileIndex++; if (EditorUtility.DisplayCancelableProgressBar("Upgrade Fog Volume Components", string.Format("({0} of {1}) {2}", profileIndex, profileCount, assetPath), (float)profileIndex / (float)profileCount)) { break; } VolumeProfile profile = AssetDatabase.LoadAssetAtPath(assetPath, typeof(VolumeProfile)) as VolumeProfile; if (profile.TryGet <VisualEnvironment>(out var visualEnv)) { if (visualEnv.fogType.value == FogType.Exponential || visualEnv.fogType.value == FogType.Volumetric) { var fog = CreateFogComponentIfNeeded(profile); fog.enabled.Override(true); } } if (profile.TryGet <ExponentialFog>(out var expFog)) { var fog = CreateFogComponentIfNeeded(profile); // We only migrate distance because the height parameters are not compatible. if (expFog.fogDistance.overrideState) { fog.meanFreePath.Override(expFog.fogDistance.value); } OverrideCommonParameters(expFog, fog); EditorUtility.SetDirty(profile); } if (profile.TryGet <VolumetricFog>(out var volFog)) { var fog = CreateFogComponentIfNeeded(profile); fog.enableVolumetricFog.Override(true); if (volFog.meanFreePath.overrideState) { fog.meanFreePath.Override(volFog.meanFreePath.value); } if (volFog.albedo.overrideState) { fog.albedo.Override(volFog.albedo.value); } if (volFog.baseHeight.overrideState) { fog.baseHeight.Override(volFog.baseHeight.value); } if (volFog.maximumHeight.overrideState) { fog.maximumHeight.Override(volFog.maximumHeight.value); } if (volFog.anisotropy.overrideState) { fog.anisotropy.Override(volFog.anisotropy.value); } if (volFog.globalLightProbeDimmer.overrideState) { fog.globalLightProbeDimmer.Override(volFog.globalLightProbeDimmer.value); } OverrideCommonParameters(volFog, fog); EditorUtility.SetDirty(profile); } if (profile.TryGet <VolumetricLightingController>(out var volController)) { var fog = CreateFogComponentIfNeeded(profile); if (volController.depthExtent.overrideState) { fog.depthExtent.Override(volController.depthExtent.value); } if (volController.sliceDistributionUniformity.overrideState) { fog.sliceDistributionUniformity.Override(volController.sliceDistributionUniformity.value); } EditorUtility.SetDirty(profile); } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorUtility.ClearProgressBar(); }
/// <summary> /// Manages the adding of components to generated scene objects. Supports generating sub-assets for those components that need them /// </summary> private static void AddNewComponent(GameObject go, COMPONENT_TYPE type) { switch (type) { case COMPONENT_TYPE.CAMERA: { var cam = go.GetOrAddComponent <Camera>(); break; } case COMPONENT_TYPE.AUDIO_LISTENER: { go.GetOrAddComponent <AudioListener>(); break; } case COMPONENT_TYPE.CINEMACHINE_BRAIN: { go.GetOrAddComponent <CinemachineBrain>(); break; } case COMPONENT_TYPE.PLAYABLE_DIRECTOR: { var pd = go.GetOrAddComponent <PlayableDirector>(); if (!AssetDatabase.IsValidFolder("Assets/Timeline")) { AssetDatabase.CreateFolder("Assets", "Timeline"); } var ta = ScriptableObjectUtility.CreateAssetType <TimelineAsset>("Assets/Timeline", "MasterTimeline.asset"); pd.playableAsset = ta; break; } case COMPONENT_TYPE.POST_LAYER: { var post = go.GetOrAddComponent <PostProcessLayer>(); var postLayer = 1 << 8; // post layer is 8 by default post.volumeLayer = postLayer; // LayerMask.NameToLayer("PostProcessing"); <= this doesn't work for some reason post.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing; break; } case COMPONENT_TYPE.POST_VOLUME: { var post = go.GetOrAddComponent <PostProcessVolume>(); post.isGlobal = true; var targetName = go.name; var scene = go.scene; // create a new profile var asset = ProfileFactory.CreatePostProcessProfile(scene, scene.name); // find & load the template // FIXME: should allow for user templates as well var templatePath = Settings.TEMPLATECONFIGPATH + "Default_Profiles/Default_PostProfile.asset"; var template = AssetDatabase.LoadAssetAtPath(templatePath, typeof(PostProcessProfile)) as PostProcessProfile; if (template != null) { // add all of the settings to the template foreach (var effect in template.settings) { asset.AddSettings(effect); } } else { Debug.Log("Could not find template post profile?"); } post.profile = asset; post.isGlobal = true; post.gameObject.layer = LayerMask.NameToLayer("PostProcessing"); break; } case COMPONENT_TYPE.SCENE_VOLUME: { #if USING_HDRP var vol = go.GetOrAddComponent <Volume>(); vol.isGlobal = true; var targetName = go.name; var scene = go.scene; // FIXME: should load a volume profile from a template & // copy the components from one in the package as a base / starting point var asset = VolumeProfileFactory.CreateVolumeProfile(scene, targetName); vol.profile = asset; vol.isGlobal = true; #endif break; } case COMPONENT_TYPE.RENDER_SETTINGS: { var settings = go.GetOrAddComponent <RenderSettings>(); // add our basic low / high detail levels to start var levels = new List <DetailLevel>() { new DetailLevel() { name = "Low", reflectionProbes = false, planarReflectionProbes = false, }, new DetailLevel() { name = "High", reflectionProbes = true, planarReflectionProbes = true, } }; settings.detailLevels.AddRange(levels); break; } default: { Debug.Log("unrecognized component type"); break; } } }