static void Update() { EditorApplication.update -= Update; if (!EditorApplication.isPlayingOrWillChangePlaymode) { bool show = false; if (!EditorPrefs.HasKey(Preferences.PrefStartUp)) { show = true; EditorPrefs.SetBool(Preferences.PrefStartUp, true); } else { if (Time.realtimeSinceStartup < 10) { show = EditorPrefs.GetBool(Preferences.PrefStartUp, true); if (!show) { StartScreen.StartBackgroundTask(StartScreen.StartRequest(StartScreen.BannerInfoURL, (www) => { Info info = Info.CreateFromJSON(www.downloadHandler.text); if (info != null) { if (DateTime.Now < DateTime.Parse(info.ShowBefore) && !EditorPrefs.GetBool(Preferences.PrefForceUpdate, false)) { EditorPrefs.SetBool(Preferences.PrefForceUpdate, true); EditorPrefs.SetBool(Preferences.PrefStartUp, true); StartScreen.Init(); } else if (DateTime.Now > DateTime.Parse(info.ShowBefore)) { EditorPrefs.SetBool(Preferences.PrefForceUpdate, false); } } })); } } } if (show) { StartScreen.Init(); } } }
public void OnGUI() { if (!m_infoDownloaded) { m_infoDownloaded = true; // get affiliate links StartBackgroundTask(StartRequest(PackageRefURL, (www) => { var pack = PackageRef.CreateFromJSON(www.downloadHandler.text); if (pack != null) { m_packageRef = pack; Repaint(); } })); // get banner information and texture StartBackgroundTask(StartRequest(BannerInfoURL, (www) => { Info info = Info.CreateFromJSON(www.downloadHandler.text); if (info != null && !string.IsNullOrEmpty(info.ImageUrl)) { StartBackgroundTask(StartTextureRequest(info.ImageUrl, (www2) => { Texture2D texture = DownloadHandlerTexture.GetContent(www2); if (texture != null) { m_newsImage = texture; } })); } if (info != null && info.Version >= m_bannerInfo.Version) { m_bannerInfo = info; } // improve this later int major = m_bannerInfo.Version / 100; int minor = (m_bannerInfo.Version / 10) - major * 10; int release = m_bannerInfo.Version - major * 100 - minor * 10; m_newVersion = major + "." + minor + "." + release; Repaint(); })); } if (m_buttonStyle == null) { m_buttonStyle = new GUIStyle(GUI.skin.button); m_buttonStyle.alignment = TextAnchor.MiddleLeft; } if (m_labelStyle == null) { m_labelStyle = new GUIStyle("BoldLabel"); m_labelStyle.margin = new RectOffset(4, 4, 4, 4); m_labelStyle.padding = new RectOffset(2, 2, 2, 2); m_labelStyle.fontSize = 13; } if (m_linkStyle == null) { var inv = AssetDatabase.LoadAssetAtPath <Texture2D>(AssetDatabase.GUIDToAssetPath("1004d06b4b28f5943abdf2313a22790a")); // find a better solution for transparent buttons m_linkStyle = new GUIStyle(); m_linkStyle.normal.textColor = new Color(0.2980392f, 0.4901961f, 1f); m_linkStyle.hover.textColor = Color.white; m_linkStyle.active.textColor = Color.grey; m_linkStyle.margin.top = 3; m_linkStyle.margin.bottom = 2; m_linkStyle.hover.background = inv; m_linkStyle.active.background = inv; } EditorGUILayout.BeginHorizontal(GUIStyle.none, GUILayout.ExpandWidth(true)); { // left column EditorGUILayout.BeginVertical(GUILayout.Width(175)); { GUILayout.Label(ResourcesTitle, m_labelStyle); if (GUILayout.Button(WikiButton, m_buttonStyle)) { Application.OpenURL(WikiURL); } GUILayout.Space(10); GUILayout.Label("Amplify Products", m_labelStyle); if (m_packageRef.Links != null) { var webIcon = EditorGUIUtility.IconContent("BuildSettings.Web.Small").image; for (int i = 0; i < m_packageRef.Links.Length; i++) { var gc = new GUIContent(" " + m_packageRef.Links[i].Title, webIcon); if (GUILayout.Button(gc, m_buttonStyle)) { Application.OpenURL(m_packageRef.Links[i].Url + RefID); } } } GUILayout.Label("* Affiliate Links", "minilabel"); } EditorGUILayout.EndVertical(); // right column EditorGUILayout.BeginVertical(GUILayout.Width(650 - 175 - 9), GUILayout.ExpandHeight(true)); { GUILayout.Label(CommunityTitle, m_labelStyle); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); { if (GUILayout.Button(DiscordButton, GUILayout.ExpandWidth(true))) { Application.OpenURL(DiscordURL); } if (GUILayout.Button(ForumButton, GUILayout.ExpandWidth(true))) { Application.OpenURL(ForumURL); } } EditorGUILayout.EndHorizontal(); GUILayout.Label(UpdateTitle, m_labelStyle); if (m_newsImage != null) { var gc = new GUIContent(m_newsImage); int width = 650 - 175 - 9 - 8; width = Mathf.Min(m_newsImage.width, width); int height = m_newsImage.height; height = (int)((width + 8) * ((float)m_newsImage.height / (float)m_newsImage.width)); Rect buttonRect = EditorGUILayout.GetControlRect(false, height); EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Link); if (GUI.Button(buttonRect, gc, m_linkStyle)) { Application.OpenURL(m_bannerInfo.LinkUrl); } } m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true)); GUILayout.Label(m_bannerInfo.NewsText, "WordWrappedMiniLabel", GUILayout.ExpandHeight(true)); GUILayout.EndScrollView(); EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); { EditorGUILayout.BeginVertical(); GUILayout.Label(TitleSTR, m_labelStyle); GUILayout.Label("Installed Version: " + Major + "." + Minor + "." + Release); if (m_bannerInfo.Version > FullNumber) { var cache = GUI.color; GUI.color = Color.red; GUILayout.Label("New version available: " + m_newVersion, "BoldLabel"); GUI.color = cache; } else { var cache = GUI.color; GUI.color = Color.green; GUILayout.Label("You are using the latest version", "BoldLabel"); GUI.color = cache; } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Download links:"); if (GUILayout.Button("Amplify", m_linkStyle)) { Application.OpenURL(SiteURL); } GUILayout.Label("-"); if (GUILayout.Button("Asset Store", m_linkStyle)) { Application.OpenURL(StoreURL); } EditorGUILayout.EndHorizontal(); GUILayout.Space(7); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.BeginVertical(); GUILayout.Space(7); GUILayout.Label(Icon); EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal("ProjectBrowserBottomBarBg", GUILayout.ExpandWidth(true), GUILayout.Height(22)); { GUILayout.FlexibleSpace(); EditorGUI.BeginChangeCheck(); var cache = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; m_startup = EditorGUILayout.ToggleLeft("Show At Startup", m_startup, GUILayout.Width(120)); EditorGUIUtility.labelWidth = cache; if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetBool(Preferences.PrefStartUp, m_startup); } } EditorGUILayout.EndHorizontal(); // Find a better way to update link buttons without repainting the window Repaint(); }