Skip to content

Commit 58b7fcb

Browse files
committed
Fixed compilation on Editor Dll
1 parent c405db6 commit 58b7fcb

File tree

7 files changed

+399
-380
lines changed

7 files changed

+399
-380
lines changed

MLAPI-Editor/GithubAsset.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
using System;
22

3-
[Serializable]
4-
public class GithubAsset
3+
namespace UnityEditor
54
{
6-
public string browser_download_url;
7-
public string name;
5+
[Serializable]
6+
public class GithubAsset
7+
{
8+
public string browser_download_url;
9+
public string name;
10+
}
811
}

MLAPI-Editor/GithubRelease.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22

3-
[Serializable]
4-
public class GithubRelease
3+
namespace UnityEditor
54
{
6-
public string html_url;
7-
public string tag_name;
8-
public string name;
9-
public string body;
10-
public string published_at;
11-
public bool prerelease;
12-
public GithubAsset[] assets;
5+
[Serializable]
6+
public class GithubRelease
7+
{
8+
public string html_url;
9+
public string tag_name;
10+
public string name;
11+
public string body;
12+
public string published_at;
13+
public bool prerelease;
14+
public GithubAsset[] assets;
15+
}
1316
}

MLAPI-Editor/MLAPI-Editor.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
<AppDesignerFolder>Properties</AppDesignerFolder>
1010
<RootNamespace>MLAPI_Editor</RootNamespace>
1111
<AssemblyName>MLAPI-Editor</AssemblyName>
12-
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
1313
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
1415
</PropertyGroup>
1516
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1617
<DebugSymbols>true</DebugSymbols>
@@ -49,6 +50,7 @@
4950
<Compile Include="GithubAsset.cs" />
5051
<Compile Include="GithubRelease.cs" />
5152
<Compile Include="MLAPIEditor.cs" />
53+
<Compile Include="MLAPIProfiler.cs" />
5254
<Compile Include="NetworkedAnimatorEditor.cs" />
5355
<Compile Include="NetworkedBehaviourEditor.cs" />
5456
<Compile Include="NetworkedObjectEditor.cs" />

MLAPI-Editor/MLAPIEditor.cs

Lines changed: 134 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,175 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using UnityEditor;
54
using UnityEngine;
65

7-
public class MLAPIEditor : EditorWindow
6+
namespace UnityEditor
87
{
9-
private GithubRelease[] releases = new GithubRelease[0];
10-
private bool[] foldoutStatus = new bool[0];
11-
private long lastUpdated = 0;
12-
private string currentVersion;
13-
14-
[MenuItem("Window/MLAPI")]
15-
public static void ShowWindow()
8+
public class MLAPIEditor : EditorWindow
169
{
17-
GetWindow<MLAPIEditor>();
18-
}
10+
private GithubRelease[] releases = new GithubRelease[0];
11+
private bool[] foldoutStatus = new bool[0];
12+
private long lastUpdated = 0;
13+
private string currentVersion;
1914

20-
private void Init()
21-
{
22-
lastUpdated = 0;
15+
[MenuItem("Window/MLAPI")]
16+
public static void ShowWindow()
17+
{
18+
GetWindow<MLAPIEditor>();
19+
}
2320

24-
if (EditorPrefs.HasKey("MLAPI_version"))
25-
currentVersion = EditorPrefs.GetString("MLAPI_version");
26-
else
27-
currentVersion = "None";
28-
}
21+
private void Init()
22+
{
23+
lastUpdated = 0;
2924

30-
private void Awake()
31-
{
32-
Init();
33-
}
25+
if (EditorPrefs.HasKey("MLAPI_version"))
26+
currentVersion = EditorPrefs.GetString("MLAPI_version");
27+
else
28+
currentVersion = "None";
29+
}
3430

35-
private void OnFocus()
36-
{
37-
Init();
38-
}
31+
private void Awake()
32+
{
33+
Init();
34+
}
3935

40-
private void OnGUI()
41-
{
42-
if(foldoutStatus != null)
36+
private void OnFocus()
4337
{
44-
for (int i = 0; i < foldoutStatus.Length; i++)
38+
Init();
39+
}
40+
41+
private void OnGUI()
42+
{
43+
if (foldoutStatus != null)
4544
{
46-
if (releases[i] == null)
47-
continue;
48-
foldoutStatus[i] = EditorGUILayout.Foldout(foldoutStatus[i], releases[i].tag_name + " - " + releases[i].name);
49-
if (foldoutStatus[i])
45+
for (int i = 0; i < foldoutStatus.Length; i++)
5046
{
51-
EditorGUI.indentLevel++;
52-
EditorGUILayout.LabelField("Release notes", EditorStyles.boldLabel);
53-
EditorGUILayout.LabelField(releases[i].body, EditorStyles.wordWrappedLabel);
54-
EditorGUILayout.Space();
55-
EditorGUILayout.Space();
56-
if (releases[i].prerelease)
47+
if (releases[i] == null)
48+
continue;
49+
foldoutStatus[i] = EditorGUILayout.Foldout(foldoutStatus[i], releases[i].tag_name + " - " + releases[i].name);
50+
if (foldoutStatus[i])
5751
{
58-
GUIStyle style = new GUIStyle(EditorStyles.boldLabel);
59-
style.normal.textColor = new Color(1f, 0.5f, 0f);
60-
EditorGUILayout.LabelField("Pre-release", style);
52+
EditorGUI.indentLevel++;
53+
EditorGUILayout.LabelField("Release notes", EditorStyles.boldLabel);
54+
EditorGUILayout.LabelField(releases[i].body, EditorStyles.wordWrappedLabel);
55+
EditorGUILayout.Space();
56+
EditorGUILayout.Space();
57+
if (releases[i].prerelease)
58+
{
59+
GUIStyle style = new GUIStyle(EditorStyles.boldLabel);
60+
style.normal.textColor = new Color(1f, 0.5f, 0f);
61+
EditorGUILayout.LabelField("Pre-release", style);
62+
}
63+
else
64+
{
65+
GUIStyle style = new GUIStyle(EditorStyles.boldLabel);
66+
style.normal.textColor = new Color(0f, 1f, 0f);
67+
EditorGUILayout.LabelField("Stable-release", style);
68+
}
69+
if (currentVersion == releases[i].tag_name)
70+
{
71+
GUIStyle boldStyle = new GUIStyle(EditorStyles.boldLabel);
72+
boldStyle.normal.textColor = new Color(0.3f, 1f, 0.3f);
73+
EditorGUILayout.LabelField("Installed", boldStyle);
74+
}
75+
EditorGUILayout.LabelField("Release date: " + DateTime.Parse(DateTime.Parse(releases[i].published_at).ToString()), EditorStyles.miniBoldLabel);
76+
77+
if (currentVersion != releases[i].tag_name && GUILayout.Button("Install"))
78+
InstallRelease(i);
79+
80+
EditorGUI.indentLevel--;
6181
}
62-
else
63-
{
64-
GUIStyle style = new GUIStyle(EditorStyles.boldLabel);
65-
style.normal.textColor = new Color(0f, 1f, 0f);
66-
EditorGUILayout.LabelField("Stable-release", style);
67-
}
68-
if (currentVersion == releases[i].tag_name)
69-
{
70-
GUIStyle boldStyle = new GUIStyle(EditorStyles.boldLabel);
71-
boldStyle.normal.textColor = new Color(0.3f, 1f, 0.3f);
72-
EditorGUILayout.LabelField("Installed", boldStyle);
73-
}
74-
EditorGUILayout.LabelField("Release date: " + DateTime.Parse(DateTime.Parse(releases[i].published_at).ToString()), EditorStyles.miniBoldLabel);
75-
76-
if(currentVersion != releases[i].tag_name && GUILayout.Button("Install"))
77-
InstallRelease(i);
78-
79-
EditorGUI.indentLevel--;
8082
}
8183
}
82-
}
8384

84-
GUILayout.BeginArea(new Rect(5, position.height - 20, position.width, 20));
85+
GUILayout.BeginArea(new Rect(5, position.height - 20, position.width, 20));
8586

86-
if (GUILayout.Button("Check for updates"))
87-
GetReleases();
87+
if (GUILayout.Button("Check for updates"))
88+
GetReleases();
8889

89-
GUILayout.EndArea();
90+
GUILayout.EndArea();
9091

91-
string lastUpdatedString = lastUpdated == 0 ? "Never" : new DateTime(lastUpdated).ToShortTimeString();
92-
EditorGUI.LabelField(new Rect(5, position.height - 40, position.width, 20), "Last checked: " + lastUpdatedString, EditorStyles.centeredGreyMiniLabel);
92+
string lastUpdatedString = lastUpdated == 0 ? "Never" : new DateTime(lastUpdated).ToShortTimeString();
93+
EditorGUI.LabelField(new Rect(5, position.height - 40, position.width, 20), "Last checked: " + lastUpdatedString, EditorStyles.centeredGreyMiniLabel);
9394

94-
if ((DateTime.Now - new DateTime(lastUpdated)).Seconds > 3600)
95-
GetReleases();
95+
if ((DateTime.Now - new DateTime(lastUpdated)).Seconds > 3600)
96+
GetReleases();
9697

97-
Repaint();
98-
}
98+
Repaint();
99+
}
99100

100-
private void InstallRelease(int index)
101-
{
102-
for (int i = 0; i < releases[index].assets.Length; i++)
101+
private void InstallRelease(int index)
103102
{
104-
WWW www = new WWW(releases[index].assets[i].browser_download_url);
105-
while (!www.isDone && string.IsNullOrEmpty(www.error))
103+
for (int i = 0; i < releases[index].assets.Length; i++)
106104
{
107-
EditorGUI.ProgressBar(new Rect(5, position.height - 60, position.width, 20), www.progress, "Installing " + i + "/" + releases[index].assets.Length);
108-
}
109-
110-
if(!Directory.Exists(Application.dataPath + "/MLAPI/Lib/"))
111-
Directory.CreateDirectory(Application.dataPath + "/MLAPI/Lib/");
112-
113-
File.WriteAllBytes(Application.dataPath + "/MLAPI/Lib/" + releases[index].assets[i].name, www.bytes);
105+
WWW www = new WWW(releases[index].assets[i].browser_download_url);
106+
while (!www.isDone && string.IsNullOrEmpty(www.error))
107+
{
108+
EditorGUI.ProgressBar(new Rect(5, position.height - 60, position.width, 20), www.progress, "Installing " + i + "/" + releases[index].assets.Length);
109+
}
114110

115-
if (releases[index].assets[i].name.EndsWith(".unitypackage"))
116-
AssetDatabase.ImportPackage(Application.dataPath + "/MLAPI/Lib/" + releases[index].assets[i].name, false);
117-
}
111+
if (!Directory.Exists(Application.dataPath + "/MLAPI/Lib/"))
112+
Directory.CreateDirectory(Application.dataPath + "/MLAPI/Lib/");
118113

119-
EditorPrefs.SetString("MLAPI_version", releases[index].tag_name);
120-
currentVersion = releases[index].tag_name;
121-
AssetDatabase.Refresh();
122-
}
114+
File.WriteAllBytes(Application.dataPath + "/MLAPI/Lib/" + releases[index].assets[i].name, www.bytes);
123115

124-
private void GetReleases()
125-
{
126-
lastUpdated = DateTime.Now.Ticks;
116+
if (releases[index].assets[i].name.EndsWith(".unitypackage"))
117+
AssetDatabase.ImportPackage(Application.dataPath + "/MLAPI/Lib/" + releases[index].assets[i].name, false);
118+
}
127119

128-
WWW www = new WWW("https://api.github.com/repos/TwoTenPvP/MLAPI/releases");
129-
while(!www.isDone && string.IsNullOrEmpty(www.error))
130-
{
131-
EditorGUI.ProgressBar(new Rect(5, position.height - 60, position.width, 20), www.progress, "Fetching...");
120+
EditorPrefs.SetString("MLAPI_version", releases[index].tag_name);
121+
currentVersion = releases[index].tag_name;
122+
AssetDatabase.Refresh();
132123
}
133-
string json = www.text;
134-
135-
//This makes it from a json array to the individual objects in the array.
136-
//The JSON serializer cant take arrays. We have to split it up outselves.
137-
List<string> releasesJson = new List<string>();
138-
int depth = 0;
139-
string currentObject = "";
140-
for (int i = 1; i < json.Length - 1; i++)
124+
125+
private void GetReleases()
141126
{
142-
if (json[i] == '[')
143-
depth++;
144-
else if (json[i] == ']')
145-
depth--;
146-
else if (json[i] == '{')
147-
depth++;
148-
else if (json[i] == '}')
149-
depth--;
150-
151-
if ((depth == 0 && json[i] != ',') || depth > 0)
152-
currentObject += json[i];
153-
154-
if (depth == 0 && json[i] == ',')
127+
lastUpdated = DateTime.Now.Ticks;
128+
129+
WWW www = new WWW("https://api.github.com/repos/TwoTenPvP/MLAPI/releases");
130+
while (!www.isDone && string.IsNullOrEmpty(www.error))
155131
{
156-
releasesJson.Add(currentObject);
157-
currentObject = "";
132+
EditorGUI.ProgressBar(new Rect(5, position.height - 60, position.width, 20), www.progress, "Fetching...");
133+
}
134+
string json = www.text;
135+
136+
//This makes it from a json array to the individual objects in the array.
137+
//The JSON serializer cant take arrays. We have to split it up outselves.
138+
List<string> releasesJson = new List<string>();
139+
int depth = 0;
140+
string currentObject = "";
141+
for (int i = 1; i < json.Length - 1; i++)
142+
{
143+
if (json[i] == '[')
144+
depth++;
145+
else if (json[i] == ']')
146+
depth--;
147+
else if (json[i] == '{')
148+
depth++;
149+
else if (json[i] == '}')
150+
depth--;
151+
152+
if ((depth == 0 && json[i] != ',') || depth > 0)
153+
currentObject += json[i];
154+
155+
if (depth == 0 && json[i] == ',')
156+
{
157+
releasesJson.Add(currentObject);
158+
currentObject = "";
159+
}
158160
}
159-
}
160161

161-
releases = new GithubRelease[releasesJson.Count];
162-
foldoutStatus = new bool[releasesJson.Count];
162+
releases = new GithubRelease[releasesJson.Count];
163+
foldoutStatus = new bool[releasesJson.Count];
163164

164-
for (int i = 0; i < releasesJson.Count; i++)
165-
{
166-
releases[i] = JsonUtility.FromJson<GithubRelease>(releasesJson[i]);
167-
if (i == 0)
168-
foldoutStatus[i] = true;
169-
else
170-
foldoutStatus[i] = false;
165+
for (int i = 0; i < releasesJson.Count; i++)
166+
{
167+
releases[i] = JsonUtility.FromJson<GithubRelease>(releasesJson[i]);
168+
if (i == 0)
169+
foldoutStatus[i] = true;
170+
else
171+
foldoutStatus[i] = false;
172+
}
171173
}
172174
}
173175
}

0 commit comments

Comments
 (0)