using System; using System.Collections.Generic; using UnityEngine; namespace Michsky.UI.MTP { public class DemoWindowManager : MonoBehaviour { [Serializable] public class WindowItem { public string windowName = "My Window"; public GameObject windowObject; public GameObject buttonObject; } [Header("List")] public List windows = new List(); [Header("Settings")] public int currentWindowIndex; private int currentButtonIndex; private int newWindowIndex; private string windowFadeIn = "Panel In"; private string windowFadeOut = "Panel Out"; private string buttonFadeIn = "Normal to Pressed"; private string buttonFadeOut = "Pressed to Normal"; private GameObject currentWindow; private GameObject nextWindow; private GameObject currentButton; private GameObject nextButton; private Animator currentWindowAnimator; private Animator nextWindowAnimator; private Animator currentButtonAnimator; private Animator nextButtonAnimator; private void Start() { try { currentButton = windows[currentWindowIndex].buttonObject; currentButtonAnimator = currentButton.GetComponent(); currentButtonAnimator.Play(buttonFadeIn); } catch { } currentWindow = windows[currentWindowIndex].windowObject; currentWindowAnimator = currentWindow.GetComponent(); currentWindowAnimator.Play(windowFadeIn); } public void OpenPanel(string newPanel) { for (int i = 0; i < windows.Count; i++) { if (windows[i].windowName == newPanel) { newWindowIndex = i; } } if (newWindowIndex != currentWindowIndex) { currentWindow = windows[currentWindowIndex].windowObject; try { currentButton = windows[currentWindowIndex].buttonObject; } catch { } currentWindowIndex = newWindowIndex; nextWindow = windows[currentWindowIndex].windowObject; currentWindowAnimator = currentWindow.GetComponent(); nextWindowAnimator = nextWindow.GetComponent(); currentWindowAnimator.Play(windowFadeOut); nextWindowAnimator.Play(windowFadeIn); try { currentButtonIndex = newWindowIndex; nextButton = windows[currentButtonIndex].buttonObject; currentButtonAnimator = currentButton.GetComponent(); nextButtonAnimator = nextButton.GetComponent(); currentButtonAnimator.Play(buttonFadeOut); nextButtonAnimator.Play(buttonFadeIn); } catch { } } } } }