forked from zxl/LaboratoryProtection
79 lines
1.9 KiB
C#
79 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace UnityTest.ZXL
|
|
{
|
|
public class UIManager : BaseAutoMono<UIManager>
|
|
{
|
|
[SerializeField] public List<UIObjectData> uiObjectData = new List<UIObjectData>();
|
|
|
|
public UI ShowUI(UIType uiType)
|
|
{
|
|
foreach (var objectData in uiObjectData)
|
|
{
|
|
if (objectData.uiType == uiType)
|
|
{
|
|
objectData.ui.gameObject.SetActive(true);
|
|
return objectData.ui;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public UI HideUI(UIType uiType)
|
|
{
|
|
foreach (var objectData in uiObjectData)
|
|
{
|
|
if (objectData.uiType == uiType)
|
|
{
|
|
objectData.ui.gameObject.SetActive(false);
|
|
return objectData.ui;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void HideAllUI()
|
|
{
|
|
foreach (var objectData in uiObjectData)
|
|
{
|
|
objectData.ui.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[Button]
|
|
void Add()
|
|
{
|
|
var uis = this.gameObject.GetComponentAllChild<UI>();
|
|
foreach (var ui in uis)
|
|
{
|
|
uiObjectData.Add(new UIObjectData() { uiType = ui.uiType, ui = ui });
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
public enum UIType
|
|
{
|
|
Chapter, //章节
|
|
BigStrongTips, //强提示
|
|
StrongTips, //强提示
|
|
WeakTips, //弱提示
|
|
Dialogue, //对话
|
|
GasDetector, //气体探测器
|
|
ChoiceQuestion, // 选择题
|
|
Summarize, // 总结面板
|
|
}
|
|
|
|
[System.Serializable]
|
|
public struct UIObjectData
|
|
{
|
|
public UIType uiType;
|
|
public UI ui;
|
|
}
|
|
} |