private void Update() { if (progressContainer != null) { // Show/hide progress modal float prev = progressContainer.AnimationProgress; UIAnimator.Animate(progressContainer, Time.unscaledDeltaTime * (progressModalVisible ? 1 : -1)); // If just closed, call ModalClosed if ((prev > 0) && (progressContainer.AnimationProgress <= 0)) { progressContainer.gameObject.SetActive(false); ModalClosed(); } } if (progressInfiniteContainer != null) { // Show/hide infinite progress float prev = progressInfiniteContainer.AnimationProgress; UIAnimator.Animate(progressInfiniteContainer, Time.unscaledDeltaTime * (progressInfiniteVisible ? 1 : -1)); // If just closed, call ModalClosed if ((prev > 0) && (progressInfiniteContainer.AnimationProgress <= 0)) { progressInfiniteContainer.gameObject.SetActive(false); ModalClosed(); } } }
public void PromptText(string title, string message, string acceptButtonText, string cancelButtonText, Action <string> onEntered, Action onCancelled) { ClearAll(); if (textPromptTitle != null) { textPromptTitle.text = title; } textPromptText.text = message; textPromptInput.text = ""; textPromptButtonAccept.gameObject.SetActive(true); textPromptButtonCancel.gameObject.SetActive(true); var btnText = textPromptButtonAccept.GetComponentInChildren <Text>(); if (btnText != null) { btnText.text = acceptButtonText; } btnText = textPromptButtonCancel.GetComponentInChildren <Text>(); if (btnText != null) { btnText.text = cancelButtonText; } textPromptButtonAccept.onClick.RemoveAllListeners(); textPromptButtonAccept.onClick.AddListener(() => { background.SetActive(false); StartCoroutine(UIAnimator.AnimationRoutine(textPromptContainer, -1, () => { textPromptContainer.gameObject.SetActive(false); ModalClosed(); if (onEntered != null) { onEntered(textPromptInput.text); } })); }); textPromptButtonCancel.onClick.RemoveAllListeners(); textPromptButtonCancel.onClick.AddListener(() => { background.SetActive(false); StartCoroutine(UIAnimator.AnimationRoutine(textPromptContainer, -1, () => { textPromptContainer.gameObject.SetActive(false); ModalClosed(); if (onCancelled != null) { onCancelled(); } })); }); background.SetActive(true); textPromptContainer.gameObject.SetActive(true); StartCoroutine(UIAnimator.AnimationRoutine(textPromptContainer, 1)); }
// Yes/no promt public void PromptYesNo(string title, string message, string yesButtonText, string noButtonText, Action onYes, Action onNo) { ClearAll(); if (promptTitle != null) { promptTitle.text = title; } promptText.text = message; var btnText = promptButtonYes.GetComponentInChildren <Text>(); if (btnText != null) { btnText.text = yesButtonText; } btnText = promptButtonNo.GetComponentInChildren <Text>(); if (btnText != null) { btnText.text = noButtonText; } promptButtonYes.onClick.RemoveAllListeners(); promptButtonYes.onClick.AddListener(() => { background.SetActive(false); StartCoroutine(UIAnimator.AnimationRoutine(promptContainer, -1, () => { promptContainer.gameObject.SetActive(false); ModalClosed(); if (onYes != null) { onYes(); } })); }); promptButtonNo.onClick.RemoveAllListeners(); promptButtonNo.onClick.AddListener(() => { background.SetActive(false); StartCoroutine(UIAnimator.AnimationRoutine(promptContainer, -1, () => { promptContainer.gameObject.SetActive(false); ModalClosed(); if (onNo != null) { onNo(); } })); }); background.SetActive(true); promptContainer.gameObject.SetActive(true); StartCoroutine(UIAnimator.AnimationRoutine(promptContainer, 1)); }
private void Update() { // Update tabs lock (idxLock) { for (int i = 0; i < tabPages.Length; i++) { if (i == currentIdx) { tabPages[i].gameObject.SetActive(true); UIAnimator.Animate(tabPages[i], Time.unscaledDeltaTime); } else { if (tabPages[i].AnimationProgress <= 0) { tabPages[i].gameObject.SetActive(false); } else { UIAnimator.Animate(tabPages[i], -Time.unscaledDeltaTime); } } } } // Prev/next if (WindowManager.Instance.HasPrevNextButtons()) { if (Input.GetButtonDown(WindowManager.Instance.PreviousUIButton)) { ShowPrevious(); } if (Input.GetButtonDown(WindowManager.Instance.NextUIButton)) { ShowNext(); } } }
// Generic error public void ShowError(string title, string message, string buttonText, Action onDismissed) { ClearAll(); if (errorBoxTitle != null) { errorBoxTitle.text = title; } errorBoxText.text = message; var btnText = errorBoxButton.GetComponentInChildren <Text>(); if (btnText != null) { btnText.text = buttonText; } errorBoxButton.onClick.RemoveAllListeners(); errorBoxButton.onClick.AddListener(() => { background.SetActive(false); StartCoroutine(UIAnimator.AnimationRoutine(errorBoxContainer, -1, () => { errorBoxContainer.gameObject.SetActive(false); ModalClosed(); if (onDismissed != null) { onDismissed(); } })); }); background.SetActive(true); errorBoxContainer.gameObject.SetActive(true); StartCoroutine(UIAnimator.AnimationRoutine(errorBoxContainer, 1)); }
private void Awake() { // Check if toggles have a group ValidateToggleGroup(); // Show an error if pages & toggles are mismatched int count = Mathf.Min(toggles.Length, tabPages.Length); if ((toggles.Length > 0) && (toggles.Length != tabPages.Length)) { Debug.LogWarning("Warning: tab page count and toggle count mismatch"); } // Toggle events for (int i = 0; i < count; i++) { int closure = i; toggles[i].onValueChanged.AddListener((value) => { if (value) { ShowTab(closure); } }); } // Show the first tab, no anim for (int i = 1; i < tabPages.Length; i++) { UIAnimator.Animate(tabPages[i], -1); } UIAnimator.Animate(tabPages[0], 1); if (OnTabSelected != null) { OnTabSelected.Invoke(0); } }
public void Hide() { StartCoroutine(UIAnimator.AnimationRoutine(this, -1f, () => { gameObject.SetActive(false); })); }
public void Show() { gameObject.SetActive(true); StartCoroutine(UIAnimator.AnimationRoutine(this, 1f)); }
private void Update() { Window top = null; // Update window showing/hiding lock (windowStackLock) { // Always try to show the top window if (windowStack.Count > 0) { top = windowStack[windowStack.Count - 1]; top.gameObject.SetActive(true); UIAnimator.Animate(top, Time.unscaledDeltaTime); } // All other windows should be hidden foreach (var wnd in registeredWindows.Values) { if (wnd != top) { UIAnimator.Animate(wnd, -Time.unscaledDeltaTime); if (wnd.AnimationProgress == 0) { wnd.gameObject.SetActive(false); } } } } // Update background deniers if (top != currentTopWindow) { // Disable old denier if ((currentTopWindow != null) && (currentTopWindow.BackgroundDenier != null)) { currentTopWindow.BackgroundDenier.gameObject.SetActive(false); } // Enable background denier and move it in the hierarchy if ((top != null) && (top.BackgroundDenier != null)) { // Get sibling index -- make sure to count the denier itself if they have the same parent int siblingIndex = top.transform.GetSiblingIndex(); if (top.transform.parent == top.BackgroundDenier.parent) { int denierIdx = top.BackgroundDenier.GetSiblingIndex(); if (denierIdx < siblingIndex) { siblingIndex--; } } else { top.BackgroundDenier.SetParent(top.transform.parent); } top.BackgroundDenier.SetSiblingIndex(siblingIndex); top.BackgroundDenier.gameObject.SetActive(true); } currentTopWindow = top; if ((currentTopWindow != null) && (currentTopWindow.OnActivated != null)) { currentTopWindow.OnActivated.Invoke(); } } // Play changed sound when the current selection changed if ((audioSource != null) && (selectionChangedSound != null)) { var newSelected = EventSystem.current.currentSelectedGameObject; if (selectedUIObject != newSelected) { audioSource.PlayOneShot(selectionChangedSound); selectedUIObject = newSelected; } } // Prev/next buttons if ((CurrentWindow != null) && HasPrevNextButtons()) { if (Input.GetButtonDown(PreviousUIButton) && (CurrentWindow.OnPreviousWindow != null)) { CurrentWindow.OnPreviousWindow.Invoke(); } if (Input.GetButtonDown(NextUIButton) && (CurrentWindow.OnNextWindow != null)) { CurrentWindow.OnNextWindow.Invoke(); } } }