Skip to content

Commit eab014c

Browse files
committed
version 2.0.0
Added - Main toolbar elements field and property serialization, using SerializeAttribute and calling InitializeElement method if it exists - Recommended styles for: Vector2Field, Vector3Field, ColorField, LayerField, EnumField, EnumFlagsField, TagField and ObjectField - Ids for native elements on Unity 6 - ObjectSelector, SearchPickerWindow and EditorGenericDropdownMenuWindowContent won't make group popup close - Support for Mac (mostly) Changed - Breaking: Overrides and some stats saved by control panel window are now saved under UserSettings folder - Breaking: Set AutoReferenced to false on assembly definition - Breaking: Added new dependency Unity serialization (while being AutoReferenced) Removed - Newtonsoft Json.Net dependency - Delete actions. Just remove UserSettings/unity-toolbar-extender-ui-toolkit/ files to remove the thing you want
1 parent 43e9824 commit eab014c

File tree

144 files changed

+2738
-316
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

144 files changed

+2738
-316
lines changed

Assets/Package/CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
# Changelog
22

3+
## [2.0.0]
4+
5+
### Added
6+
7+
- Main toolbar elements field and property serialization, using SerializeAttribute and calling InitializeElement method if it exists
8+
- Recommended styles for: Vector2Field, Vector3Field, ColorField, LayerField, EnumField, EnumFlagsField, TagField and ObjectField
9+
- Ids for native elements on Unity 6
10+
- ObjectSelector, SearchPickerWindow and EditorGenericDropdownMenuWindowContent won't make group popup close
11+
- Support for Mac (mostly)
12+
13+
### Changed
14+
15+
- **Breaking:** Overrides and some stats saved by control panel window are now saved under UserSettings folder
16+
- **Breaking:** Set AutoReferenced to false on assembly definition
17+
- **Breaking:** Added new dependency Unity serialization (while being AutoReferenced)
18+
19+
### Removed
20+
21+
- Newtonsoft Json.Net dependency
22+
- Delete actions. Just remove UserSettings/unity-toolbar-extender-ui-toolkit/ files to remove the thing you want
23+
324
## [1.0.1]
425

526
### Fixed

Assets/Package/Editor/ControlPanelWindow/MainToolbarElementController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ public MainToolbarElementController(OverridableElement overridableElement,
5353

5454
private void SaveFoldoutState(ChangeEvent<bool> eventArgs)
5555
{
56-
JsonEditorPrefs.SetBool(GetFullFoldoutStateSaveKey(), eventArgs.newValue);
56+
UserSettingsPrefs.SetBool(GetFullFoldoutStateSaveKey(), eventArgs.newValue);
5757
}
5858

5959
private bool GetSavedFoldoutState()
6060
{
61-
return JsonEditorPrefs.GetBool(GetFullFoldoutStateSaveKey(), false);
61+
return UserSettingsPrefs.GetBool(GetFullFoldoutStateSaveKey(), false);
6262
}
6363

6464
public bool ContainsSubController(string id)

Assets/Package/Editor/ControlPanelWindow/OrganizationalFoldableContainer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public OrganizationalFoldableContainer(string containerId, string foldoutText)
3030

3131
private void SaveFoldoutState(ChangeEvent<bool> eventArgs)
3232
{
33-
JsonEditorPrefs.SetBool(GetFullFoldoutStateSaveKey(), eventArgs.newValue);
33+
UserSettingsPrefs.SetBool(GetFullFoldoutStateSaveKey(), eventArgs.newValue);
3434
}
3535

3636
private bool GetSavedFoldoutState()
3737
{
38-
return JsonEditorPrefs.GetBool(GetFullFoldoutStateSaveKey(), false);
38+
return UserSettingsPrefs.GetBool(GetFullFoldoutStateSaveKey(), false);
3939
}
4040

4141
public void SetControllers(IEnumerable<MainToolbarElementController> controllers)

Assets/Package/Editor/GroupDefinitions/GroupDropdownWindowPopupManager.cs

+22-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ namespace Paps.UnityToolbarExtenderUIToolkit
1212
internal static class GroupDropdownWindowPopupManager
1313
{
1414
private const string POPUP_WINDOW_CONTENT_FIELD_NAME = "m_WindowContent";
15+
private static readonly string[] SPECIAL_EDITOR_WINDOW_TYPE_NAMES =
16+
{
17+
"UnityEditor.UIElements.Debugger.UIElementsDebugger",
18+
"UnityEditor.UIElements.EditorMenuExtensions+ContextMenu",
19+
"UnityEditor.ObjectSelector",
20+
"UnityEditor.Search.SearchPickerWindow"
21+
};
22+
private static readonly string[] SPECIAL_POPUP_WINDOW_CONTENT_TYPE_NAMES =
23+
{
24+
"UnityEditor.UIElements.EditorGenericDropdownMenuWindowContent"
25+
};
1526

1627
private static FieldInfo _popupWindowContentField;
1728
private static Type[] _subWindowTypes = new Type[0];
@@ -40,14 +51,11 @@ private static void InitializeSpecialWindowTypes()
4051
{
4152
var typeList = new List<Type>();
4253

43-
var uiToolkitDebuggerType = TypeCache.GetTypesDerivedFrom<EditorWindow>()
44-
.FirstOrDefault(type => type.Name == "UIElementsDebugger");
54+
typeList.AddRange(TypeCache.GetTypesDerivedFrom<EditorWindow>()
55+
.Where(type => SPECIAL_EDITOR_WINDOW_TYPE_NAMES.Contains(type.Name) || SPECIAL_EDITOR_WINDOW_TYPE_NAMES.Contains(type.FullName)));
4556

46-
var contextMenuType = TypeCache.GetTypesDerivedFrom<EditorWindow>()
47-
.FirstOrDefault(type => type.FullName == "UnityEditor.UIElements.EditorMenuExtensions+ContextMenu");
48-
49-
typeList.Add(uiToolkitDebuggerType);
50-
typeList.Add(contextMenuType);
57+
typeList.AddRange(TypeCache.GetTypesDerivedFrom<PopupWindowContent>()
58+
.Where(type => SPECIAL_POPUP_WINDOW_CONTENT_TYPE_NAMES.Contains(type.Name) || SPECIAL_POPUP_WINDOW_CONTENT_TYPE_NAMES.Contains(type.FullName)));
5159

5260
_specialWindowTypes = typeList.Where(t => t != null).ToArray();
5361
}
@@ -66,7 +74,7 @@ private static bool ContainsValidPopupWindowContent(EditorWindow window)
6674

6775
var popupContentSpecificType = popupContent.GetType();
6876

69-
return _subWindowTypes.Contains(popupContentSpecificType);
77+
return _subWindowTypes.Contains(popupContentSpecificType) || _specialWindowTypes.Contains(popupContentSpecificType);
7078
}
7179

7280
return false;
@@ -124,7 +132,13 @@ public static void Show(Rect activatorRect, VisualElement[] elements)
124132
_windows.Add(window);
125133

126134
window.Initialize(elements);
135+
136+
#if UNITY_EDITOR_WIN
127137
window.ShowPopup();
138+
#elif UNITY_EDITOR_OSX
139+
window.ShowAsDropdownForMainToolbar(activatorRect, window.position.size);
140+
#endif
141+
128142
}
129143
}
130144
}

Assets/Package/Editor/Helpers/GlobalActions.cs

-18
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,6 @@ public static void ResetOverridesIfUserAccepts()
2222
);
2323
}
2424

25-
public static void DeleteEditorPrefs()
26-
{
27-
ServicesAndRepositories.MainToolbarElementOverridesRepository.Clear();
28-
JsonEditorPrefs.DeleteAll();
29-
MainToolbarAutomaticExtender.Refresh();
30-
}
31-
32-
public static void DeleteEditorPrefsIfUserAccepts()
33-
{
34-
ShowDialog(
35-
"Delete Package Related Editor Prefs",
36-
$"You are about to delete all Editor Prefs related to {ToolInfo.FRIENDLY_TOOL_NAME}.\nAre you sure you want to continue?",
37-
"Delete",
38-
"Cancel",
39-
DeleteEditorPrefs
40-
);
41-
}
42-
4325
public static void ShowDialog(string title, string message, string okMessage,
4426
string cancelMessage, Action onOk = null, Action onCancel = null)
4527
{

Assets/Package/Editor/Helpers/MenuItems.cs

-12
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,5 @@ public static void OpenControlPanel()
1515
{
1616
MainToolbarControlPanelWindow.OpenWindow();
1717
}
18-
19-
[MenuItem(ToolInfo.EDITOR_MENU_BASE + "/Delete Actions/Reset Overrides", priority = 23)]
20-
public static void ResetOverrides()
21-
{
22-
GlobalActions.ResetOverridesIfUserAccepts();
23-
}
24-
25-
[MenuItem(ToolInfo.EDITOR_MENU_BASE + "/Delete Actions/Delete Package Related EditorPrefs", priority = 23)]
26-
public static void DeletePackageRelatedEditorPrefs()
27-
{
28-
GlobalActions.DeleteEditorPrefsIfUserAccepts();
29-
}
3018
}
3119
}

Assets/Package/Editor/Helpers/ServicesAndRepositories.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
internal static class ServicesAndRepositories
44
{
55
public static IMainToolbarElementOverrideRepository MainToolbarElementOverridesRepository =
6-
new JsonEditorPrefsMainToolbarElementOverrideRepository();
6+
new UserSettingsFileMainToolbarElementOverrideRepository();
77

88
public static IGroupDefinitionRepository GroupDefinitionRepository =
99
new ScriptableObjectGroupDefinitionRepository();
1010

1111
public static IMainToolbarElementRepository MainToolbarElementRepository =
1212
new ByAttributeMainToolbarElementRepository();
13+
14+
public static IValueSerializer ValueSerializer =
15+
new UnitySerializationValueSerializer();
16+
17+
public static IMainToolbarElementVariableSerializer MainToolbarElementVariableSerializer =
18+
new UnitySerializationMainToolbarElementVariableSerializer(ValueSerializer);
19+
20+
public static IMainToolbarElementVariableRepository MainToolbarElementVariableRepository =
21+
new UserSettingsFileMainToolbarElementVariableRepository(MainToolbarElementVariableSerializer);
1322
}
1423
}

Assets/Package/Editor/Helpers/UnityNativeElementsIds.cs

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ internal static class UnityNativeElementsIds
2525
// ------------------- ELEMENTS NAMES ---------------------
2626

2727
// LEFT
28+
private const string TOOLBAR_PRODUCT_CAPTION_NAME = "ToolbarProductCaption";
2829
private const string ACCOUNT_DROPDOWN_ELEMENT_NAME = "AccountDropdown";
2930
private const string CLOUD_BUTTON_ELEMENT_NAME = "Cloud";
3031

@@ -43,6 +44,7 @@ internal static class UnityNativeElementsIds
4344
// ------------------- FIXED IDS ---------------------
4445

4546
// LEFT
47+
public const string TOOLBAR_PRODUCT_CAPTION = "ToolbarProductCaption";
4648
public const string ACCOUNT_DROPDOWN_ID = "AccountDropdown";
4749
public const string CLOUD_BUTTON_ID = "CloudButton";
4850
public const string VERSION_CONTROL_ID = "VersionControlButton";
@@ -83,6 +85,7 @@ internal static class UnityNativeElementsIds
8385
private static readonly Dictionary<string, string> IDS_BY_NAME = new Dictionary<string, string>()
8486
{
8587
// LEFT
88+
{ TOOLBAR_PRODUCT_CAPTION_NAME, TOOLBAR_PRODUCT_CAPTION },
8689
{ ACCOUNT_DROPDOWN_ELEMENT_NAME, ACCOUNT_DROPDOWN_ID },
8790
{ CLOUD_BUTTON_ELEMENT_NAME, CLOUD_BUTTON_ID },
8891

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using Unity.Serialization.Json;
5+
using UnityEngine;
6+
7+
namespace Paps.UnityToolbarExtenderUIToolkit
8+
{
9+
public static class UserSettingsPrefs
10+
{
11+
private static readonly string DIRECTORY = Path.Combine(Directory.GetParent(Application.dataPath).FullName, "UserSettings/", "unity-toolbar-extender-ui-toolkit", "user-settings-prefs");
12+
private static readonly string FILE = Path.Combine(DIRECTORY, "user-settings-prefs.json");
13+
14+
private static Dictionary<string, object> _prefs;
15+
private static Dictionary<string, object> Prefs
16+
{
17+
get
18+
{
19+
if (_prefs == null)
20+
_prefs = Load();
21+
22+
return _prefs;
23+
}
24+
}
25+
26+
public static void SetInt(string key, int value)
27+
{
28+
Prefs[key] = value;
29+
Save();
30+
}
31+
32+
public static void SetFloat(string key, float value)
33+
{
34+
Prefs[key] = value;
35+
Save();
36+
}
37+
38+
public static void SetDouble(string key, double value)
39+
{
40+
Prefs[key] = value;
41+
Save();
42+
}
43+
44+
public static void SetBool(string key, bool value)
45+
{
46+
Prefs[key] = value;
47+
Save();
48+
}
49+
50+
public static void SetString(string key, string value)
51+
{
52+
Prefs[key] = value;
53+
Save();
54+
}
55+
56+
public static string GetString(string key, string defaultValue = null)
57+
{
58+
if (Prefs.ContainsKey(key))
59+
return (string)Prefs[key];
60+
61+
return defaultValue;
62+
}
63+
64+
public static bool GetBool(string key, bool defaultValue = false)
65+
{
66+
if (Prefs.ContainsKey(key))
67+
return (bool)Prefs[key];
68+
69+
return defaultValue;
70+
}
71+
72+
public static int GetInt(string key, int defaultValue = 0)
73+
{
74+
if (Prefs.ContainsKey(key))
75+
return Convert.ToInt32(Prefs[key]);
76+
77+
return defaultValue;
78+
}
79+
80+
public static float GetFloat(string key, float defaultValue = 0.0f)
81+
{
82+
if (Prefs.ContainsKey(key))
83+
return Convert.ToSingle(Prefs[key]);
84+
85+
return defaultValue;
86+
}
87+
88+
public static double GetDouble(string key, double defaultValue = 0.0)
89+
{
90+
if (Prefs.ContainsKey(key))
91+
return Convert.ToDouble(Prefs[key]);
92+
93+
return defaultValue;
94+
}
95+
96+
private static Dictionary<string, object> Load()
97+
{
98+
if (!Directory.Exists(DIRECTORY))
99+
Directory.CreateDirectory(DIRECTORY);
100+
101+
if (!File.Exists(FILE))
102+
return JsonSerialization.FromJson<Dictionary<string, object>>("{}");
103+
104+
var json = File.ReadAllText(FILE);
105+
106+
var serializedDictionary = JsonSerialization.FromJson<Dictionary<string, object>>(json);
107+
108+
return serializedDictionary;
109+
}
110+
111+
private static void Save()
112+
{
113+
var json = JsonSerialization.ToJson(Prefs);
114+
115+
File.WriteAllText(FILE, json);
116+
}
117+
}
118+
}

Assets/Package/Editor/JsonEditorPrefs.cs.meta Assets/Package/Editor/Helpers/UserSettingsPrefs.cs.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)