Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FullScreenPassRendererFeature.migration.cs 3.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEngine.Rendering.Universal;
  4. public partial class FullScreenPassRendererFeature : ISerializationCallbackReceiver
  5. {
  6. private enum Version
  7. {
  8. // * Uninitialised is a special last entry that will only ever be set on newly created objects or objects
  9. // which were previously serialised with no Version member at all.
  10. // * We distinguish between new objects and the unversioned objects based on if we first see this value during
  11. // serialization or during deserialization respectively.
  12. Uninitialised = -1,
  13. Initial,
  14. AddFetchColorBufferCheckbox,
  15. // These two entries should remain at the end of the enum and new version should be added before Count
  16. Count,
  17. Latest = Count - 1,
  18. }
  19. [SerializeField]
  20. [HideInInspector]
  21. private Version m_Version = Version.Uninitialised;
  22. private void UpgradeIfNeeded()
  23. {
  24. // As we rely on serialization/deserialization order to initialize the version as player might have restricions
  25. // on when and if serialization is done skipping any upgrading at runtime to avoid accidentally doing the
  26. // upgrade on the latest version. Upgrading at runtime does not really have much utility as it would mean
  27. // that the asset would need to have been produced in an editor which is an earlier build version than the player
  28. #if UNITY_EDITOR
  29. if (m_Version == Version.Latest)
  30. return;
  31. if(m_Version == Version.Initial)
  32. {
  33. // * Previously the ScriptableRenderPassInput.Color requirement was repurposed to mean "copy the active
  34. // color target" even though it is typically used to request '_CameraOpaqueTexture' and the copy color pass.
  35. // * From now on, the "Fetch Color Buffer" choice will be a separate checkbox to remove the inconsistent
  36. // meaning and to allow using the '_CameraOpaqueTexture' if one wants to as well.
  37. fetchColorBuffer = requirements.HasFlag(ScriptableRenderPassInput.Color);
  38. // As the Color flag was being masked out during actual rendering we can safely disable it.
  39. requirements &= ~ScriptableRenderPassInput.Color;
  40. m_Version++;
  41. }
  42. // Put the next upgrader in an "if" here (not "else if" as they migh all need to run)
  43. // Making sure SetDirty is called once after deserialization
  44. EditorApplication.delayCall += () =>
  45. {
  46. if (this)
  47. EditorUtility.SetDirty(this);
  48. };
  49. #endif
  50. }
  51. /// <inheritdoc/>
  52. void ISerializationCallbackReceiver.OnBeforeSerialize()
  53. {
  54. // This should only ever be true the first time we're serializing a newly created object
  55. if (m_Version == Version.Uninitialised)
  56. m_Version = Version.Latest;
  57. }
  58. /// <inheritdoc/>
  59. void ISerializationCallbackReceiver.OnAfterDeserialize()
  60. {
  61. // The 'Uninitialised' version is expected to only occur during deserialization for objects that were previously
  62. // serialized before we added the m_Version field
  63. if (m_Version == Version.Uninitialised)
  64. m_Version = Version.Initial;
  65. UpgradeIfNeeded();
  66. }
  67. }