RenderStreamingSettingBuildProvider.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Linq;
  2. using UnityEditor;
  3. using UnityEditor.Build;
  4. using UnityEditor.Build.Reporting;
  5. namespace Unity.RenderStreaming.Editor
  6. {
  7. internal class RenderStreamingSettingBuildProvider : IPreprocessBuildWithReport, IPostprocessBuildWithReport
  8. {
  9. public int callbackOrder => 0;
  10. public void OnPreprocessBuild(BuildReport report)
  11. {
  12. if (RenderStreaming.Settings == null)
  13. return;
  14. // If we operate on temporary object instead of input setting asset,
  15. // adding temporary asset would result in preloadedAssets containing null object "{fileID: 0}".
  16. // Hence we ignore adding temporary objects to preloaded assets.
  17. if (!EditorUtility.IsPersistent(RenderStreaming.Settings))
  18. return;
  19. // Add InputSettings object assets, if it's not in there already.
  20. var preloadedAssets = PlayerSettings.GetPreloadedAssets();
  21. if (!preloadedAssets.Contains(RenderStreaming.Settings))
  22. {
  23. ArrayHelpers.Append(ref preloadedAssets, RenderStreaming.Settings);
  24. PlayerSettings.SetPreloadedAssets(preloadedAssets);
  25. }
  26. }
  27. public void OnPostprocessBuild(BuildReport report)
  28. {
  29. // Revert back to original state by removing all render streaming settings from preloaded assets.
  30. var preloadedAssets = PlayerSettings.GetPreloadedAssets();
  31. while (preloadedAssets != null && preloadedAssets.Length > 0)
  32. {
  33. var target = preloadedAssets.FirstOrDefault(x => x is RenderStreamingSettings);
  34. var index = ArrayHelpers.IndexOf(preloadedAssets, target);
  35. if (index != -1)
  36. {
  37. ArrayHelpers.EraseAt(ref preloadedAssets, index);
  38. PlayerSettings.SetPreloadedAssets(preloadedAssets);
  39. }
  40. else
  41. break;
  42. }
  43. }
  44. }
  45. }