using UnityEngine; using UnityEditor; using UnityEngine.Networking; using UnityEngine.UIElements; using System; namespace com.zibra.common.Editor { internal class ZibraEffectsUpdateChecker : EditorWindow { public static GUIContent WindowTitle => new GUIContent("Zibra Effects Update Checker"); #if !ZIBRA_EFFECTS_OTP_VERSION const string URL = "https://generation.zibra.ai/api/pluginVersion?effect=effects&engine=unity&sku=pro"; #else const string URL = "https://generation.zibra.ai/api/pluginVersion?effect=effects&engine=unity&sku=otp"; #endif private const string UPDATE_CHECK_PREFS_KEY = "ZibraEffectsAutomaticallyCheckForUpdates"; private const string UPDATE_CHECKED_SESSION_STATE_KEY = "ZibraEffectsUpdateChecked"; private static ZibraEffectsUpdateChecker InstanceInternal; private static ZibraEffectsUpdateChecker Instance { get { if (InstanceInternal == null) { InstanceInternal = CreateInstance(); } return InstanceInternal; } } private static UnityWebRequestAsyncOperation Request; private static Label LabelMessage; private static Label LabelPluginSKU; private static Button UpdateButton; private static Toggle Checkbox; private bool OnlyShowOutdated = false; private bool IsLatestVersion = false; [InitializeOnLoadMethod] internal static void InitializeOnLoad() { // Don't automatically open any windows in batch mode if (Application.isBatchMode) { return; } // Check whether user disabled auto update checking if (!EditorPrefs.GetBool(UPDATE_CHECK_PREFS_KEY, true)) { return; } // Check whether auto update checking ran this editor session if (!SessionState.GetBool(UPDATE_CHECKED_SESSION_STATE_KEY, false)) { SessionState.SetBool(UPDATE_CHECKED_SESSION_STATE_KEY, true); EditorApplication.update += ShowWindowDelayed; } } internal static void ShowWindowDelayed() { ShowWindow(true); EditorApplication.update -= ShowWindowDelayed; } [MenuItem(Effects.BaseMenuBarPath + "Check for Update", false, 9000)] public static void ShowWindowMenu() { ShowWindow(false); } public static void ShowWindow(bool onlyShowOutdated) { Instance.OnlyShowOutdated = onlyShowOutdated; if (!onlyShowOutdated) { Instance.Show(); } } private void OnEnable() { titleContent = WindowTitle; var root = rootVisualElement; int width = 400; int height = 240; minSize = maxSize = new Vector2(width, height); var uxmlAssetPath = AssetDatabase.GUIDToAssetPath("f1c391edc80cd254a81b3eea9e36b979"); var visualTree = AssetDatabase.LoadAssetAtPath(uxmlAssetPath); visualTree.CloneTree(root); var commonUSSAssetPath = AssetDatabase.GUIDToAssetPath("20c4b12a1544dac44b6c04777afe69db"); var commonStyleSheet = AssetDatabase.LoadAssetAtPath(commonUSSAssetPath); root.styleSheets.Add(commonStyleSheet); UpdateButton = root.Q