SettingsGUILayout.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace UnityEditor.SettingsManagement
  6. {
  7. static class SettingsGUIStyles
  8. {
  9. const string k_SettingsGearIcon = "Packages/" + UserSettings.packageName + "/Content/Options.png";
  10. static bool s_Initialized;
  11. public static GUIStyle s_SettingsGizmo;
  12. public static GUIStyle s_SettingsArea;
  13. public static GUIStyle s_IndentedSettingBlock;
  14. static void Init()
  15. {
  16. if (s_Initialized)
  17. return;
  18. s_Initialized = true;
  19. s_SettingsGizmo = new GUIStyle()
  20. {
  21. normal = new GUIStyleState()
  22. {
  23. background = AssetDatabase.LoadAssetAtPath<Texture2D>(k_SettingsGearIcon)
  24. },
  25. fixedWidth = 14,
  26. fixedHeight = 14,
  27. padding = new RectOffset(0, 0, 0, 0),
  28. margin = new RectOffset(4, 4, 4, 4),
  29. imagePosition = ImagePosition.ImageOnly
  30. };
  31. s_SettingsArea = new GUIStyle()
  32. {
  33. margin = new RectOffset(6, 6, 0, 0)
  34. };
  35. s_IndentedSettingBlock = new GUIStyle()
  36. {
  37. padding = new RectOffset(16, 0, 0, 0)
  38. };
  39. }
  40. public static GUIStyle settingsGizmo
  41. {
  42. get
  43. {
  44. Init();
  45. return s_SettingsGizmo;
  46. }
  47. }
  48. public static GUIStyle settingsArea
  49. {
  50. get
  51. {
  52. Init();
  53. return s_SettingsArea;
  54. }
  55. }
  56. public static GUIStyle indentedSettingBlock
  57. {
  58. get
  59. {
  60. Init();
  61. return s_IndentedSettingBlock;
  62. }
  63. }
  64. }
  65. /// <summary>
  66. /// Extension methods for GUILayout that also implement settings-specific functionality.
  67. /// </summary>
  68. public static class SettingsGUILayout
  69. {
  70. /// <inheritdoc />
  71. /// <summary>
  72. /// Create an indented GUI section.
  73. /// </summary>
  74. public class IndentedGroup : IDisposable
  75. {
  76. bool m_IsDisposed;
  77. /// <summary>
  78. /// Create an indented GUI section.
  79. /// </summary>
  80. public IndentedGroup()
  81. {
  82. EditorGUIUtility.labelWidth -= SettingsGUIStyles.indentedSettingBlock.padding.left - 4;
  83. GUILayout.BeginVertical(SettingsGUIStyles.indentedSettingBlock);
  84. }
  85. /// <summary>
  86. /// Create an indented GUI section with a header.
  87. /// </summary>
  88. public IndentedGroup(string label)
  89. {
  90. GUILayout.Label(label);
  91. EditorGUIUtility.labelWidth -= SettingsGUIStyles.indentedSettingBlock.padding.left - 4;
  92. GUILayout.BeginVertical(SettingsGUIStyles.indentedSettingBlock);
  93. }
  94. /// <inheritdoc />
  95. /// <summary>
  96. /// Revert the GUI indent back to it's original value.
  97. /// </summary>
  98. public void Dispose()
  99. {
  100. if (m_IsDisposed)
  101. return;
  102. m_IsDisposed = true;
  103. GUILayout.EndVertical();
  104. EditorGUIUtility.labelWidth += SettingsGUIStyles.indentedSettingBlock.padding.left - 4;
  105. }
  106. }
  107. internal static HashSet<string> s_Keywords = null;
  108. internal static bool MatchSearchGroups(string searchContext, string label)
  109. {
  110. if (s_Keywords != null)
  111. {
  112. foreach (var keyword in label.Split(' '))
  113. s_Keywords.Add(keyword);
  114. }
  115. if (searchContext == null)
  116. return true;
  117. var ctx = searchContext.Trim();
  118. if (string.IsNullOrEmpty(ctx))
  119. return true;
  120. var split = searchContext.Split(' ');
  121. return split.Any(x => !string.IsNullOrEmpty(x) && label.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) > -1);
  122. }
  123. internal static bool DebugModeFilter(IUserSetting pref)
  124. {
  125. if (!EditorPrefs.GetBool("DeveloperMode", false))
  126. return true;
  127. if (pref.scope == SettingsScope.Project && UserSettingsProvider.showProjectSettings)
  128. return true;
  129. if (pref.scope == SettingsScope.User && UserSettingsProvider.showUserSettings)
  130. return true;
  131. return false;
  132. }
  133. /// <summary>
  134. /// A slider that implements search filtering.
  135. /// </summary>
  136. /// <param name="label">Label in front of the value field.</param>
  137. /// <param name="value">The value to edit.</param>
  138. /// <param name="min">The value at the left end of the slider.</param>
  139. /// <param name="max">The value at the right end of the slider.</param>
  140. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  141. /// <returns>The value that has been set by the user.</returns>
  142. public static float SearchableSlider(GUIContent label, float value, float min, float max, string searchContext)
  143. {
  144. if (!MatchSearchGroups(searchContext, label.text))
  145. return value;
  146. return EditorGUILayout.Slider(label, value, min, max);
  147. }
  148. /// <summary>
  149. /// A slider that implements search filtering.
  150. /// </summary>
  151. /// <param name="label">Label in front of the value field.</param>
  152. /// <param name="value">The value to edit.</param>
  153. /// <param name="min">The value at the left end of the slider.</param>
  154. /// <param name="max">The value at the right end of the slider.</param>
  155. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  156. /// <returns>The value that has been set by the user.</returns>
  157. public static float SearchableSlider(string label, float value, float min, float max, string searchContext)
  158. {
  159. if (!MatchSearchGroups(searchContext, label))
  160. return value;
  161. return EditorGUILayout.Slider(label, value, min, max);
  162. }
  163. /// <summary>
  164. /// A float field that implements search filtering.
  165. /// </summary>
  166. /// <param name="label">Label in front of the value field.</param>
  167. /// <param name="value">The value to edit.</param>
  168. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  169. /// <returns>The value that has been set by the user.</returns>
  170. public static float SearchableFloatField(GUIContent label, float value, string searchContext)
  171. {
  172. if (!MatchSearchGroups(searchContext, label.text))
  173. return value;
  174. return EditorGUILayout.FloatField(label, value);
  175. }
  176. /// <summary>
  177. /// A float field that implements search filtering.
  178. /// </summary>
  179. /// <param name="label">Label in front of the value field.</param>
  180. /// <param name="value">The value to edit.</param>
  181. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  182. /// <returns>The value that has been set by the user.</returns>
  183. public static float SearchableFloatField(string label, float value, string searchContext)
  184. {
  185. if (!MatchSearchGroups(searchContext, label))
  186. return value;
  187. return EditorGUILayout.FloatField(label, value);
  188. }
  189. /// <summary>
  190. /// An int field that implements search filtering.
  191. /// </summary>
  192. /// <param name="label">Label in front of the value field.</param>
  193. /// <param name="value">The value to edit.</param>
  194. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  195. /// <returns>The value that has been set by the user.</returns>
  196. public static int SearchableIntField(GUIContent label, int value, string searchContext)
  197. {
  198. if (!MatchSearchGroups(searchContext, label.text))
  199. return value;
  200. return EditorGUILayout.IntField(label, value);
  201. }
  202. /// <summary>
  203. /// An int field that implements search filtering.
  204. /// </summary>
  205. /// <param name="label">Label in front of the value field.</param>
  206. /// <param name="value">The value to edit.</param>
  207. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  208. /// <returns>The value that has been set by the user.</returns>
  209. public static int SearchableIntField(string label, int value, string searchContext)
  210. {
  211. if (!MatchSearchGroups(searchContext, label))
  212. return value;
  213. return EditorGUILayout.IntField(label, value);
  214. }
  215. /// <summary>
  216. /// An toggle field that implements search filtering.
  217. /// </summary>
  218. /// <param name="label">Label in front of the value field.</param>
  219. /// <param name="value">The value to edit.</param>
  220. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  221. /// <returns>The value that has been set by the user.</returns>
  222. public static bool SearchableToggle(GUIContent label, bool value, string searchContext)
  223. {
  224. if (!MatchSearchGroups(searchContext, label.text))
  225. return value;
  226. return EditorGUILayout.Toggle(label, value);
  227. }
  228. /// <summary>
  229. /// An toggle field that implements search filtering.
  230. /// </summary>
  231. /// <param name="label">Label in front of the value field.</param>
  232. /// <param name="value">The value to edit.</param>
  233. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  234. /// <returns>The value that has been set by the user.</returns>
  235. public static bool SearchableToggle(string label, bool value, string searchContext)
  236. {
  237. if (!MatchSearchGroups(searchContext, label))
  238. return value;
  239. return EditorGUILayout.Toggle(label, value);
  240. }
  241. /// <summary>
  242. /// An text field that implements search filtering.
  243. /// </summary>
  244. /// <param name="label">Label in front of the value field.</param>
  245. /// <param name="value">The value to edit.</param>
  246. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  247. /// <returns>The value that has been set by the user.</returns>
  248. public static string SearchableTextField(GUIContent label, string value, string searchContext)
  249. {
  250. if (!MatchSearchGroups(searchContext, label.text))
  251. return value;
  252. return EditorGUILayout.TextField(label, value);
  253. }
  254. /// <summary>
  255. /// An text field that implements search filtering.
  256. /// </summary>
  257. /// <param name="label">Label in front of the value field.</param>
  258. /// <param name="value">The value to edit.</param>
  259. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  260. /// <returns>The value that has been set by the user.</returns>
  261. public static string SearchableTextField(string label, string value, string searchContext)
  262. {
  263. if (!MatchSearchGroups(searchContext, label))
  264. return value;
  265. return EditorGUILayout.TextField(label, value);
  266. }
  267. /// <summary>
  268. /// An color field that implements search filtering.
  269. /// </summary>
  270. /// <param name="label">Label in front of the value field.</param>
  271. /// <param name="value">The value to edit.</param>
  272. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  273. /// <returns>The value that has been set by the user.</returns>
  274. public static Color SearchableColorField(GUIContent label, Color value, string searchContext)
  275. {
  276. if (!MatchSearchGroups(searchContext, label.text))
  277. return value;
  278. return EditorGUILayout.ColorField(label, value);
  279. }
  280. /// <summary>
  281. /// An color field that implements search filtering.
  282. /// </summary>
  283. /// <param name="label">Label in front of the value field.</param>
  284. /// <param name="value">The value to edit.</param>
  285. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  286. /// <returns>The value that has been set by the user.</returns>
  287. public static Color SearchableColorField(string label, Color value, string searchContext)
  288. {
  289. if (!MatchSearchGroups(searchContext, label))
  290. return value;
  291. return EditorGUILayout.ColorField(label, value);
  292. }
  293. /// <summary>
  294. /// A slider that implements search filtering and context menu reset.
  295. /// </summary>
  296. /// <param name="label">Label in front of the value field.</param>
  297. /// <param name="value">The value to edit.</param>
  298. /// <param name="min">The value at the left end of the slider.</param>
  299. /// <param name="max">The value at the right end of the slider.</param>
  300. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  301. /// <returns>The value that has been set by the user.</returns>
  302. public static float SettingsSlider(GUIContent label, UserSetting<float> value, float min, float max, string searchContext)
  303. {
  304. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  305. return value;
  306. var res = EditorGUILayout.Slider(label, value, min, max);
  307. DoResetContextMenuForLastRect(value);
  308. return res;
  309. }
  310. /// <summary>
  311. /// A slider that implements search filtering and context menu reset.
  312. /// </summary>
  313. /// <param name="label">Label in front of the value field.</param>
  314. /// <param name="value">The value to edit.</param>
  315. /// <param name="min">The value at the left end of the slider.</param>
  316. /// <param name="max">The value at the right end of the slider.</param>
  317. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  318. /// <returns>The value that has been set by the user.</returns>
  319. public static float SettingsSlider(string label, UserSetting<float> value, float min, float max, string searchContext)
  320. {
  321. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  322. return value;
  323. var res = EditorGUILayout.Slider(label, value, min, max);
  324. DoResetContextMenuForLastRect(value);
  325. return res;
  326. }
  327. /// <summary>
  328. /// A slider that implements search filtering and context menu reset.
  329. /// </summary>
  330. /// <param name="label">Label in front of the value field.</param>
  331. /// <param name="value">The value to edit.</param>
  332. /// <param name="min">The value at the left end of the slider.</param>
  333. /// <param name="max">The value at the right end of the slider.</param>
  334. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  335. /// <returns>The value that has been set by the user.</returns>
  336. public static int SettingsSlider(GUIContent label, UserSetting<int> value, int min, int max, string searchContext)
  337. {
  338. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  339. return value;
  340. var res = EditorGUILayout.IntSlider(label, value, min, max);
  341. DoResetContextMenuForLastRect(value);
  342. return res;
  343. }
  344. /// <summary>
  345. /// A slider that implements search filtering and context menu reset.
  346. /// </summary>
  347. /// <param name="label">Label in front of the value field.</param>
  348. /// <param name="value">The value to edit.</param>
  349. /// <param name="min">The value at the left end of the slider.</param>
  350. /// <param name="max">The value at the right end of the slider.</param>
  351. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  352. /// <returns>The value that has been set by the user.</returns>
  353. public static int SettingsSlider(string label, UserSetting<int> value, int min, int max, string searchContext)
  354. {
  355. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  356. return value;
  357. var res = EditorGUILayout.IntSlider(label, value, min, max);
  358. DoResetContextMenuForLastRect(value);
  359. return res;
  360. }
  361. /// <summary>
  362. /// A float field that implements search filtering and context menu reset.
  363. /// </summary>
  364. /// <param name="label">Label in front of the value field.</param>
  365. /// <param name="value">The value to edit.</param>
  366. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  367. /// <returns>The value that has been set by the user.</returns>
  368. public static float SettingsFloatField(GUIContent label, UserSetting<float> value, string searchContext)
  369. {
  370. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  371. return value;
  372. var res = EditorGUILayout.FloatField(label, value);
  373. DoResetContextMenuForLastRect(value);
  374. return res;
  375. }
  376. /// <summary>
  377. /// A float field that implements search filtering and context menu reset.
  378. /// </summary>
  379. /// <param name="label">Label in front of the value field.</param>
  380. /// <param name="value">The value to edit.</param>
  381. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  382. /// <returns>The value that has been set by the user.</returns>
  383. public static float SettingsFloatField(string label, UserSetting<float> value, string searchContext)
  384. {
  385. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  386. return value;
  387. var res = EditorGUILayout.FloatField(label, value);
  388. DoResetContextMenuForLastRect(value);
  389. return res;
  390. }
  391. /// <summary>
  392. /// An integer field that implements search filtering and context menu reset.
  393. /// </summary>
  394. /// <param name="label">Label in front of the value field.</param>
  395. /// <param name="value">The value to edit.</param>
  396. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  397. /// <returns>The value that has been set by the user.</returns>
  398. public static int SettingsIntField(GUIContent label, UserSetting<int> value, string searchContext)
  399. {
  400. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  401. return value;
  402. var res = EditorGUILayout.IntField(label, value);
  403. DoResetContextMenuForLastRect(value);
  404. return res;
  405. }
  406. /// <summary>
  407. /// An integer field that implements search filtering and context menu reset.
  408. /// </summary>
  409. /// <param name="label">Label in front of the value field.</param>
  410. /// <param name="value">The value to edit.</param>
  411. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  412. /// <returns>The value that has been set by the user.</returns>
  413. public static int SettingsIntField(string label, UserSetting<int> value, string searchContext)
  414. {
  415. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  416. return value;
  417. var res = EditorGUILayout.IntField(label, value);
  418. DoResetContextMenuForLastRect(value);
  419. return res;
  420. }
  421. /// <summary>
  422. /// A boolean toggle field that implements search filtering and context menu reset.
  423. /// </summary>
  424. /// <param name="label">Label in front of the value field.</param>
  425. /// <param name="value">The value to edit.</param>
  426. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  427. /// <returns>The value that has been set by the user.</returns>
  428. public static bool SettingsToggle(GUIContent label, UserSetting<bool> value, string searchContext)
  429. {
  430. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  431. return value;
  432. var res = EditorGUILayout.Toggle(label, value);
  433. DoResetContextMenuForLastRect(value);
  434. return res;
  435. }
  436. /// <summary>
  437. /// A boolean toggle field that implements search filtering and context menu reset.
  438. /// </summary>
  439. /// <param name="label">Label in front of the value field.</param>
  440. /// <param name="value">The value to edit.</param>
  441. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  442. /// <returns>The value that has been set by the user.</returns>
  443. public static bool SettingsToggle(string label, UserSetting<bool> value, string searchContext)
  444. {
  445. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  446. return value;
  447. var res = EditorGUILayout.Toggle(label, value);
  448. DoResetContextMenuForLastRect(value);
  449. return res;
  450. }
  451. /// <summary>
  452. /// A text field that implements search filtering and context menu reset.
  453. /// </summary>
  454. /// <param name="label">Label in front of the value field.</param>
  455. /// <param name="value">The value to edit.</param>
  456. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  457. /// <returns>The value that has been set by the user.</returns>
  458. public static string SettingsTextField(GUIContent label, UserSetting<string> value, string searchContext)
  459. {
  460. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  461. return value;
  462. var res = EditorGUILayout.TextField(label, value);
  463. DoResetContextMenuForLastRect(value);
  464. return res;
  465. }
  466. /// <summary>
  467. /// A text field that implements search filtering and context menu reset.
  468. /// </summary>
  469. /// <param name="label">Label in front of the value field.</param>
  470. /// <param name="value">The value to edit.</param>
  471. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  472. /// <returns>The value that has been set by the user.</returns>
  473. public static string SettingsTextField(string label, UserSetting<string> value, string searchContext)
  474. {
  475. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  476. return value;
  477. var res = EditorGUILayout.TextField(label, value);
  478. DoResetContextMenuForLastRect(value);
  479. return res;
  480. }
  481. /// <summary>
  482. /// A color field that implements search filtering and context menu reset.
  483. /// </summary>
  484. /// <param name="label">Label in front of the value field.</param>
  485. /// <param name="value">The value to edit.</param>
  486. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  487. /// <returns>The value that has been set by the user.</returns>
  488. public static Color SettingsColorField(GUIContent label, UserSetting<Color> value, string searchContext)
  489. {
  490. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label.text))
  491. return value;
  492. var res = EditorGUILayout.ColorField(label, value);
  493. DoResetContextMenuForLastRect(value);
  494. return res;
  495. }
  496. /// <summary>
  497. /// A color field that implements search filtering and context menu reset.
  498. /// </summary>
  499. /// <param name="label">Label in front of the value field.</param>
  500. /// <param name="value">The value to edit.</param>
  501. /// <param name="searchContext">A string representing the current search query. Empty or null strings are to be treated as matching any value.</param>
  502. /// <returns>The value that has been set by the user.</returns>
  503. public static Color SettingsColorField(string label, UserSetting<Color> value, string searchContext)
  504. {
  505. if (!DebugModeFilter(value) || !MatchSearchGroups(searchContext, label))
  506. return value;
  507. var res = EditorGUILayout.ColorField(label, value);
  508. DoResetContextMenuForLastRect(value);
  509. return res;
  510. }
  511. /// <summary>
  512. /// Using the last automatically layoutted rect, implement a context click menu for a user setting.
  513. /// </summary>
  514. /// <param name="setting">The target setting for the reset context menu.</param>
  515. public static void DoResetContextMenuForLastRect(IUserSetting setting)
  516. {
  517. DoResetContextMenu(GUILayoutUtility.GetLastRect(), setting);
  518. }
  519. static void DoResetContextMenu(Rect rect, IUserSetting pref)
  520. {
  521. var evt = Event.current;
  522. if (evt.type == EventType.ContextClick && rect.Contains(evt.mousePosition))
  523. {
  524. var menu = new GenericMenu();
  525. menu.AddItem(new GUIContent("Reset [" + pref.scope + "] " + pref.key), false, () =>
  526. {
  527. pref.Reset(true);
  528. });
  529. menu.ShowAsContext();
  530. }
  531. }
  532. }
  533. }