Files
CreatGame/UnityGame/Assets/Scripts/GameLogic/UI/UIViewBase.cs

62 lines
1.6 KiB
C#
Raw Normal View History

2025-07-16 18:10:09 +08:00
using UnityEngine;
namespace CreatGame.UI
2025-07-15 15:33:35 +08:00
{
2025-07-24 12:50:20 +08:00
public class UIViewBase : UILoader
2025-07-15 15:33:35 +08:00
{
2025-07-16 13:36:21 +08:00
/// <summary>
2025-07-16 19:16:46 +08:00
/// 预制件的Addressables地址
/// 由导出代码自己添加
2025-07-16 13:36:21 +08:00
/// </summary>
public virtual string PrefabPath { get; set; }
/// <summary>
2025-07-16 18:10:09 +08:00
/// 窗口预制件
/// </summary>
protected GameObject m_ViewObject;
/// <summary>
/// 导出脚本
/// </summary>
2025-07-24 12:50:20 +08:00
protected UIViewExport m_ViewExport;
2025-07-16 18:10:09 +08:00
/// <summary>
2025-07-16 19:16:46 +08:00
/// 是否加载完成
/// </summary>
public bool IsPreLoad = false;
/// <summary>
2025-07-16 13:36:21 +08:00
/// 加载窗口的时候需要预先加载的东西
/// </summary>
2025-07-16 18:10:09 +08:00
public virtual void PreLoad(GameObject viewObject)
2025-07-16 13:36:21 +08:00
{
2025-07-16 18:10:09 +08:00
m_ViewObject = viewObject;
2025-07-24 12:50:20 +08:00
m_ViewExport = viewObject.GetComponent<UIViewExport>();
2025-07-16 19:16:46 +08:00
IsPreLoad = true;
2025-07-16 13:36:21 +08:00
}
/// <summary>
/// 初始化界面
/// </summary>
public virtual void InitView()
{
}
/// <summary>
/// 关闭窗口的时候的调用
/// </summary>
public virtual void CloseView()
{
2025-07-24 12:50:20 +08:00
DisposeGameObjectCache();
2025-07-17 09:52:33 +08:00
GameObject.Destroy(m_ViewObject);
2025-07-16 13:36:21 +08:00
}
2025-07-16 18:10:09 +08:00
protected GameObject GetGameObject(string name)
{
2025-07-24 12:50:20 +08:00
for (int i = 0; i < m_ViewExport.entries.Count; i++)
2025-07-16 18:10:09 +08:00
{
2025-07-24 12:50:20 +08:00
if (m_ViewExport.entries[i].key == name)
2025-07-16 18:10:09 +08:00
{
2025-07-24 12:50:20 +08:00
return m_ViewExport.entries[i].prefab;
2025-07-16 18:10:09 +08:00
}
}
return null;
}
2025-07-15 15:33:35 +08:00
}
}