SHA256
Improve CommonWarningDialogUI Compatibility with Unity UI Toolkit
This commit is contained in:
1 file changed
+33
-2
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.UIElements;
|
||||
using Button = UnityEngine.UI.Button;
|
||||
using Image = UnityEngine.UI.Image;
|
||||
|
||||
namespace ADOFAIRenderer.UI
|
||||
{
|
||||
@@ -22,6 +26,7 @@ namespace ADOFAIRenderer.UI
|
||||
public class CommonWarningDialogUI : MonoBehaviour
|
||||
{
|
||||
public static CommonWarningDialogUI? Instance { get; private set; }
|
||||
private readonly List<VisualElement> _disabledElements = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -30,6 +35,15 @@ namespace ADOFAIRenderer.UI
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var elem in _disabledElements)
|
||||
{
|
||||
if (elem != null)
|
||||
{
|
||||
elem.SetEnabled(true);
|
||||
}
|
||||
}
|
||||
_disabledElements.Clear();
|
||||
|
||||
if (Instance == this)
|
||||
{
|
||||
Instance = null;
|
||||
@@ -88,6 +102,23 @@ namespace ADOFAIRenderer.UI
|
||||
|
||||
private void Initialize(string title, string description, DialogButton[] buttons)
|
||||
{
|
||||
if (!UnityEngine.EventSystems.EventSystem.current)
|
||||
{
|
||||
var eventSystemObj = new GameObject("EventSystem");
|
||||
eventSystemObj.transform.SetParent(transform);
|
||||
eventSystemObj.AddComponent<UnityEngine.EventSystems.EventSystem>();
|
||||
eventSystemObj.AddComponent<UnityEngine.EventSystems.StandaloneInputModule>();
|
||||
}
|
||||
|
||||
foreach (var doc in FindObjectsByType<UIDocument>(FindObjectsSortMode.None))
|
||||
{
|
||||
if (doc && doc.rootVisualElement != null && doc.rootVisualElement.enabledSelf)
|
||||
{
|
||||
doc.rootVisualElement.SetEnabled(false);
|
||||
_disabledElements.Add(doc.rootVisualElement);
|
||||
}
|
||||
}
|
||||
|
||||
// UI 레이어(5) 설정
|
||||
gameObject.layer = 5;
|
||||
|
||||
@@ -229,7 +260,7 @@ namespace ADOFAIRenderer.UI
|
||||
{
|
||||
try
|
||||
{
|
||||
btnData.OnClick?.Invoke();
|
||||
btnData.OnClick();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -237,7 +268,7 @@ namespace ADOFAIRenderer.UI
|
||||
}
|
||||
Destroy(gameObject);
|
||||
});
|
||||
|
||||
|
||||
var btnRect = btnObj.GetComponent<RectTransform>();
|
||||
btnRect.anchorMin = new Vector2(0.5f, 0.5f);
|
||||
btnRect.anchorMax = new Vector2(0.5f, 0.5f);
|
||||
|
||||
Reference in new issue
Block a user