ProgressView.cs
2.13 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
using System;
using JetBrains.Annotations;
using Unity.Cloud.Collaborate.Assets;
using Unity.Cloud.Collaborate.UserInterface;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace Unity.Cloud.Collaborate.Components
{
[UsedImplicitly]
internal class ProgressView : VisualElement
{
public const string UssClassName = "progress-view";
public const string LabelUssClassName = UssClassName + "__label";
public const string ProgressBarUssClassName = UssClassName + "__progress-bar";
public const string ButtonUssClassName = UssClassName + "__button";
static readonly string k_LayoutPath = $"{CollaborateWindow.LayoutPath}/{nameof(ProgressView)}.uxml";
static readonly string k_StylePath = $"{CollaborateWindow.StylePath}/{nameof(ProgressView)}.uss";
readonly Label m_Label;
readonly ProgressBar m_ProgressBar;
readonly Button m_Button;
public ProgressView()
{
AddToClassList(UssClassName);
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(k_LayoutPath).CloneTree(this);
styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>(k_StylePath));
m_Label = this.Q<Label>(className: LabelUssClassName);
m_Label.text = string.Empty;
m_ProgressBar = this.Q<ProgressBar>(className: ProgressBarUssClassName);
m_Button = this.Q<Button>(className: ButtonUssClassName);
m_Button.text = StringAssets.cancel;
}
public void SetText(string text, string progressText)
{
m_Label.text = text;
m_ProgressBar.title = progressText;
}
public void SetPercentComplete(int percent)
{
m_ProgressBar.value = percent;
}
public void SetCancelCallback(Action callback)
{
m_Button.clickable.clicked += callback;
}
public void SetCancelButtonActive(bool active)
{
m_Button.SetEnabled(active);
}
[UsedImplicitly]
public new class UxmlFactory : UxmlFactory<ProgressView> { }
}
}