add dialogue type

This commit is contained in:
NguyenVanDat
2026-03-03 10:59:00 +07:00
parent 22b97e3321
commit beaa50b9d7
3 changed files with 100 additions and 99 deletions
@@ -30,7 +30,9 @@ namespace BrewMonster
[SerializeField] private Button okButton;
[SerializeField] private Button _noButton;
[SerializeField] private Button _closeButton;
public override DialogueType DialogueType => DialogueType.MessageBox;
private MessageBoxData _messageData;
public override void OnEnable()
@@ -6,6 +6,11 @@ using UnityEngine.UI;
namespace BrewMonster.UI
{
public enum DialogueType
{
Window,
MessageBox
}
public class AUIDialog : MonoBehaviour
{
protected Dictionary<int, string> m_StringTable = new Dictionary<int, string>();
@@ -20,6 +25,8 @@ namespace BrewMonster.UI
private bool m_bUpdateRenderTarget = false;
[SerializeField] TextMeshProUGUI skillNameText;
[SerializeField] Image imageProgress;
public virtual DialogueType DialogueType => DialogueType.Window;
public virtual void Show(bool value)
{
+90 -98
View File
@@ -12,6 +12,8 @@ using TMPro;
public class CECUIManager : MonoSingleton<CECUIManager>
{
[SerializeField] private GameObject _windowContainer;
[SerializeField] private GameObject _messageBoxContainer;
[SerializeField] private TMP_Text _fpsText;
[SerializeField] private List<GameObject> uiPrefabs; // drag các prefab UI vào đây
@@ -150,16 +152,6 @@ public class CECUIManager : MonoSingleton<CECUIManager>
}
GetInGameUIMan().GetDialog(componentName).Show(true);
return;
var type = FindTypeByName(componentName);
if (TryShowCachedUI(type)) return;
if (FindUIByName(componentName, type)) return;
if (FindUIByType(type)) return;
Debug.LogWarning($"Không tìm thấy UI {componentName} đã spawn trong canvasDlg. Type found: {(type != null ? type.FullName : "null")}");
}
public CDlgMessageBox ShowMessageBox(MessageBoxData messageBoxData)
{
@@ -330,86 +322,86 @@ public class CECUIManager : MonoSingleton<CECUIManager>
return true;
}
private System.Type FindTypeByName(string componentName)
{
string[] namespacePrefixes = {
"", // No namespace
"BrewMonster.Scripts.Task.UI.",
"BrewMonster.UI.",
"BrewMonster.Scripts.UI.",
"BrewMonster."
};
// Try with common namespace prefixes
foreach (var prefix in namespacePrefixes)
{
string fullTypeName = string.IsNullOrEmpty(prefix) ? componentName : prefix + componentName;
var type = System.Type.GetType(fullTypeName);
if (type != null) return type;
}
// Search in all assemblies
foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
{
var type = assembly.GetType(componentName);
if (type != null) return type;
foreach (var prefix in namespacePrefixes)
{
if (string.IsNullOrEmpty(prefix)) continue;
type = assembly.GetType(prefix + componentName);
if (type != null) return type;
}
}
return null;
}
private bool TryShowCachedUI(System.Type type)
{
if (type != null && _spawnedUIs.TryGetValue(type, out var uiGo))
{
uiGo.SetActive(true);
return true;
}
return false;
}
private bool FindUIByName(string componentName, System.Type type)
{
for (int i = 0; i < canvasDlg.transform.childCount; i++)
{
var child = canvasDlg.transform.GetChild(i);
if (!child.name.Contains(componentName) && child.name != componentName) continue;
if (type != null)
{
var foundComponent = child.GetComponentInChildren(type, true);
if (foundComponent != null)
{
ActivateAndCacheUI(foundComponent.gameObject, type);
return true;
}
}
ActivateAndCacheUI(child.gameObject, type);
return true;
}
return false;
}
private bool FindUIByType(System.Type type)
{
if (type == null) return false;
var foundComponent = canvasDlg.GetComponentInChildren(type, true);
if (foundComponent != null)
{
ActivateAndCacheUI(foundComponent.gameObject, type);
return true;
}
return false;
}
// private System.Type FindTypeByName(string componentName)
// {
// string[] namespacePrefixes = {
// "", // No namespace
// "BrewMonster.Scripts.Task.UI.",
// "BrewMonster.UI.",
// "BrewMonster.Scripts.UI.",
// "BrewMonster."
// };
//
// // Try with common namespace prefixes
// foreach (var prefix in namespacePrefixes)
// {
// string fullTypeName = string.IsNullOrEmpty(prefix) ? componentName : prefix + componentName;
// var type = System.Type.GetType(fullTypeName);
// if (type != null) return type;
// }
//
// // Search in all assemblies
// foreach (var assembly in System.AppDomain.CurrentDomain.GetAssemblies())
// {
// var type = assembly.GetType(componentName);
// if (type != null) return type;
//
// foreach (var prefix in namespacePrefixes)
// {
// if (string.IsNullOrEmpty(prefix)) continue;
// type = assembly.GetType(prefix + componentName);
// if (type != null) return type;
// }
// }
//
// return null;
// }
//
// private bool TryShowCachedUI(System.Type type)
// {
// if (type != null && _spawnedUIs.TryGetValue(type, out var uiGo))
// {
// uiGo.SetActive(true);
// return true;
// }
// return false;
// }
//
// private bool FindUIByName(string componentName, System.Type type)
// {
// for (int i = 0; i < canvasDlg.transform.childCount; i++)
// {
// var child = canvasDlg.transform.GetChild(i);
// if (!child.name.Contains(componentName) && child.name != componentName) continue;
//
// if (type != null)
// {
// var foundComponent = child.GetComponentInChildren(type, true);
// if (foundComponent != null)
// {
// ActivateAndCacheUI(foundComponent.gameObject, type);
// return true;
// }
// }
//
// ActivateAndCacheUI(child.gameObject, type);
// return true;
// }
// return false;
// }
//
// private bool FindUIByType(System.Type type)
// {
// if (type == null) return false;
//
// var foundComponent = canvasDlg.GetComponentInChildren(type, true);
// if (foundComponent != null)
// {
// ActivateAndCacheUI(foundComponent.gameObject, type);
// return true;
// }
// return false;
// }
private void ActivateAndCacheUI(GameObject uiGameObject, System.Type type)
{
@@ -421,14 +413,14 @@ public class CECUIManager : MonoSingleton<CECUIManager>
/// <summary>
/// Ẩn UI (disable thay vì destroy)
/// </summary>
public void HideUI<T>() where T : Component
{
var type = typeof(T);
if (_spawnedUIs.TryGetValue(type, out var uiGo))
{
uiGo.SetActive(false);
}
}
// public void HideUI<T>() where T : Component
// {
// var type = typeof(T);
// if (_spawnedUIs.TryGetValue(type, out var uiGo))
// {
// uiGo.SetActive(false);
// }
// }
/// <summary>
/// Kiểm tra UI có đang active không