diff --git a/Editor/Favorites/Utilities/Favorites.cs b/Editor/Favorites/Utilities/Favorites.cs index 030abc5..2f0e5ed 100644 --- a/Editor/Favorites/Utilities/Favorites.cs +++ b/Editor/Favorites/Utilities/Favorites.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using Module.NavigationTool.Editor.Utilities; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; @@ -17,7 +18,7 @@ namespace Module.NavigationTool.Editor.Favorite public Favorites() { entries = new List(); - string json = EditorPrefs.GetString(PREF_ID); + string json = EditorProjectPrefs.GetString(PREF_ID); if (!string.IsNullOrEmpty(json)) EditorJsonUtility.FromJsonOverwrite(json, this); @@ -220,7 +221,7 @@ namespace Module.NavigationTool.Editor.Favorite { Sort(); string json = EditorJsonUtility.ToJson(this, false); - EditorPrefs.SetString(PREF_ID, json); + EditorProjectPrefs.SetString(PREF_ID, json); } /// diff --git a/Editor/Favorites/Utilities/FavoritesUtility.cs b/Editor/Favorites/Utilities/FavoritesUtility.cs index e09357d..8a19114 100644 --- a/Editor/Favorites/Utilities/FavoritesUtility.cs +++ b/Editor/Favorites/Utilities/FavoritesUtility.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using Module.NavigationTool.Editor.Utilities; using UnityEditor; namespace Module.NavigationTool.Editor.Favorite @@ -39,7 +40,7 @@ namespace Module.NavigationTool.Editor.Favorite public static void DeleteAll() { FAVORITES = null; - EditorPrefs.DeleteKey(Favorites.PREF_ID); + EditorProjectPrefs.DeleteKey(Favorites.PREF_ID); } } } \ No newline at end of file diff --git a/Editor/History/Utilities/HistoryList.cs b/Editor/History/Utilities/HistoryList.cs index 590b7d3..2719d96 100644 --- a/Editor/History/Utilities/HistoryList.cs +++ b/Editor/History/Utilities/HistoryList.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using Module.NavigationTool.Editor.Utilities; using UnityEditor; using UnityEngine; using Object = UnityEngine.Object; @@ -18,7 +19,7 @@ namespace Module.NavigationTool.Editor.History public HistoryList() { entries = new List(); - string json = EditorPrefs.GetString(PREF_ID); + string json = EditorProjectPrefs.GetString(PREF_ID); if (!string.IsNullOrEmpty(json)) EditorJsonUtility.FromJsonOverwrite(json, this); @@ -96,7 +97,7 @@ namespace Module.NavigationTool.Editor.History public void Save() { string json = EditorJsonUtility.ToJson(this, false); - EditorPrefs.SetString(PREF_ID, json); + EditorProjectPrefs.SetString(PREF_ID, json); } /// diff --git a/Editor/Utilities.meta b/Editor/Utilities.meta new file mode 100644 index 0000000..c62228f --- /dev/null +++ b/Editor/Utilities.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 39e02e3db8dc47ffa992c360f3293481 +timeCreated: 1642702539 \ No newline at end of file diff --git a/Editor/Utilities/EditorProjectPrefs.cs b/Editor/Utilities/EditorProjectPrefs.cs new file mode 100644 index 0000000..61e8b36 --- /dev/null +++ b/Editor/Utilities/EditorProjectPrefs.cs @@ -0,0 +1,85 @@ +using System.Security.Cryptography; +using System.Text; +using UnityEditor; +using UnityEngine; + +namespace Module.NavigationTool.Editor.Utilities +{ + internal static class EditorProjectPrefs + { + private static string PRODUCT_ID; + + public static void SetInt(string key, int value) + { + EditorPrefs.SetInt(GetProjectKey(key), value); + } + + public static void SetFloat(string key, float value) + { + EditorPrefs.SetFloat(GetProjectKey(key), value); + } + + public static void SetString(string key, string value) + { + EditorPrefs.SetString(GetProjectKey(key), value); + } + + public static void SetBool(string key, bool value) + { + EditorPrefs.SetBool(GetProjectKey(key), value); + } + + public static int GetInt(string key, int defaultValue = 0) + { + return EditorPrefs.GetInt(GetProjectKey(key), defaultValue); + } + + public static float GetFloat(string key, float defaultValue = 0.0f) + { + return EditorPrefs.GetFloat(GetProjectKey(key), defaultValue); + } + + public static string GetString(string key, string defaultValue = "") + { + return EditorPrefs.GetString(GetProjectKey(key), defaultValue); + } + + public static bool GetBool(string key, bool defaultValue = false) + { + return EditorPrefs.GetBool(GetProjectKey(key), defaultValue); + } + + public static bool HasKey(string key) + { + return EditorPrefs.HasKey(GetProjectKey(key)); + } + + public static void DeleteKey(string key) + { + EditorPrefs.DeleteKey(GetProjectKey(key)); + } + + private static string GetProjectKey(string key) + { + if (string.IsNullOrEmpty(PRODUCT_ID)) + PRODUCT_ID = ConstructProductIdFromPath(); + + return $"{PRODUCT_ID}_{key}"; + } + + private static string ConstructProductIdFromPath() + { + var md5 = MD5.Create(); + byte[] bytes = Encoding.UTF8.GetBytes(Application.dataPath); + byte[] data = md5.ComputeHash(bytes); + var sb = new StringBuilder(); + + for (var i = 0; i < data.Length; i++) + { + sb.Append(data[i].ToString("x2")); + } + + return sb.ToString(); + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorProjectPrefs.cs.meta b/Editor/Utilities/EditorProjectPrefs.cs.meta new file mode 100644 index 0000000..eec0b83 --- /dev/null +++ b/Editor/Utilities/EditorProjectPrefs.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: da00f657aa474ea9bc9c0b2f26e43f47 +timeCreated: 1642702549 \ No newline at end of file diff --git a/package.json b/package.json index 7b82a18..f31f1a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.navigationtool", - "version": "1.2.0", + "version": "1.3.0", "displayName": "Module.NavigationTool", "description": "Support for navigation tools, like favorites, history and toolbars", "unity": "2019.2",