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