1.3.0: Added EditorProjectPrefs, so each project can have their own settings for history and favorites
This commit is contained in:
parent
65ca5dd355
commit
c54a325cfe
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Module.NavigationTool.Editor.Utilities;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
@ -17,7 +18,7 @@ namespace Module.NavigationTool.Editor.Favorite
|
||||||
public Favorites()
|
public Favorites()
|
||||||
{
|
{
|
||||||
entries = new List<Entry>();
|
entries = new List<Entry>();
|
||||||
string json = EditorPrefs.GetString(PREF_ID);
|
string json = EditorProjectPrefs.GetString(PREF_ID);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(json))
|
if (!string.IsNullOrEmpty(json))
|
||||||
EditorJsonUtility.FromJsonOverwrite(json, this);
|
EditorJsonUtility.FromJsonOverwrite(json, this);
|
||||||
|
|
@ -220,7 +221,7 @@ namespace Module.NavigationTool.Editor.Favorite
|
||||||
{
|
{
|
||||||
Sort();
|
Sort();
|
||||||
string json = EditorJsonUtility.ToJson(this, false);
|
string json = EditorJsonUtility.ToJson(this, false);
|
||||||
EditorPrefs.SetString(PREF_ID, json);
|
EditorProjectPrefs.SetString(PREF_ID, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Module.NavigationTool.Editor.Utilities;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
|
||||||
namespace Module.NavigationTool.Editor.Favorite
|
namespace Module.NavigationTool.Editor.Favorite
|
||||||
|
|
@ -39,7 +40,7 @@ namespace Module.NavigationTool.Editor.Favorite
|
||||||
public static void DeleteAll()
|
public static void DeleteAll()
|
||||||
{
|
{
|
||||||
FAVORITES = null;
|
FAVORITES = null;
|
||||||
EditorPrefs.DeleteKey(Favorites.PREF_ID);
|
EditorProjectPrefs.DeleteKey(Favorites.PREF_ID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Module.NavigationTool.Editor.Utilities;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
@ -18,7 +19,7 @@ namespace Module.NavigationTool.Editor.History
|
||||||
public HistoryList()
|
public HistoryList()
|
||||||
{
|
{
|
||||||
entries = new List<Entry>();
|
entries = new List<Entry>();
|
||||||
string json = EditorPrefs.GetString(PREF_ID);
|
string json = EditorProjectPrefs.GetString(PREF_ID);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(json))
|
if (!string.IsNullOrEmpty(json))
|
||||||
EditorJsonUtility.FromJsonOverwrite(json, this);
|
EditorJsonUtility.FromJsonOverwrite(json, this);
|
||||||
|
|
@ -96,7 +97,7 @@ namespace Module.NavigationTool.Editor.History
|
||||||
public void Save()
|
public void Save()
|
||||||
{
|
{
|
||||||
string json = EditorJsonUtility.ToJson(this, false);
|
string json = EditorJsonUtility.ToJson(this, false);
|
||||||
EditorPrefs.SetString(PREF_ID, json);
|
EditorProjectPrefs.SetString(PREF_ID, json);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
3
Editor/Utilities.meta
Normal file
3
Editor/Utilities.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 39e02e3db8dc47ffa992c360f3293481
|
||||||
|
timeCreated: 1642702539
|
||||||
85
Editor/Utilities/EditorProjectPrefs.cs
Normal file
85
Editor/Utilities/EditorProjectPrefs.cs
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/Utilities/EditorProjectPrefs.cs.meta
Normal file
3
Editor/Utilities/EditorProjectPrefs.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: da00f657aa474ea9bc9c0b2f26e43f47
|
||||||
|
timeCreated: 1642702549
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.navigationtool",
|
"name": "com.module.navigationtool",
|
||||||
"version": "1.2.0",
|
"version": "1.3.0",
|
||||||
"displayName": "Module.NavigationTool",
|
"displayName": "Module.NavigationTool",
|
||||||
"description": "Support for navigation tools, like favorites, history and toolbars",
|
"description": "Support for navigation tools, like favorites, history and toolbars",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue