-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialogUIField.cs
More file actions
33 lines (29 loc) · 940 Bytes
/
Copy pathDialogUIField.cs
File metadata and controls
33 lines (29 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using Screenplay.Component;
using Object = UnityEngine.Object;
namespace Screenplay
{
[Serializable]
public class DialogUIField : ICustomField<UIBase>
{
[PrefabWithComponent]
public required UIBase DialogUIPrefab;
public void GetValue(ScreenplayGraph graph, out UIBase value, out Action<UIBase>? onCleanup)
{
value = Object.Instantiate(DialogUIPrefab);
onCleanup = o =>
{
if (o == null || o.gameObject == null)
return;
if (UnityEngine.Application.isPlaying)
Object.Destroy(o.gameObject);
else
Object.DestroyImmediate(o.gameObject);
};
}
}
public static class DialogUIFieldExtension
{
public static UIBase GetDialogUI(this IEventContext context) => context.Get<DialogUIField, UIBase>();
}
}