// Open recommended setting window (with possible new version prompt)
        // won't do any thing if the window is already opened
        public static void TryOpenRecommendedSettingWindow()
        {
            if (recommendedWindowOpened)
            {
                return;
            }

            windowInstance         = GetWindow <VIUVersionCheck>(true, "Vive Input Utility");
            windowInstance.minSize = new Vector2(240f, 550f);
            var rect = windowInstance.position;

            windowInstance.position = new Rect(Mathf.Max(rect.x, 50f), Mathf.Max(rect.y, 50f), rect.width, 200f + (showNewVersion ? 700f : 400f));
        }
        // check vive input utility version on github
        private static void CheckVersion()
        {
            // On Windows, PlaterSetting is stored at \HKEY_CURRENT_USER\Software\Unity Technologies\Unity Editor 5.x
            nextVersionCheckTimeKey = "ViveInputUtility." + PlayerSettings.productGUID + ".LastVersionCheckTime";
            doNotShowUpdateKey      = "ViveInputUtility." + PlayerSettings.productGUID + ".DoNotShowUpdate.v{0}";
            doNotShowSetupSwitch    = "ViveInputUtility." + PlayerSettings.productGUID + ".DoNotShowSetupSwitch";

            if (!completeCheckVersionFlow)
            {
                if (www == null) // web request not running
                {
                    if (EditorPrefs.HasKey(nextVersionCheckTimeKey) && DateTime.UtcNow < UtcDateTimeFromStr(EditorPrefs.GetString(nextVersionCheckTimeKey)))
                    {
                        completeCheckVersionFlow = true;
                        return;
                    }

                    www = new WWW(lastestVersionUrl);
                }

                if (!www.isDone)
                {
                    return;
                }

                if (UrlSuccess(www))
                {
                    EditorPrefs.SetString(nextVersionCheckTimeKey, UtcDateTimeToStr(DateTime.UtcNow.AddMinutes(versionCheckIntervalMinutes)));

                    latestRepoInfo = JsonUtility.FromJson <RepoInfo>(www.text);
                }

                showNewVersionInfo = ShouldDisplayNewUpdate();

                www.Dispose();
                www = null;

                completeCheckVersionFlow = true;
            }

            showSwitchSetup = showNewVersionInfo || !EditorPrefs.HasKey(doNotShowSetupSwitch);

            if (showNewVersionInfo || showSwitchSetup)
            {
                window         = GetWindow <VIUVersionCheck>(true, "Vive Input Utility");
                window.minSize = new Vector2(320, 440);
            }

            EditorApplication.update -= CheckVersion;
        }
Beispiel #3
0
        private void OnDestroy()
        {
            if (viuLogo != null)
            {
                viuLogo = null;
            }

            if (showNewVersion && toggleSkipThisVersion && !string.IsNullOrEmpty(ignoreThisVersionKey))
            {
                showNewVersion = false;
                VIUProjectSettings.AddIgnoreKey(ignoreThisVersionKey);
            }

            if (windowInstance == this)
            {
                windowInstance = null;
            }
        }
Beispiel #4
0
        // check vive input utility version on github
        private static void CheckVersionAndSettings()
        {
            if (string.IsNullOrEmpty(editorPrefsPrefix))
            {
                editorPrefsPrefix       = "ViveInputUtility." + PlayerSettings.productGUID + ".";
                nextVersionCheckTimeKey = editorPrefsPrefix + "LastVersionCheckTime";
                fmtIgnoreUpdateKey      = editorPrefsPrefix + "DoNotShowUpdate.v{0}";

                // Force refresh preference window so it won't stuck in "re-compinling" state
                if (GUIUtility.hotControl == 0)
                {
                    var prefWindow = GetWindow <EditorWindow>("Unity Preferences", false);
                    if (prefWindow != null && prefWindow.titleContent.text == "Unity Preferences")
                    {
                        prefWindow.Repaint();
                    }
                }
            }

            // fetch new version info from github release site
            if (!completeCheckVersionFlow)
            {
                if (www == null) // web request not running
                {
                    if (EditorPrefs.HasKey(nextVersionCheckTimeKey) && DateTime.UtcNow < UtcDateTimeFromStr(EditorPrefs.GetString(nextVersionCheckTimeKey)))
                    {
                        completeCheckVersionFlow = true;
                        return;
                    }

                    www = new WWW(lastestVersionUrl);
                }

                if (!www.isDone)
                {
                    return;
                }

                if (UrlSuccess(www))
                {
                    EditorPrefs.SetString(nextVersionCheckTimeKey, UtcDateTimeToStr(DateTime.UtcNow.AddMinutes(versionCheckIntervalMinutes)));

                    latestRepoInfo = JsonUtility.FromJson <RepoInfo>(www.text);
                }

                // parse latestVersion and ignoreThisVersionKey
                if (!string.IsNullOrEmpty(latestRepoInfo.tag_name))
                {
                    try
                    {
                        latestVersion        = new Version(Regex.Replace(latestRepoInfo.tag_name, "[^0-9\\.]", string.Empty));
                        ignoreThisVersionKey = string.Format(fmtIgnoreUpdateKey, latestVersion.ToString());
                    }
                    catch
                    {
                        latestVersion        = default(Version);
                        ignoreThisVersionKey = string.Empty;
                    }
                }

                www.Dispose();
                www = null;

                completeCheckVersionFlow = true;
            }

            showNewVersion = !string.IsNullOrEmpty(ignoreThisVersionKey) && !EditorPrefs.HasKey(ignoreThisVersionKey) && latestVersion > VIUVersion.current;

            // check if their is setting that not using recommended value and not ignored
            var recommendCount = 0; // not ignored and not using recommended value

            foreach (var setting in s_settings)
            {
                if (!setting.IsIgnored() && !setting.IsUsingRecommendedValue())
                {
                    ++recommendCount;
                }
            }

            if (showNewVersion || recommendCount > 0)
            {
                window         = GetWindow <VIUVersionCheck>(true, "Vive Input Utility");
                window.minSize = new Vector2(240f, 550f);

                var rect = window.position;
                window.position = new Rect(Mathf.Max(rect.x, 50f), Mathf.Max(rect.y, 50f), rect.width, 200f + (showNewVersion ? 700f : 400f));
            }

            EditorApplication.update -= CheckVersionAndSettings;
        }