|
| 1 | +using System.Linq; |
| 2 | +using NUnit.Framework; |
| 3 | +using UnityEditor; |
| 4 | + |
| 5 | +namespace UnityEngine.InputSystem.Editor |
| 6 | +{ |
| 7 | + public class InputSystemPluginControl |
| 8 | + { |
| 9 | + [InitializeOnLoadMethod] |
| 10 | + private static void CheckForExtension() |
| 11 | + { |
| 12 | + ThrowWarningOnMissingPlugin(); |
| 13 | + } |
| 14 | + |
| 15 | + private static readonly BuildTarget[] targetNoPluginNeeded = new BuildTarget[] |
| 16 | + { |
| 17 | + BuildTarget.StandaloneOSX, |
| 18 | + BuildTarget.StandaloneWindows, |
| 19 | + BuildTarget.iOS, |
| 20 | + BuildTarget.Android, |
| 21 | + BuildTarget.StandaloneWindows64, |
| 22 | + BuildTarget.WebGL, |
| 23 | + BuildTarget.WSAPlayer, |
| 24 | + BuildTarget.StandaloneLinux64, |
| 25 | + BuildTarget.tvOS, |
| 26 | + BuildTarget.LinuxHeadlessSimulation, |
| 27 | + BuildTarget.PS5, |
| 28 | + BuildTarget.EmbeddedLinux, |
| 29 | + BuildTarget.QNX, |
| 30 | + BuildTarget.VisionOS, |
| 31 | + BuildTarget.ReservedCFE, |
| 32 | + BuildTarget.NoTarget |
| 33 | + }; |
| 34 | + |
| 35 | + static bool BuildTargetNeedsPlugin() |
| 36 | + { |
| 37 | + BuildTarget target = EditorUserBuildSettings.activeBuildTarget; |
| 38 | + return !targetNoPluginNeeded.Contains(target); |
| 39 | + } |
| 40 | + |
| 41 | + private static string plugInName = "com.unity.inputsystem."; |
| 42 | + private static bool IsPluginInstalled() |
| 43 | + { |
| 44 | + var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages(); |
| 45 | + foreach (var package in registeredPackages) |
| 46 | + { |
| 47 | + if (package.name.StartsWith(plugInName)) //TODO better ?? |
| 48 | + return true; |
| 49 | + } |
| 50 | + return false; |
| 51 | + } |
| 52 | + |
| 53 | + private static void ThrowWarningOnMissingPlugin() |
| 54 | + { |
| 55 | + if (BuildTargetNeedsPlugin() && !IsPluginInstalled()) |
| 56 | + Debug.Log("No plugin installed!"); |
| 57 | + // TODO Assert. |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments