static bool DrawCountdown(string text, float remainingTime, float totalTime, GUIStyle labelStyle) { GUILayout.Label(string.Format("{0} in {1}...", text, EditorUtils.DurationString(remainingTime)), labelStyle); const float boxHeight = 2; Rect controlRect = EditorGUILayout.GetControlRect(false, boxHeight * 2); Rect boxRect = controlRect; boxRect.width *= remainingTime / totalTime; boxRect.x += (controlRect.width - boxRect.width) / 2; boxRect.height = 2; GUI.DrawTexture(boxRect, EditorGUIUtility.whiteTexture); GUIContent cancelContent = new GUIContent("Cancel"); controlRect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight * 2); Rect buttonRect = controlRect; buttonRect.width = 100; buttonRect.x += (controlRect.width - buttonRect.width) / 2; return(GUI.Button(buttonRect, cancelContent)); }
void DrawStatus() { GUIStyle labelStyle = new GUIStyle(EditorStyles.whiteLargeLabel); labelStyle.alignment = TextAnchor.MiddleCenter; GUIStyle largeErrorStyle = new GUIStyle(labelStyle); largeErrorStyle.normal.textColor = Color.red; GUIStyle errorStyle = new GUIStyle(GUI.skin.box); errorStyle.alignment = TextAnchor.UpperLeft; errorStyle.wordWrap = true; errorStyle.normal.textColor = Color.red; float timeSinceFileChange = BankRefresher.TimeSinceSourceFileChange(); if (timeSinceFileChange != float.MaxValue) { GUILayout.Label(string.Format("The FMOD source banks changed {0} ago.", EditorUtils.DurationString(timeSinceFileChange)), labelStyle); float timeUntilBankRefresh = BankRefresher.TimeUntilBankRefresh(); if (timeUntilBankRefresh == 0) { GUILayout.Label("Refreshing banks now...", labelStyle); readyToRefreshBanks = true; } else if (timeUntilBankRefresh != float.MaxValue) { if (DrawCountdown("Refreshing banks", timeUntilBankRefresh, Settings.Instance.BankRefreshCooldown, labelStyle) || ConsumeEscapeKey()) { BankRefresher.DisableAutoRefresh(); } } else { GUILayout.Label("Would you like to refresh banks?", labelStyle); } } else { if (lastRefreshError == null) { GUILayout.Label("The FMOD banks are up to date.", labelStyle); } else { GUILayout.Label("Bank refresh failed:", largeErrorStyle); GUILayout.Box(lastRefreshError, errorStyle, GUILayout.ExpandWidth(true)); } } if (closeTime != float.MaxValue) { float timeUntilClose = Mathf.Max(0, closeTime - Time.realtimeSinceStartup); if (DrawCountdown("Closing", timeUntilClose, CloseDelay, labelStyle) || ConsumeEscapeKey()) { closeTime = float.MaxValue; } } }