-
Notifications
You must be signed in to change notification settings - Fork 877
Expand file tree
/
Copy pathVFXStickyNote.cs
More file actions
153 lines (139 loc) · 4.61 KB
/
Copy pathVFXStickyNote.cs
File metadata and controls
153 lines (139 loc) · 4.61 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements;
using System.Reflection;
using System.Linq;
namespace UnityEditor.VFX.UI
{
class VFXStickyNoteController : VFXUIController<VFXUI.StickyNoteInfo>
{
public VFXStickyNoteController(VFXViewController viewController, VFXUI ui, int index) : base(viewController, ui, index)
{
}
public string contents
{
get
{
if (m_Index < 0) return "";
return m_UI.stickyNoteInfos[m_Index].contents;
}
set
{
if (m_Index < 0) return;
m_UI.stickyNoteInfos[m_Index].contents = value;
Modified();
}
}
override protected VFXUI.StickyNoteInfo[] infos { get { return m_UI.stickyNoteInfos; } }
public string theme
{
get
{
return m_UI.stickyNoteInfos[m_Index].theme;
}
set
{
m_UI.stickyNoteInfos[m_Index].theme = value;
Modified();
}
}
public string fontSize
{
get
{
return m_UI.stickyNoteInfos[m_Index].textSize;
}
set
{
m_UI.stickyNoteInfos[m_Index].textSize = value;
Modified();
}
}
}
class VFXStickyNote : StickyNote, IControlledElement<VFXStickyNoteController>, IVFXMovable
{
public void OnMoved()
{
controller.position = new Rect(resolvedStyle.left, resolvedStyle.top, resolvedStyle.width, resolvedStyle.height);
}
Controller IControlledElement.controller
{
get { return m_Controller; }
}
public VFXStickyNoteController controller
{
get { return m_Controller; }
set
{
if (m_Controller != null)
{
m_Controller.UnregisterHandler(this);
}
m_Controller = value;
if (m_Controller != null)
{
m_Controller.RegisterHandler(this);
}
}
}
VFXStickyNoteController m_Controller;
public VFXStickyNote() : base(Vector2.zero)
{
styleSheets.Add(Resources.Load<StyleSheet>("StickyNote"));
this.RegisterCallback<StickyNoteChangeEvent>(OnUIChange);
}
void OnUIChange(StickyNoteChangeEvent e)
{
if (m_Controller == null) return;
switch (e.change)
{
case StickyNoteChange.Title:
controller.title = title;
break;
case StickyNoteChange.Contents:
controller.contents = contents;
break;
case StickyNoteChange.Theme:
controller.theme = theme.ToString();
break;
case StickyNoteChange.FontSize:
controller.fontSize = fontSize.ToString();
break;
case StickyNoteChange.Position:
controller.position = new Rect(resolvedStyle.left, resolvedStyle.top, style.width.value.value, style.height.value.value);
break;
}
}
void IControlledElement.OnControllerChanged(ref ControllerChangedEvent e)
{
title = controller.title;
contents = controller.contents;
if (!string.IsNullOrEmpty(controller.theme))
{
try
{
theme = (StickyNoteTheme)System.Enum.Parse(typeof(StickyNoteTheme), controller.theme, true);
}
catch (System.ArgumentException)
{
controller.theme = StickyNoteTheme.Classic.ToString();
Debug.LogError("Unknown theme name");
}
}
if (!string.IsNullOrEmpty(controller.fontSize))
{
try
{
fontSize = (StickyNoteFontSize)System.Enum.Parse(typeof(StickyNoteFontSize), controller.fontSize, true);
}
catch (System.ArgumentException)
{
controller.theme = StickyNoteFontSize.Medium.ToString();
Debug.LogError("Unknown text size name");
}
}
SetPosition(controller.position);
}
}
}