110 lines
2.5 KiB
C#
110 lines
2.5 KiB
C#
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<WindowItem> windows = new List<WindowItem>();
|
|
|
|
[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<Animator>();
|
|
currentButtonAnimator.Play(buttonFadeIn);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
currentWindow = windows[currentWindowIndex].windowObject;
|
|
currentWindowAnimator = currentWindow.GetComponent<Animator>();
|
|
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<Animator>();
|
|
nextWindowAnimator = nextWindow.GetComponent<Animator>();
|
|
currentWindowAnimator.Play(windowFadeOut);
|
|
nextWindowAnimator.Play(windowFadeIn);
|
|
try
|
|
{
|
|
currentButtonIndex = newWindowIndex;
|
|
nextButton = windows[currentButtonIndex].buttonObject;
|
|
currentButtonAnimator = currentButton.GetComponent<Animator>();
|
|
nextButtonAnimator = nextButton.GetComponent<Animator>();
|
|
currentButtonAnimator.Play(buttonFadeOut);
|
|
nextButtonAnimator.Play(buttonFadeIn);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|