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);
    }
示例#2
0
        /// <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);
        }
    private static void SetEditorData(PluginImporter pluginImporter, string cpu, string os)
    {
        if (!pluginImporter.GetEditorData("CPU").Equals(cpu))
        {
            pluginImporter.SetEditorData("CPU", cpu);
            mHasAtLeastOneLibraryBeenModified = true;
        }

        if (!pluginImporter.GetEditorData("OS").Equals(os))
        {
            pluginImporter.SetEditorData("OS", os);
            mHasAtLeastOneLibraryBeenModified = 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();
            }
        }