/// <summary> /// Returns true if the plugin importer already has the correct settings, otherwise returns false. If /// false is returned, the plugin settings should be reset to their expected values. /// </summary> /// <param name="pluginImporter"></param> /// <param name="isCompatibleWithAnyPlatform"></param> /// <param name="isCompatibleWithEditor"></param> /// <param name="editorPlatform"></param> /// <param name="allowedRuntimePlatforms"></param> /// <returns></returns> private static bool HasCorrectImportSettings( PluginImporter pluginImporter, bool isCompatibleWithAnyPlatform, bool isCompatibleWithEditor, EditorOS editorPlatform, params BuildTarget[] allowedRuntimePlatforms) { // Return false if our platform compatibility doesn't match if (pluginImporter.GetCompatibleWithAnyPlatform() != isCompatibleWithAnyPlatform) { return(false); } // Return false if our editor compatibility doesn't match if (pluginImporter.GetCompatibleWithEditor() != isCompatibleWithEditor) { return(false); } // If the plugin is compatible with the editor and not set to the proper platform or to the proper // CPU level, return false. if (pluginImporter.GetCompatibleWithEditor() && isCompatibleWithEditor) { var editorPlatformValue = pluginImporter.GetEditorData(OS_KEY); var editorOS = (EditorOS)Enum.Parse(typeof(EditorOS), editorPlatformValue); if (editorOS != editorPlatform) { return(false); } if (pluginImporter.GetEditorData(CPU_KEY) != CPU_VALUE) { return(false); } } // Check compatibility with each platform and verify that we have correct setting for each. foreach (var buildTarget in ALL_BUILD_TARGETS) { var shouldBeCompatible = allowedRuntimePlatforms.Contains(buildTarget); var isCompatible = pluginImporter.GetCompatibleWithPlatform(buildTarget); if (shouldBeCompatible && !isCompatible) { return(false); } else if (!shouldBeCompatible && isCompatible) { return(false); } } return(true); }
static bool ResetPluginSettings(PluginImporter plugin, string CPU, string OS) { bool didUpdate = false; if (plugin.GetCompatibleWithAnyPlatform() != false) { plugin.SetCompatibleWithAnyPlatform(false); didUpdate = true; } if (plugin.GetCompatibleWithEditor() != true) { plugin.SetCompatibleWithEditor(true); didUpdate = true; } if (plugin.GetEditorData("CPU") != CPU) { plugin.SetEditorData("CPU", CPU); didUpdate = true; } if (plugin.GetEditorData("OS") != OS) { plugin.SetEditorData("OS", OS); didUpdate = true; } return(didUpdate); }
private static void SetCompatibleWithEditor(PluginImporter pluginImporter, bool enable) { if (pluginImporter.GetCompatibleWithEditor() != enable) { pluginImporter.SetCompatibleWithEditor(enable); mHasAtLeastOneLibraryBeenModified = true; } }
internal bool UpdateCompatibleWithEditor(PluginImporter pluginImporter) { if (CompatibleWithEditor != pluginImporter.GetCompatibleWithEditor()) { pluginImporter.SetCompatibleWithEditor(CompatibleWithEditor); return(true); } return(false); }
private static void SetPluginEnabled(string pluginPath, bool enabled) { PluginImporter pluginImporter = AssetImporter.GetAtPath(pluginPath) as PluginImporter; if (pluginImporter.GetCompatibleWithEditor() == enabled) { return; } pluginImporter.SetCompatibleWithEditor(enabled); pluginImporter.SaveAndReimport(); }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { #if UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_5 || UNITY_5_4 foreach (string importedAsset in importedAssets) { if (importedAsset.Equals(importedAssets[importedAssets.Length - 1])) { if (Directory.Exists(Utils.FixSlashesInPath("Assets/Plugins/Android/appodeal/assets")) && !Directory.Exists(Utils.FixSlashesInPath("Assets/Plugins/Android/assets"))) { if (EditorUtility.DisplayDialog("Appodeal Unity", "We have detected that you're using Unity" + Application.unityVersion + " and it can't compile android assets from library folder so Assets/Plugins/Android/appodeal/assets folder should be moved into Android folder.", "Move it for me", "Leave it there")) { Directory.Move(Utils.FixSlashesInPath("Assets/Plugins/Android/appodeal/assets"), Utils.FixSlashesInPath("Assets/Plugins/Android/assets")); reimportFolder(Utils.FixSlashesInPath("Assets/Plugins/Android/assets")); reimportFolder(Utils.FixSlashesInPath("Assets/Plugins/Android/appodeal")); } } } } #endif #if UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 if (File.Exists(Utils.FixSlashesInPath("Assets/Appodeal/SampleAndroidManifest.xml")) && !File.Exists(Utils.FixSlashesInPath("Assets/Plugins/Android/AndroidManifest.xml"))) { FileUtil.CopyFileOrDirectory(Utils.FixSlashesInPath("Assets/Appodeal/SampleAndroidManifest.xml"), Utils.FixSlashesInPath("Assets/Plugins/Android/AndroidManifest.xml")); } #endif #if UNITY_5_5 || UNITY_5_4 foreach (string plugin in Plugins) { string fullpath = Utils.FixSlashesInPath("Assets/Plugins/Android/" + plugin); if (File.Exists(fullpath)) { PluginImporter pluginImporter = AssetImporter.GetAtPath(fullpath) as PluginImporter; if (!pluginImporter.GetCompatibleWithPlatform(BuildTarget.Android)) { pluginImporter.SetCompatibleWithPlatform(BuildTarget.Android, true); } } } string path = Utils.FixSlashesInPath("Assets/Plugins/Ionic.Zip.Unity.dll"); if (File.Exists(path)) { PluginImporter ionicPluginImporter = AssetImporter.GetAtPath(path) as PluginImporter; if (!ionicPluginImporter.GetCompatibleWithEditor()) { ionicPluginImporter.SetCompatibleWithEditor(true); } } #endif }
private static void SetPluginCompatibleEditor(string path, bool enable) { if (File.Exists(path) == true || Directory.Exists(path) == true) { PluginImporter pluginImporter = PluginImporter.GetAtPath(path) as PluginImporter; if (pluginImporter != null) { pluginImporter.SetCompatibleWithAnyPlatform(false); if (pluginImporter.GetCompatibleWithEditor() != enable) { pluginImporter.SetCompatibleWithEditor(enable); pluginImporter.SaveAndReimport(); } } } }
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) { #if UNITY_4 && UNITY_IPHONE if (PlayerSettings.apiCompatibilityLevel.Equals(ApiCompatibilityLevel.NET_2_0_Subset)) { if (EditorUtility.DisplayDialog("Appodeal Unity", "We have detected that you're using subset API compatibility level: " + PlayerSettings.apiCompatibilityLevel + " you should change it to NET_2_0 to be able using Ionic.ZIP.dll.", "Change it for me", "I'll do it")) { PlayerSettings.apiCompatibilityLevel = ApiCompatibilityLevel.NET_2_0; } } #endif #if UNITY_4 if (File.Exists(Utils.FixSlashesInPath("Assets/Appodeal/SampleAndroidManifest.xml")) && !File.Exists(Utils.FixSlashesInPath("Assets/Plugins/Android/AndroidManifest.xml")) && moveManifest) { if (EditorUtility.DisplayDialog("Appodeal Unity", "We have detected that you have no AndroidManifest.xml inside Android folder, it should override Unity's settings to fix not clickable ads", "Place template for me", "Don't do that!")) { FileUtil.CopyFileOrDirectory(Utils.FixSlashesInPath("Assets/Appodeal/SampleAndroidManifest.xml"), Utils.FixSlashesInPath("Assets/Plugins/Android/AndroidManifest.xml")); } } #endif #if UNITY_5 foreach (string plugin in Plugins) { string fullpath = Utils.FixSlashesInPath("Assets/Plugins/Android/" + plugin); if (File.Exists(fullpath)) { PluginImporter pluginImporter = AssetImporter.GetAtPath(fullpath) as PluginImporter; if (!pluginImporter.GetCompatibleWithPlatform(BuildTarget.Android)) { pluginImporter.SetCompatibleWithPlatform(BuildTarget.Android, true); } } } string path = Utils.FixSlashesInPath("Assets/Plugins/Ionic.Zip.Unity.dll"); if (File.Exists(path)) { PluginImporter ionicPluginImporter = AssetImporter.GetAtPath(path) as PluginImporter; if (!ionicPluginImporter.GetCompatibleWithEditor()) { ionicPluginImporter.SetCompatibleWithEditor(true); } } #endif }
private static void EnableIOSResolver() { string iosResolverPath = AssetDatabase.GUIDToAssetPath(_iosResolverGuid); if (iosResolverPath == null) { Debug.LogError("ARCoreExtensions: Could not locate Google.IOSResolver plugin."); return; } PluginImporter pluginImporter = AssetImporter.GetAtPath(iosResolverPath) as PluginImporter; if (!pluginImporter.GetCompatibleWithEditor()) { pluginImporter.SetCompatibleWithEditor(true); } }
private static void ToggleAssemblies(string path, string[] assemblies, bool enable) { foreach (var file in assemblies) { var filepath = path + file; PluginImporter importer = AssetImporter.GetAtPath(filepath) as PluginImporter; if (importer == null) { Debug.LogFormat("GitHub for Unity: Could not find importer for {0}. Some functionality may fail.", filepath); continue; } if (importer.GetCompatibleWithEditor() != enable) { importer.SetCompatibleWithEditor(enable); importer.SaveAndReimport(); } } }
public override void OnEnable() { me = this; Target = (PluginImporter)target; if (DLLManager.ExistsKey(fileName)) { _ignore = DLLManager.GetBool(fileName); } else { _ignore = !Target.GetCompatibleWithEditor(); } lastIgnore = _ignore; base.OnEnable(); }
private FixProblemInstruction checkAndGetInstruction(string relativePath, platforms platform) { EnablePluginForPlatform instr = null; PluginImporter imp = AssetImporter.GetAtPath(relativePath) as PluginImporter; if (imp == null) { return(instr); } bool isChecked = false; switch (platform) { case platforms.any: isChecked = imp.GetCompatibleWithAnyPlatform(); break; case platforms.editor: isChecked = imp.GetCompatibleWithEditor(); break; case platforms.android: isChecked = imp.GetCompatibleWithPlatform(BuildTarget.Android); break; case platforms.ios: isChecked = imp.GetCompatibleWithPlatform(BuildTarget.iOS); break; } if (!isChecked) { string desc = "Plugin " + relativePath + " should be enabled for platform: " + platform.ToString() + ".\n"; if (relativePath.Contains(AppodealUnityUtils.combinePaths("Assets", "Plugins", "Android"))) { desc += "If you wan't to exclude this network from your game, don't forget to add Appodeal.disableNetwork(networkname) before initialization."; } instr = new EnablePluginForPlatform(desc, true, relativePath, platform); } return(instr); }
private static bool HasCompatibility(string pathToDLL, BuildTarget[] supportedBuildTargets, bool isCompatibleWithEditor) { PluginImporter pluginImporter = (PluginImporter)AssetImporter.GetAtPath(pathToDLL); // check if any platform is enabled if (pluginImporter.GetCompatibleWithAnyPlatform()) { return(false); } // check if compatible with editor if that is desired if (pluginImporter.GetCompatibleWithEditor() != isCompatibleWithEditor) { return(false); } // check for each build target if compatible when desired foreach (BuildTarget buildTarget in Enum.GetValues(typeof(BuildTarget))) { if (IsBuildTargetObsolete(buildTarget) || buildTarget == BuildTarget.NoTarget) { continue;; } bool isCompatible = pluginImporter.GetCompatibleWithPlatform(buildTarget); if (supportedBuildTargets.Contains(buildTarget)) { if (!isCompatible) { return(false); } } else { if (isCompatible) { return(false); } } } return(true); }
/// <summary> /// Enable a dependency resolver. /// </summary> /// <param name="resolverName">Resolver plugin's filename.</param> public static void EnableDependencyResolver(string resolverName) { string resolverPath = null; string[] guids = AssetDatabase.FindAssets(resolverName); foreach (var guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); if (path.EndsWith(".dll")) { if (resolverPath != null) { Debug.LogErrorFormat("ARCoreExtensions: " + "There are multiple {0} plugins detected. " + "One is {1}, another is {2}. Please remove one of them.", resolverName, resolverPath, path); return; } resolverPath = path; } } if (resolverPath == null) { Debug.LogErrorFormat( "ARCoreExtensions: Could not locate {0} plugin.", resolverName); return; } PluginImporter pluginImporter = AssetImporter.GetAtPath(resolverPath) as PluginImporter; if (!pluginImporter.GetCompatibleWithEditor()) { pluginImporter.SetCompatibleWithEditor(true); } }
private static void EnableJarResolver() { string jarResolverPath = null; string[] guids = AssetDatabase.FindAssets("Google.JarResolver"); foreach (var guid in guids) { string path = AssetDatabase.GUIDToAssetPath(guid); if (path.EndsWith(".dll")) { if (jarResolverPath != null) { Debug.LogErrorFormat("ARCoreExtensions: " + "There are multiple Google.JarResolver plugins detected. " + "One is {0}, another is {1}. Please remove one of them.", jarResolverPath, path); return; } jarResolverPath = path; } } if (jarResolverPath == null) { Debug.LogError("ARCoreExtensions: Could not locate Google.JarResolver plugin."); return; } PluginImporter pluginImporter = AssetImporter.GetAtPath(jarResolverPath) as PluginImporter; if (!pluginImporter.GetCompatibleWithEditor()) { pluginImporter.SetCompatibleWithEditor(true); } }
static void SetCompatibility(string guid, PlatformSupport[] platformSupport) { string pluginPath = AssetDatabase.GUIDToAssetPath(guid); PluginImporter plugin = AssetImporter.GetAtPath(pluginPath) as PluginImporter; if (plugin == null) { return; } bool updateRequired = false; if (platformSupport.Length == 0) { // Just set every platform to disabled before enabling the correct ones foreach (BuildTarget bt in Enum.GetValues(typeof(BuildTarget))) { // If the build target is obsolete if (bt < 0) { continue; } // Use a string here to handle issue where a platform dependency may not be installed // within the current Unity Editor install if (plugin.GetCompatibleWithPlatform(bt.ToString())) { updateRequired = true; } } } else { foreach (PlatformSupport s in platformSupport) { if (!plugin.GetCompatibleWithPlatform(s.platformName)) { updateRequired = true; } if (plugin.GetCompatibleWithEditor() != s.editorSupport) { updateRequired = true; } if (s.editorSupport) { if (plugin.GetEditorData("OS") != s.editorOS || plugin.GetEditorData("CPU") != s.editorCPU) { updateRequired = true; } } } } if (updateRequired) { #if UNITY_5_5_OR_NEWER plugin.ClearSettings(); #endif plugin.SetCompatibleWithEditor(false); plugin.SetCompatibleWithAnyPlatform(false); // Just set every platform to disabled before enabling the correct ones foreach (BuildTarget bt in Enum.GetValues(typeof(BuildTarget))) { // If the build target is obsolete if (bt < 0) { continue; } // Use a string here to handle issue where a platform dependency may not be installed // within the current Unity Editor install plugin.SetCompatibleWithPlatform(bt.ToString(), false); } foreach (PlatformSupport s in platformSupport) { plugin.SetCompatibleWithPlatform(s.platformName, s.platformSupport); plugin.SetPlatformData("Any", "Exclude Editor", (s.editorSupport ? 0 : 1).ToString()); plugin.SetPlatformData("Any", "Exclude " + s.platformName, (s.platformSupport ? 0 : 1).ToString()); if (!string.IsNullOrEmpty(s.platformCPU)) { plugin.SetPlatformData(s.platformName, "CPU", s.platformCPU); } plugin.SetCompatibleWithEditor(s.editorSupport); if (s.editorSupport) { plugin.SetEditorData("OS", s.editorOS); plugin.SetEditorData("CPU", s.editorCPU); } } plugin.SaveAndReimport(); } }
static void SetDLLPlatforms(string dllName, bool active) { string[] assetGuids = AssetDatabase.FindAssets(dllName); foreach (string guid in assetGuids) { string dllPath = AssetDatabase.GUIDToAssetPath(guid); if (string.IsNullOrEmpty(dllPath) || dllPath.ToLower().EndsWith(".dll") == false) { return; } PluginImporter importer = AssetImporter.GetAtPath(dllPath) as PluginImporter; bool allCorrect = true; if (importer.GetCompatibleWithAnyPlatform() != active) { allCorrect = false; } else { if (importer.GetCompatibleWithAnyPlatform()) { if (importer.GetExcludeEditorFromAnyPlatform() != !active || importer.GetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows) != !active) { allCorrect = false; } } else { if (importer.GetCompatibleWithEditor() != active || importer.GetCompatibleWithPlatform(BuildTarget.StandaloneWindows) != active) { allCorrect = false; } } } if (allCorrect == false) { if (active) { importer.SetCompatibleWithAnyPlatform(true); importer.SetExcludeEditorFromAnyPlatform(false); importer.SetExcludeFromAnyPlatform(BuildTarget.Android, false); importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows, false); importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneWindows64, false); importer.SetExcludeFromAnyPlatform(BuildTarget.StandaloneLinux64, false); } else { importer.SetCompatibleWithAnyPlatform(false); importer.SetCompatibleWithEditor(false); importer.SetCompatibleWithPlatform(BuildTarget.Android, false); importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false); importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false); importer.SetCompatibleWithPlatform(BuildTarget.StandaloneLinux64, false); } importer.SaveAndReimport(); } } }
public bool IsWin64Enabled() { string path = ""; if (Plugins.TryGetValue(PluginPlatform.Win64, out path)) { if (File.Exists(path)) { string basePath = GetCurrentProjectPath(); string relPath = path.Substring(basePath.Length + 1); PluginImporter pi = PluginImporter.GetAtPath(relPath) as PluginImporter; if (pi != null) { return(pi.GetCompatibleWithPlatform(BuildTarget.StandaloneWindows64) && pi.GetCompatibleWithEditor()); } } } return(false); }