-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathCreateFromTemplateDropDownButton.cs
More file actions
74 lines (62 loc) · 2.16 KB
/
Copy pathCreateFromTemplateDropDownButton.cs
File metadata and controls
74 lines (62 loc) · 2.16 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
using UnityEditor.Experimental;
using UnityEditor.VFX.UI;
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.VFX
{
class CreateFromTemplateDropDownButton : DropDownButtonBase
{
private const string mainButtonName = "create-button";
private Button m_InsertButton;
public CreateFromTemplateDropDownButton(VFXView vfxView)
: base(
nameof(CreateFromTemplateDropDownButton),
vfxView,
"VFXCreateFromTemplateDropDownPanel",
"Insert a template into current asset\nHold CTRL key and click to create a new VFX",
mainButtonName,
EditorResources.iconsPath + "CreateAddNew.png",
true,
false)
{
var createNew = m_PopupContent.Q<Button>("createNew");
createNew.clicked += OnCreateNew;
var mainButton = this.Q<Button>(mainButtonName);
mainButton.RegisterCallback<MouseUpEvent>(OnMainButtonMouseUp);
m_InsertButton = m_PopupContent.Q<Button>("insert");
m_InsertButton.clicked += OnInsert;
}
private void OnMainButtonMouseUp(MouseUpEvent evt)
{
if (evt.button != (int)MouseButton.LeftMouse || evt.clickCount > 1)
return;
// If the current asset is a subgraph do not call "OnInsert" callback and rather open the dropdown
if (m_VFXView.controller.model.isSubgraph)
{
OnTogglePopup();
}
else if (evt.modifiers.HasFlag(EventModifiers.Control))
{
OnCreateNew();
}
else
{
OnInsert();
}
}
protected override Vector2 GetPopupSize() => new(200, 54);
protected override void OnOpenPopup()
{
m_InsertButton.SetEnabled(!m_VFXView.controller.model.isSubgraph);
base.OnOpenPopup();
}
private void OnCreateNew()
{
VFXTemplateWindow.ShowCreateFromTemplate(null, null);
}
private void OnInsert()
{
VFXTemplateWindow.ShowInsertTemplate(m_VFXView);
}
}
}