コード例 #1
0
        internal static IEnumerable <KeyValuePair <string, string> > GetEditorPrefMigrationsForPlugin(Plugin p)
        {
            var fieldInfo             = p.GetType().GetField("ID", BindingFlags.Public | BindingFlags.Static);
            var renamedFromAttributes = fieldInfo.GetCustomAttributes(typeof(RenamedFromAttribute), true)
                                        .Cast <RenamedFromAttribute>();

            foreach (var renamed in renamedFromAttributes)
            {
                foreach (var editorPref in p.configuration.editorPrefs)
                {
                    var previousKey = EditorPrefMetadata.GetNamespacedKey(renamed.previousName, editorPref.key);
                    if (EditorPrefs.HasKey(previousKey))
                    {
                        yield return(new KeyValuePair <string, string>(previousKey, editorPref.namespacedKey));
                    }
                }
            }
        }
コード例 #2
0
        public static void DeleteAllEditorPrefs()
        {
            foreach (var plugin in PluginContainer.plugins)
            {
                // Delete all current editor prefs for this plugin
                foreach (var editorPref in plugin.configuration.editorPrefs)
                {
                    EditorPrefs.DeleteKey(editorPref.namespacedKey);
                }

                // If our plugin was renamed, delete all editor pref keys for the plugin using its previous names
                IEnumerable <RenamedFromAttribute> renamedFromAttributes;
                var fieldInfo = plugin.GetType().GetField("ID", BindingFlags.Public | BindingFlags.Static);
                renamedFromAttributes = fieldInfo.GetCustomAttributes(typeof(RenamedFromAttribute), true).Cast <RenamedFromAttribute>();
                foreach (var renamed in renamedFromAttributes)
                {
                    foreach (var editorPref in plugin.configuration.editorPrefs)
                    {
                        EditorPrefs.DeleteKey(EditorPrefMetadata.GetNamespacedKey(renamed.previousName, editorPref.key));
                    }
                }
            }
        }