@@ -27,33 +27,33 @@ public class MLAPIEditor : EditorWindow
27
27
{
28
28
private GithubRelease [ ] releases = new GithubRelease [ 0 ] ;
29
29
private bool [ ] foldoutStatus = new bool [ 0 ] ;
30
- private long lastUpdated = 0 ;
31
- private string currentVersion ;
32
-
33
- [ MenuItem ( "Window/MLAPI" ) ]
34
- public static void ShowWindow ( )
30
+ private string currentVersion
35
31
{
36
- GetWindow < MLAPIEditor > ( ) ;
37
- }
38
-
39
- private void Init ( )
40
- {
41
- lastUpdated = 0 ;
42
-
43
- if ( EditorPrefs . HasKey ( "MLAPI_version" ) )
44
- currentVersion = EditorPrefs . GetString ( "MLAPI_version" ) ;
45
- else
46
- currentVersion = "None" ;
32
+ get
33
+ {
34
+ return EditorPrefs . GetString ( "MLAPI_version" , "None" ) ;
35
+ }
36
+ set
37
+ {
38
+ EditorPrefs . SetString ( "MLAPI_version" , value ) ;
39
+ }
47
40
}
48
-
49
- private void Awake ( )
41
+ private long lastUpdated
50
42
{
51
- Init ( ) ;
43
+ get
44
+ {
45
+ return Convert . ToInt64 ( EditorPrefs . GetString ( "MLAPI_lastUpdated" , "0" ) ) ;
46
+ }
47
+ set
48
+ {
49
+ EditorPrefs . SetString ( "MLAPI_lastUpdated" , Convert . ToString ( value ) ) ;
50
+ }
52
51
}
53
52
54
- private void OnFocus ( )
53
+ [ MenuItem ( "Window/MLAPI" ) ]
54
+ public static void ShowWindow ( )
55
55
{
56
- Init ( ) ;
56
+ GetWindow < MLAPIEditor > ( ) ;
57
57
}
58
58
59
59
private void OnGUI ( )
@@ -100,17 +100,24 @@ private void OnGUI()
100
100
}
101
101
}
102
102
103
- GUILayout . BeginArea ( new Rect ( 5 , position . height - 20 , position . width , 20 ) ) ;
103
+ GUILayout . BeginArea ( new Rect ( 5 , position . height - 40 , position . width , 40 ) ) ;
104
104
105
- if ( GUILayout . Button ( "Check for updates " ) )
105
+ if ( GUILayout . Button ( "Fetch releases " ) )
106
106
GetReleases ( ) ;
107
+ if ( GUILayout . Button ( "Reset defaults" ) )
108
+ {
109
+ releases = new GithubRelease [ 0 ] ;
110
+ foldoutStatus = new bool [ 0 ] ;
111
+ if ( EditorPrefs . HasKey ( "MLAPI_version" ) ) EditorPrefs . DeleteKey ( "MLAPI_version" ) ;
112
+ if ( EditorPrefs . HasKey ( "MLAPI_lastUpdated" ) ) EditorPrefs . DeleteKey ( "MLAPI_lastUpdated" ) ;
113
+ }
107
114
108
115
GUILayout . EndArea ( ) ;
109
116
110
117
string lastUpdatedString = lastUpdated == 0 ? "Never" : new DateTime ( lastUpdated ) . ToShortTimeString ( ) ;
111
- EditorGUI . LabelField ( new Rect ( 5 , position . height - 40 , position . width , 20 ) , "Last checked: " + lastUpdatedString , EditorStyles . centeredGreyMiniLabel ) ;
118
+ EditorGUI . LabelField ( new Rect ( 5 , position . height - 60 , position . width , 20 ) , "Last checked: " + lastUpdatedString , EditorStyles . centeredGreyMiniLabel ) ;
112
119
113
- if ( ( DateTime . Now - new DateTime ( lastUpdated ) ) . Seconds > 3600 )
120
+ if ( ( releases . Length == 0 && ( DateTime . Now - new DateTime ( lastUpdated ) ) . TotalSeconds > 600 ) || ( DateTime . Now - new DateTime ( lastUpdated ) ) . TotalSeconds > 3600 )
114
121
GetReleases ( ) ;
115
122
116
123
Repaint ( ) ;
@@ -135,7 +142,6 @@ private void InstallRelease(int index)
135
142
AssetDatabase . ImportPackage ( Application . dataPath + "/MLAPI/Lib/" + releases [ index ] . assets [ i ] . name , false ) ;
136
143
}
137
144
138
- EditorPrefs . SetString ( "MLAPI_version" , releases [ index ] . tag_name ) ;
139
145
currentVersion = releases [ index ] . tag_name ;
140
146
AssetDatabase . Refresh ( ) ;
141
147
}
0 commit comments