-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUIExtensions.cs
48 lines (45 loc) · 1.74 KB
/
UIExtensions.cs
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using SFS.UI;
using SFS.UI.ModGUI;
using Button = SFS.UI.ModGUI.Button;
namespace UITools
{
/// <summary>
/// Class that provides some extra functionality for default
/// </summary>
public static class UIExtensions
{
/// <summary>
/// Allow you to register some actions on window drop after dragging.
/// </summary>
/// <param name="window">The window for which the action will be subscribed</param>
/// <param name="onDrop">Action that will be called every time the window is dropped</param>
/// <example>
/// The following code register writing message in the console every time window dropped
/// <code>
/// Window window = Builder.CreateWindow(...);
/// window.RegisterOnDropListener(() => Debug.Log("Window is dropped!"));
/// </code>
/// </example>
public static void RegisterOnDropListener(this Window window, Action onDrop)
{
window.gameObject.GetComponent<DraggableWindowModule>().OnDropAction += onDrop;
}
/// <summary>
/// Set if button is interactable
/// </summary>
public static void SetEnabled(this Button button, bool enabled)
{
ButtonPC buttonComponent = button.gameObject.GetComponent<ButtonPC>();
buttonComponent.SetEnabled(enabled);
}
/// <summary>
/// Set if button is selected
/// </summary>
public static void SetSelected(this Button button, bool selected)
{
ButtonPC buttonComponent = button.gameObject.GetComponent<ButtonPC>();
buttonComponent.SetSelected(selected);
}
}
}