10 using System.Text.RegularExpressions;
15 const string currentVersion =
"1.2.3";
16 const string versionUrl =
"http://media.steampowered.com/apps/steamvr/unitypluginversion.txt";
17 const string notesUrl =
"http://media.steampowered.com/apps/steamvr/unityplugin-v{0}.txt";
18 const string pluginUrl =
"http://u3d.as/content/valve-corporation/steam-vr-plugin";
19 const string doNotShowKey =
"SteamVR.DoNotShow.v{0}";
21 static bool gotVersion =
false;
22 static WWW wwwVersion, wwwNotes;
23 static string version, notes;
28 EditorApplication.update += Update;
35 if (wwwVersion == null)
36 wwwVersion =
new WWW(versionUrl);
38 if (!wwwVersion.isDone)
41 if (UrlSuccess(wwwVersion))
42 version = wwwVersion.text;
49 var url = string.Format(notesUrl, version);
50 wwwNotes =
new WWW(url);
52 window = GetWindow<SteamVR_Update>(
true);
53 window.minSize =
new Vector2(320, 440);
63 if (UrlSuccess(wwwNotes))
64 notes = wwwNotes.text;
72 EditorApplication.update -= Update;
75 static bool UrlSuccess(WWW www)
77 if (!
string.IsNullOrEmpty(www.error))
79 if (Regex.IsMatch(www.text,
"404 not found", RegexOptions.IgnoreCase))
84 static bool ShouldDisplay()
86 if (
string.IsNullOrEmpty(version))
88 if (version == currentVersion)
90 if (EditorPrefs.HasKey(
string.Format(doNotShowKey, version)))
94 var versionSplit = version.Split(
'.');
95 var currentVersionSplit = currentVersion.Split(
'.');
96 for (
int i = 0; i < versionSplit.Length && i < currentVersionSplit.Length; i++)
98 int versionValue, currentVersionValue;
99 if (
int.TryParse(versionSplit[i], out versionValue) &&
100 int.TryParse(currentVersionSplit[i], out currentVersionValue))
102 if (versionValue > currentVersionValue)
104 if (versionValue < currentVersionValue)
110 if (versionSplit.Length <= currentVersionSplit.Length)
116 Vector2 scrollPosition;
119 string GetResourcePath()
121 var ms = MonoScript.FromScriptableObject(
this);
122 var path = AssetDatabase.GetAssetPath(ms);
123 path = Path.GetDirectoryName(path);
124 return path.Substring(0, path.Length -
"Editor".Length) +
"Textures/";
129 EditorGUILayout.HelpBox(
"A new version of the SteamVR plugin is available!", MessageType.Warning);
131 var resourcePath = GetResourcePath();
132 var logo = AssetDatabase.LoadAssetAtPath<Texture2D>(resourcePath +
"logo.png");
133 var rect = GUILayoutUtility.GetRect(position.width, 150, GUI.skin.box);
135 GUI.DrawTexture(rect, logo, ScaleMode.ScaleToFit);
137 scrollPosition = GUILayout.BeginScrollView(scrollPosition);
139 GUILayout.Label(
"Current version: " + currentVersion);
140 GUILayout.Label(
"New version: " + version);
144 GUILayout.Label(
"Release notes:");
145 EditorGUILayout.HelpBox(notes, MessageType.Info);
148 GUILayout.EndScrollView();
150 GUILayout.FlexibleSpace();
152 if (GUILayout.Button(
"Get Latest Version"))
154 Application.OpenURL(pluginUrl);
157 EditorGUI.BeginChangeCheck();
158 var doNotShow = GUILayout.Toggle(toggleState,
"Do not prompt for this version again.");
159 if (EditorGUI.EndChangeCheck())
161 toggleState = doNotShow;
162 var key = string.Format(doNotShowKey, version);
164 EditorPrefs.SetBool(key,
true);
166 EditorPrefs.DeleteKey(key);