您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
36 行
1.3 KiB
36 行
1.3 KiB
using UnityEditor;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Unity.Services.Core.Editor
|
|
{
|
|
static class ExceptionHelper
|
|
{
|
|
const string k_UxmlPath = "Packages/com.unity.services.core/Editor/Core/UiHelpers/UXML/ExceptionVisual.uxml";
|
|
const string k_ExceptionContext = "exception-context";
|
|
const string k_ExceptionMessage = "exception-message";
|
|
|
|
public static void AddExceptionVisual(VisualElement exceptionContainer, string exceptionContext, string exceptionMessage)
|
|
{
|
|
if (exceptionContainer == null)
|
|
return;
|
|
|
|
var visualTreeAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(k_UxmlPath);
|
|
if (visualTreeAsset != null)
|
|
{
|
|
visualTreeAsset.CloneTree(exceptionContainer);
|
|
|
|
SetLabelText(exceptionContainer, k_ExceptionContext, exceptionContext);
|
|
SetLabelText(exceptionContainer, k_ExceptionMessage, exceptionMessage);
|
|
}
|
|
}
|
|
|
|
static void SetLabelText(VisualElement labelContainer, string className, string message)
|
|
{
|
|
var label = labelContainer.Q<Label>(className: className);
|
|
if (label != null)
|
|
{
|
|
label.text = L10n.Tr(message);
|
|
}
|
|
}
|
|
}
|
|
}
|