示例#1
0
        public static void OnVersionStringReceived(string lastestVersion)
        {
            int latestVersionNumber  = 0;
            int currentVersionNumber = 0;

            if (int.TryParse(lastestVersion, out latestVersionNumber) &&
                int.TryParse(currentVersion, out currentVersionNumber))
            {
                if (latestVersionNumber <= currentVersionNumber)
                {
                    if (checkUpdateFromMenu)
                    {
                        EditorUtility.DisplayDialog("Maquette Unity Editor Addon",
                                                    string.Format("Current version (version {0}) is up to date.", latestVersionNumber), "OK");
                    }
                }
                else
                {
                    if (EditorUtility.DisplayDialog("Maquette Unity Editor Addon",
                                                    string.Format("A new version (version {0}) is availabe for download.", latestVersionNumber),
                                                    "Download update", "Cancel"))
                    {
                        var www = UnityWebRequest.Get(unityPackageUrl);
                        www.SendWebRequest();

                        ContinuationManager.Add(() => www.isDone, () =>
                        {
                            if (!string.IsNullOrEmpty(www.error))
                            {
                                Debug.Log("WWW failed: " + www.error);
                                return;
                            }

                            // Debug.Log("WWW downloaded: " + www.downloadHandler.data);

                            string downloadFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                            string packagePath        = Path.Combine(downloadFolderPath, "MaquetteUnityEditorAddon.unitypackage");

                            File.WriteAllBytes(packagePath, www.downloadHandler.data);

                            AssetDatabase.ImportPackage(packagePath, true);
                        });

                        latestVersion = "";
                    }
                }
            }
        }
示例#2
0
        private static void CheckVersionUpdate()
        {
            var www = UnityWebRequest.Get(versionUrl);

            www.SendWebRequest();

            ContinuationManager.Add(() => www.isDone, () =>
            {
                if (!string.IsNullOrEmpty(www.error))
                {
                    Debug.Log("WWW failed: " + www.error);
                    return;
                }

                latestVersion = www.downloadHandler.text;
                OnVersionStringReceived(latestVersion);
            });
        }