SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
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.

84 lines
3.5 KiB

4 years ago
  1. using System.Linq;
  2. using UnityEditor;
  3. using UnityEditor.Build;
  4. using UnityEditor.Build.Reporting;
  5. namespace UnityEngine.XR.ARKit
  6. {
  7. /// <summary>
  8. /// The build processor that makes sure that any custom configuration is passed to the
  9. /// ARKit Loader at runtime.
  10. ///
  11. /// Custom configuration instances that are stored in EditorBuildSettings are not copied to the target build
  12. /// as they are considered unreferenced assets. In order to get them to the runtime side of things, they need
  13. /// to be serialized to the build app and deserialized at runtime. Previously this would be a manual process
  14. /// requiring the implementor to manually serialize to some location that can then be read from to deserialize
  15. /// at runtime. With the new PlayerSettings Preloaded Assets API we can now just add our asset to the preloaded
  16. /// list and have it be instantiated at app launch.
  17. ///
  18. /// Note that the preloaded assets are only notified with Awake, so anything you want or need to do with the
  19. /// asset after launch needs to be handled there.
  20. ///
  21. /// More info on APIs used here:
  22. /// * <a href="https://docs.unity3d.com/ScriptReference/EditorBuildSettings.html">EditorBuildSettings</a>
  23. /// * <a href="https://docs.unity3d.com/ScriptReference/PlayerSettings.GetPreloadedAssets.html">PlayerSettings.GetPreloadedAssets</a>
  24. /// * <a href="https://docs.unity3d.com/ScriptReference/PlayerSettings.SetPreloadedAssets.html">PlayerSettings.SetPreloadedAssets</a>
  25. /// </summary>
  26. public class ARKitLoaderBuildProcessor : IPreprocessBuildWithReport, IPostprocessBuildWithReport
  27. {
  28. public int callbackOrder
  29. {
  30. get { return 0; }
  31. }
  32. void CleanOldSettings()
  33. {
  34. UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
  35. if (preloadedAssets == null)
  36. return;
  37. var oldSettings = from s in preloadedAssets
  38. where s != null && s.GetType() == typeof(ARKitLoaderSettings)
  39. select s;
  40. if (oldSettings != null && oldSettings.Any())
  41. {
  42. var assets = preloadedAssets.ToList();
  43. foreach (var s in oldSettings)
  44. {
  45. assets.Remove(s);
  46. }
  47. PlayerSettings.SetPreloadedAssets(assets.ToArray());
  48. }
  49. }
  50. public void OnPreprocessBuild(BuildReport report)
  51. {
  52. // Always remember to cleanup preloaded assets after build to make sure we don't
  53. // dirty later builds with assets that may not be needed or are out of date.
  54. CleanOldSettings();
  55. ARKitLoaderSettings settings = null;
  56. EditorBuildSettings.TryGetConfigObject(ARKitLoaderConstants.k_SettingsKey, out settings);
  57. if (settings == null)
  58. return;
  59. UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
  60. if (!preloadedAssets.Contains(settings))
  61. {
  62. var assets = preloadedAssets.ToList();
  63. assets.Add(settings);
  64. PlayerSettings.SetPreloadedAssets(assets.ToArray());
  65. }
  66. }
  67. public void OnPostprocessBuild(BuildReport report)
  68. {
  69. // Always remember to cleanup preloaded assets after build to make sure we don't
  70. // dirty later builds with assets that may not be needed or are out of date.
  71. CleanOldSettings();
  72. }
  73. }
  74. }