StatusView.cs
2.09 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using UnityEditor;
using UnityEngine;
#if UNITY_2019_1_OR_NEWER
using UnityEngine.UIElements;
#else
using UnityEngine.Experimental.UIElements;
using UnityEngine.Experimental.UIElements.StyleEnums;
#endif
namespace UnityEditor.Collaboration
{
internal class StatusView : VisualElement
{
Image m_Image;
Label m_Message;
Button m_Button;
Action m_Callback;
public Texture icon
{
get { return m_Image.image; }
set
{
m_Image.image = value;
m_Image.visible = value != null;
// Until "display: hidden" is added, this is the only way to hide an element
m_Image.style.height = value != null ? 150 : 0;
}
}
public string message
{
get { return m_Message.text; }
set
{
m_Message.text = value;
m_Message.visible = value != null;
}
}
public string buttonText
{
get { return m_Button.text; }
set
{
m_Button.text = value;
UpdateButton();
}
}
public Action callback
{
get { return m_Callback; }
set
{
m_Callback = value;
UpdateButton();
}
}
public StatusView()
{
name = "StatusView";
this.StretchToParentSize();
m_Image = new Image() { name = "StatusIcon", visible = false, style = { height = 0f }};
m_Message = new Label() { name = "StatusMessage", visible = false};
m_Button = new Button(InternalCallaback) { name = "StatusButton", visible = false};
Add(m_Image);
Add(m_Message);
Add(m_Button);
}
private void UpdateButton()
{
m_Button.visible = m_Button.text != null && m_Callback != null;
}
private void InternalCallaback()
{
m_Callback();
}
}
}