diff --git a/com.stansassets.plugins-dev-kit/Editor/IMGUI/Headers/IMGUIBlockWithIndent.cs b/com.stansassets.plugins-dev-kit/Editor/IMGUI/Headers/IMGUIBlockWithIndent.cs index 4ea0b1d..e682931 100644 --- a/com.stansassets.plugins-dev-kit/Editor/IMGUI/Headers/IMGUIBlockWithIndent.cs +++ b/com.stansassets.plugins-dev-kit/Editor/IMGUI/Headers/IMGUIBlockWithIndent.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using UnityEngine; using UnityEditor; diff --git a/com.stansassets.plugins-dev-kit/Editor/UIToolkit/SettingsWindow/BaseTab.cs b/com.stansassets.plugins-dev-kit/Editor/UIToolkit/SettingsWindow/BaseTab.cs index e51d860..5d8cc09 100644 --- a/com.stansassets.plugins-dev-kit/Editor/UIToolkit/SettingsWindow/BaseTab.cs +++ b/com.stansassets.plugins-dev-kit/Editor/UIToolkit/SettingsWindow/BaseTab.cs @@ -1,7 +1,6 @@ #if UNITY_2019_4_OR_NEWER using StansAssets.Foundation.Editor; -using UnityEditor; using UnityEngine.UIElements; namespace StansAssets.Plugins.Editor diff --git a/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs new file mode 100644 index 0000000..339f3ac --- /dev/null +++ b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs @@ -0,0 +1,28 @@ +using System.Linq; + +namespace StansAssets.Plugins.Editor +{ + public class GitHubRelease + { + public string Name { get; private set; } + public string Tag { get; private set; } + + public void ReadJson (string json) + { + Name = FindValueByKey ("name", json); + Tag = FindValueByKey ("tag_name", json); + } + + string FindValueByKey (string key, string json) + { + // number of characters from the 1st char of the given key to the 1st char of corresponding value + int offsetBeforeValue = key.Length + 5; + string lookForString = $"\"{key}\""; + int position = json.IndexOf (lookForString) + offsetBeforeValue; + var value = (position > offsetBeforeValue) + ? new string(json.Skip (position).TakeWhile (c => c != '"').ToArray ()) + : string.Empty; + return value; + } + } +} diff --git a/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs.meta b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs.meta new file mode 100644 index 0000000..d90acd7 --- /dev/null +++ b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubRelease.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ef20256522cd4339913eee76e849c638 +timeCreated: 1615401859 \ No newline at end of file diff --git a/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs new file mode 100644 index 0000000..9d361a0 --- /dev/null +++ b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs @@ -0,0 +1,31 @@ +using System; +using UnityEngine.Networking; + +namespace StansAssets.Plugins.Editor +{ + public static class GitHubUtility + { + public static void GetLatestRelease (string url, Action callback) + { + var release = new GitHubRelease (); + var rq = UnityWebRequest.Get (GetReleaseInfoURL (url)); + rq.SendWebRequest ().completed += obj => { + release.ReadJson (rq.downloadHandler.text); + callback (release); + }; + } + + public static string GetReleaseInfoURL (string repositoryURL) + { + if (repositoryURL.Contains ("github.com")) { + return repositoryURL.Replace (@".git", @"/releases/latest") + .Replace (@"ssh://git@github.com:", @"https://api.github.com/repos/"); + } + else if (repositoryURL.Contains ("npmjs.org")) { + throw new NotImplementedException (); + } + + throw new NotImplementedException (); + } + } +} diff --git a/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs.meta b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs.meta new file mode 100644 index 0000000..268a0fe --- /dev/null +++ b/com.stansassets.plugins-dev-kit/Editor/Utility/GitHubUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a75ca5d93e3640d28b484907e79f0077 +timeCreated: 1615384062 \ No newline at end of file