SHA256
forked from ADOFAIEditorForum/ADOFAIRenderer
Improve CommonWarningDialogUI Compatibility with Unity UI Toolkit
This commit is contained in:
1 file changed
+32
-1
@@ -1,7 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
using Button = UnityEngine.UI.Button;
|
||||||
|
using Image = UnityEngine.UI.Image;
|
||||||
|
|
||||||
namespace ADOFAIRenderer.UI
|
namespace ADOFAIRenderer.UI
|
||||||
{
|
{
|
||||||
@@ -22,6 +26,7 @@ namespace ADOFAIRenderer.UI
|
|||||||
public class CommonWarningDialogUI : MonoBehaviour
|
public class CommonWarningDialogUI : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static CommonWarningDialogUI? Instance { get; private set; }
|
public static CommonWarningDialogUI? Instance { get; private set; }
|
||||||
|
private readonly List<VisualElement> _disabledElements = new();
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -30,6 +35,15 @@ namespace ADOFAIRenderer.UI
|
|||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
|
foreach (var elem in _disabledElements)
|
||||||
|
{
|
||||||
|
if (elem != null)
|
||||||
|
{
|
||||||
|
elem.SetEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_disabledElements.Clear();
|
||||||
|
|
||||||
if (Instance == this)
|
if (Instance == this)
|
||||||
{
|
{
|
||||||
Instance = null;
|
Instance = null;
|
||||||
@@ -88,6 +102,23 @@ namespace ADOFAIRenderer.UI
|
|||||||
|
|
||||||
private void Initialize(string title, string description, DialogButton[] buttons)
|
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) 설정
|
// UI 레이어(5) 설정
|
||||||
gameObject.layer = 5;
|
gameObject.layer = 5;
|
||||||
|
|
||||||
@@ -229,7 +260,7 @@ namespace ADOFAIRenderer.UI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
btnData.OnClick?.Invoke();
|
btnData.OnClick();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user