Skip to content

Commit 2b19a9b

Browse files
committed
Updated Installer
1 parent bc6ebcf commit 2b19a9b

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

MLAPI-Editor/MLAPIEditor.cs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@ public class MLAPIEditor : EditorWindow
2727
{
2828
private GithubRelease[] releases = new GithubRelease[0];
2929
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
3531
{
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+
}
4740
}
48-
49-
private void Awake()
41+
private long lastUpdated
5042
{
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+
}
5251
}
5352

54-
private void OnFocus()
53+
[MenuItem("Window/MLAPI")]
54+
public static void ShowWindow()
5555
{
56-
Init();
56+
GetWindow<MLAPIEditor>();
5757
}
5858

5959
private void OnGUI()
@@ -100,17 +100,24 @@ private void OnGUI()
100100
}
101101
}
102102

103-
GUILayout.BeginArea(new Rect(5, position.height - 20, position.width, 20));
103+
GUILayout.BeginArea(new Rect(5, position.height - 40, position.width, 40));
104104

105-
if (GUILayout.Button("Check for updates"))
105+
if (GUILayout.Button("Fetch releases"))
106106
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+
}
107114

108115
GUILayout.EndArea();
109116

110117
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);
112119

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)
114121
GetReleases();
115122

116123
Repaint();
@@ -135,7 +142,6 @@ private void InstallRelease(int index)
135142
AssetDatabase.ImportPackage(Application.dataPath + "/MLAPI/Lib/" + releases[index].assets[i].name, false);
136143
}
137144

138-
EditorPrefs.SetString("MLAPI_version", releases[index].tag_name);
139145
currentVersion = releases[index].tag_name;
140146
AssetDatabase.Refresh();
141147
}

0 commit comments

Comments
 (0)