1
0
Fork 0
LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/UIManager.cs

79 lines
1.9 KiB
C#
Raw Normal View History

2023-09-13 15:31:44 +08:00
using System;
using System.Collections.Generic;
2023-09-13 15:04:19 +08:00
using Sirenix.OdinInspector;
using UnityEngine;
namespace UnityTest.ZXL
{
2023-09-13 15:31:44 +08:00
public class UIManager : BaseAutoMono<UIManager>
2023-09-13 15:04:19 +08:00
{
[SerializeField] public List<UIObjectData> uiObjectData = new List<UIObjectData>();
2023-09-13 15:31:44 +08:00
2023-09-14 15:36:17 +08:00
public UI ShowUI(UIType uiType)
2023-09-13 15:31:44 +08:00
{
2023-09-13 20:15:22 +08:00
foreach (var objectData in uiObjectData)
{
if (objectData.uiType == uiType)
{
objectData.ui.gameObject.SetActive(true);
2023-09-14 15:36:17 +08:00
return objectData.ui;
2023-09-13 20:15:22 +08:00
}
}
2023-09-14 15:36:17 +08:00
return null;
2023-09-13 15:31:44 +08:00
}
2023-09-14 15:36:17 +08:00
public UI HideUI(UIType uiType)
2023-09-13 15:31:44 +08:00
{
2023-09-13 20:15:22 +08:00
foreach (var objectData in uiObjectData)
{
if (objectData.uiType == uiType)
{
objectData.ui.gameObject.SetActive(false);
2023-09-14 15:36:17 +08:00
return objectData.ui;
2023-09-13 20:15:22 +08:00
}
}
2023-09-14 15:36:17 +08:00
return null;
2023-09-13 20:15:22 +08:00
}
public void HideAllUI()
{
foreach (var objectData in uiObjectData)
{
objectData.ui.gameObject.SetActive(false);
}
2023-09-13 15:31:44 +08:00
}
#if UNITY_EDITOR
[Button]
void Add()
{
var uis = this.gameObject.GetComponentAllChild<UI>();
foreach (var ui in uis)
{
2023-09-14 15:36:17 +08:00
uiObjectData.Add(new UIObjectData() { uiType = ui.uiType, ui = ui });
2023-09-13 15:31:44 +08:00
}
}
#endif
2023-09-13 15:04:19 +08:00
}
public enum UIType
{
2023-09-13 15:31:44 +08:00
Chapter, //章节
2023-09-18 01:37:18 +08:00
BigStrongTips, //强提示
2023-09-13 15:31:44 +08:00
StrongTips, //强提示
WeakTips, //弱提示
Dialogue, //对话
2023-09-18 03:39:32 +08:00
GasDetector, //气体探测器
ChoiceQuestion, // 选择题
2023-09-24 11:28:47 +08:00
Summarize, // 总结面板
2023-09-13 15:04:19 +08:00
}
2023-09-13 15:31:44 +08:00
2023-09-13 15:04:19 +08:00
[System.Serializable]
public struct UIObjectData
{
2023-09-13 15:31:44 +08:00
public UIType uiType;
public UI ui;
2023-09-13 15:04:19 +08:00
}
}