Files
peng-zhihui 06ec2e469e Released.
2022-03-13 06:31:07 +08:00

58 lines
1.3 KiB
C#

namespace UIWidgets.Examples
{
using System;
using UIWidgets;
using UnityEngine;
/// <summary>
/// Test dialog with custom content.
/// </summary>
public class TestDialogWithCustomContent : MonoBehaviour
{
/// <summary>
/// Dialog template.
/// </summary>
[SerializeField]
public Dialog DialogTemplate;
/// <summary>
/// Custom content.
/// </summary>
[SerializeField]
public RectTransform CustomContent;
[NonSerialized]
Transform ContentParent;
/// <summary>
/// Show dialog.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
public void ShowDialog()
{
ContentParent = CustomContent.parent;
CustomContent.gameObject.SetActive(true);
var actions = new DialogButton[]
{
new DialogButton("Close", DialogBase.DefaultClose),
};
var dialog = DialogTemplate.Clone();
dialog.Show(
title: "Dialog With Custom Content",
buttons: actions,
focusButton: "Close",
modal: true,
modalColor: new Color(0, 0, 0, 0.8f),
content: CustomContent,
onClose: RestoreContentParent);
}
void RestoreContentParent()
{
CustomContent.SetParent(ContentParent, false);
CustomContent.gameObject.SetActive(false);
}
}
}