11using System ;
2- using System . Collections . Generic ;
32
43using UnityEditor ;
54
65namespace Toolbox . Editor
76{
7+ /// <summary>
8+ /// Additional overlay for <see cref="EditorPrefs"/>.
9+ /// This utility class is Work in Progress.
10+ /// </summary>
811 internal static class ToolboxPrefs
912 {
10- private const string separator = "." ;
11- private const string keyBase = "Toolbox" ;
12-
13- private static readonly HashSet < string > usedKeys = new HashSet < string > ( ) ;
14-
15-
16- private static string GetKey ( object causer , string propertyName )
17- {
18- return GetKey ( causer . GetType ( ) , propertyName ) ;
19- }
20-
2113 private static string GetKey ( Type causer , string propertyName )
2214 {
2315 return GetKey ( causer . Name , propertyName ) ;
2416 }
2517
2618 private static string GetKey ( string causer , string propertyName )
2719 {
28- return string . Format ( "{0}{3}{1}{3}{2}" , keyBase , causer , propertyName , separator ) ;
20+ return string . Format ( "{0}{3}{1}{3}{2}" , "Toolbox" , causer , propertyName , "." ) ;
2921 }
3022
3123
@@ -34,20 +26,48 @@ public static void DeleteAll()
3426 EditorPrefs . DeleteAll ( ) ;
3527 }
3628
37- public static void DeleteCached ( )
29+ public static bool GetBool ( object causer , string propertyName , bool defaultValue = false )
3830 {
39- //TODO:
31+ return GetBool ( causer . GetType ( ) , propertyName , defaultValue ) ;
4032 }
4133
42- public static bool GetBool ( string causer , string propertyName , bool defaultValue )
34+ public static bool GetBool ( Type causer , string propertyName , bool defaultValue = false )
4335 {
4436 var key = GetKey ( causer , propertyName ) ;
4537 return EditorPrefs . GetBool ( key , defaultValue ) ;
4638 }
4739
48- public static T GetValue < T > ( string causer , string propertyName , T defaultValue )
40+ public static void SetBool ( object causer , string propertyName , bool value )
41+ {
42+ SetBool ( causer . GetType ( ) , propertyName , value ) ;
43+ }
44+
45+ public static void SetBool ( Type causer , string propertyName , bool value )
46+ {
47+ var key = GetKey ( causer , propertyName ) ;
48+ EditorPrefs . SetBool ( key , value ) ;
49+ }
50+
51+ public static int GetInt ( object causer , string propertyName , int defaultValue = 0 )
52+ {
53+ return GetInt ( causer . GetType ( ) , propertyName , defaultValue ) ;
54+ }
55+
56+ public static int GetInt ( Type causer , string propertyName , int defaultValue = 0 )
57+ {
58+ var key = GetKey ( causer , propertyName ) ;
59+ return EditorPrefs . GetInt ( key , defaultValue ) ;
60+ }
61+
62+ public static void SetInt ( object causer , string propertyName , int value )
63+ {
64+ SetInt ( causer . GetType ( ) , propertyName , value ) ;
65+ }
66+
67+ public static void SetInt ( Type causer , string propertyName , int value )
4968 {
50- return default ;
69+ var key = GetKey ( causer , propertyName ) ;
70+ EditorPrefs . SetInt ( key , value ) ;
5171 }
5272 }
5373}
0 commit comments