forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualElementDataWatch.cs
More file actions
98 lines (83 loc) · 2.99 KB
/
Copy pathVisualElementDataWatch.cs
File metadata and controls
98 lines (83 loc) · 2.99 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
namespace UnityEngine.Experimental.UIElements
{
public interface IUIElementDataWatchRequest : IDisposable {}
public interface IUIElementDataWatch
{
IUIElementDataWatchRequest RegisterWatch(Object toWatch, Action<Object> watchNotification);
void UnregisterWatch(IUIElementDataWatchRequest requested);
}
public partial class VisualElement : IUIElementDataWatch
{
private class DataWatchRequest : IUIElementDataWatchRequest, IVisualElementPanelActivatable
{
public Action<Object> notification { get; set; }
public Object watchedObject { get; set; }
public IDataWatchHandle requestedHandle { get; set; }
private VisualElementPanelActivator m_Activator;
public VisualElement element { get; set; }
public DataWatchRequest(VisualElement handler)
{
element = handler;
m_Activator = new VisualElementPanelActivator(this);
}
public void Start()
{
m_Activator.SetActive(true);
}
public void Stop()
{
m_Activator.SetActive(false);
}
public bool CanBeActivated()
{
return element != null && element.elementPanel != null && element.elementPanel.dataWatch != null;
}
public void OnPanelActivate()
{
if (requestedHandle == null)
{
requestedHandle = element.elementPanel.dataWatch.AddWatch(watchedObject, notification);
}
}
public void OnPanelDeactivate()
{
if (requestedHandle != null)
{
element.elementPanel.dataWatch.RemoveWatch(requestedHandle);
requestedHandle = null;
}
}
public void Dispose()
{
Stop();
}
}
// this allows us to not expose all datawatch accessors directly on VisualElement class
public IUIElementDataWatch dataWatch
{
get { return this; }
}
IUIElementDataWatchRequest IUIElementDataWatch.RegisterWatch(Object toWatch, Action<Object> watchNotification)
{
var datawatchRequest = new DataWatchRequest(this)
{
notification = watchNotification,
watchedObject = toWatch
};
datawatchRequest.Start();
return datawatchRequest;
}
void IUIElementDataWatch.UnregisterWatch(IUIElementDataWatchRequest requested)
{
DataWatchRequest r = requested as DataWatchRequest;
if (r != null)
{
r.Stop();
}
}
}
}