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.

iOSPostProcessBuild.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #if UNITY_EDITOR
  2. using System.IO;
  3. using UnityEditor;
  4. using UnityEditor.Callbacks;
  5. using UnityEngine;
  6. using UnityEngine.InputSystem;
  7. namespace UnityEngine.InputSystem
  8. {
  9. internal class iOSPostProcessBuild
  10. {
  11. [PostProcessBuild]
  12. public static void UpdateInfoPList(BuildTarget buildTarget, string pathToBuiltProject)
  13. {
  14. if (buildTarget != BuildTarget.iOS)
  15. return;
  16. var settings = InputSystem.settings.iOS;
  17. if (!settings.motionUsage.enabled)
  18. return;
  19. var plistPath = pathToBuiltProject + "/Info.plist";
  20. var contents = File.ReadAllText(plistPath);
  21. var description = InputSystem.settings.iOS.motionUsage.usageDescription;
  22. #if UNITY_IOS || UNITY_TVOS
  23. var plist = new UnityEditor.iOS.Xcode.PlistDocument();
  24. plist.ReadFromString(contents);
  25. var root = plist.root;
  26. var buildKey = "NSMotionUsageDescription";
  27. if (root[buildKey] != null)
  28. Debug.LogWarning($"{buildKey} is already present in Info.plist, the value will be overwritten.");
  29. root.SetString(buildKey, description);
  30. File.WriteAllText(plistPath, plist.WriteToString());
  31. #endif
  32. }
  33. }
  34. }
  35. #endif