private bool ConvertVolumeComponent(BIRPRendering.PostProcessVolume oldVolume, StringBuilder errorString) { // Don't convert if it appears to already have been converted. if (oldVolume.GetComponent <Volume>()) { return(true); } var gameObject = oldVolume.gameObject; var newVolume = gameObject.AddComponent <Volume>(); newVolume.priority = oldVolume.priority; newVolume.weight = oldVolume.weight; newVolume.blendDistance = oldVolume.blendDistance; newVolume.isGlobal = oldVolume.isGlobal; newVolume.enabled = oldVolume.enabled; var success = true; newVolume.sharedProfile = ConvertVolumeProfileAsset(oldVolume.sharedProfile, errorString, ref success); if (PrefabUtility.IsPartOfPrefabAsset(oldVolume)) { postConversionDestroyables.Add(oldVolume); } else { Object.DestroyImmediate(oldVolume, allowDestroyingAssets: true); } EditorUtility.SetDirty(gameObject); return(success); }
private bool ConvertVolumeInstance(BIRPRendering.PostProcessVolume oldVolume, StringBuilder errorString) { // First get a reference to the local instance of the converted component // which may require immediately converting it at its origin location first. var newVolumeInstance = oldVolume.GetComponent <Volume>(); if (!newVolumeInstance) { var oldVolumeOrigin = PrefabUtility.GetCorrespondingObjectFromSource(oldVolume); if (!ConvertVolumeComponent(oldVolumeOrigin, errorString)) { return(false); } PrefabUtility.SavePrefabAsset(oldVolumeOrigin.gameObject); newVolumeInstance = oldVolume.GetComponent <Volume>(); if (!newVolumeInstance) { errorString.AppendLine( "PPv2 PostProcessVolume failed to be converted because the instance object did not inherit the converted Prefab source."); return(false); } } bool success = true; var oldModifications = PrefabUtility.GetPropertyModifications(oldVolume); foreach (var oldModification in oldModifications) { if (oldModification.target is BIRPRendering.PostProcessVolume) { if (oldModification.propertyPath.EndsWith("priority", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.priority = oldVolume.priority; } else if (oldModification.propertyPath.EndsWith("weight", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.weight = oldVolume.weight; } else if (oldModification.propertyPath.EndsWith("blendDistance", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.blendDistance = oldVolume.blendDistance; } else if (oldModification.propertyPath.EndsWith("isGlobal", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.isGlobal = oldVolume.isGlobal; } else if (oldModification.propertyPath.EndsWith("enabled", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.enabled = oldVolume.enabled; } else if (oldModification.propertyPath.EndsWith("sharedProfile", StringComparison.InvariantCultureIgnoreCase)) { newVolumeInstance.sharedProfile = ConvertVolumeProfileAsset(oldVolume.sharedProfile, errorString, ref success); } EditorUtility.SetDirty(newVolumeInstance); } } return(success); }