No Description
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.

ProjectWideActionsBuildProvider.cs 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
  2. using System;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEditor.Build;
  6. using UnityEditor.Build.Reporting;
  7. using UnityEngine.InputSystem.Utilities;
  8. namespace UnityEngine.InputSystem.Editor
  9. {
  10. internal class ProjectWideActionsBuildProvider : IPreprocessBuildWithReport, IPostprocessBuildWithReport
  11. {
  12. private Object m_Asset;
  13. public int callbackOrder => 0;
  14. // In the editor, we keep track of the appointed project-wide action asset through EditorBuildSettings.
  15. internal const string EditorBuildSettingsActionsConfigKey = "com.unity.input.settings.actions";
  16. /// <summary>
  17. /// Holds an editor build setting for which InputActionAsset to be included as a preloaded asset in
  18. /// player builds.
  19. /// </summary>
  20. internal static InputActionAsset actionsToIncludeInPlayerBuild
  21. {
  22. get
  23. {
  24. // Attempt to get any persisted configuration
  25. EditorBuildSettings.TryGetConfigObject(EditorBuildSettingsActionsConfigKey, out InputActionAsset value);
  26. return value;
  27. }
  28. set
  29. {
  30. // Get the current persisted configuration and remove tag when changed
  31. if (EditorBuildSettings.TryGetConfigObject(EditorBuildSettingsActionsConfigKey,
  32. out InputActionAsset current))
  33. {
  34. current.m_IsProjectWide = false;
  35. }
  36. // Get asset path (note that this will fail if this is an in-memory object)
  37. var path = AssetDatabase.GetAssetPath(value);
  38. if (string.IsNullOrEmpty(path))
  39. {
  40. // Remove the object to not keep a broken reference
  41. EditorBuildSettings.RemoveConfigObject(EditorBuildSettingsActionsConfigKey);
  42. }
  43. else
  44. {
  45. // Add configuration object as a persisted setting
  46. value.m_IsProjectWide = true;
  47. EditorBuildSettings.AddConfigObject(EditorBuildSettingsActionsConfigKey, value, true);
  48. }
  49. }
  50. }
  51. public void OnPreprocessBuild(BuildReport report)
  52. {
  53. // Make sure flag is set to indicate project-wide in build
  54. var actions = actionsToIncludeInPlayerBuild;
  55. if (actions != null)
  56. actions.m_IsProjectWide = true;
  57. // Add asset
  58. m_Asset = BuildProviderHelpers.PreProcessSinglePreloadedAsset(actions);
  59. }
  60. public void OnPostprocessBuild(BuildReport report)
  61. {
  62. BuildProviderHelpers.PostProcessSinglePreloadedAsset(ref m_Asset);
  63. }
  64. }
  65. }
  66. #endif // UNITY_EDITOR && UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS