Skip to content

Commit 8a91bd6

Browse files
author
Unity Technologies
committed
Unity 2017.1.0a4 C# reference source code
1 parent 2622109 commit 8a91bd6

File tree

153 files changed

+12762
-2375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+12762
-2375
lines changed

Editor/Mono/Animation/AnimationWindow/AddCurvesPopupHierarchy.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ internal class AddCurvesPopupHierarchy
1414
private TreeViewState m_TreeViewState;
1515
private AddCurvesPopupHierarchyDataSource m_TreeViewDataSource;
1616

17-
public AddCurvesPopupHierarchy()
18-
{
19-
}
20-
2117
public void OnGUI(Rect position, EditorWindow owner)
2218
{
2319
InitIfNeeded(owner, position);

Editor/Mono/Animation/AnimationWindow/AnimEditorOverlay.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ internal class AnimEditorOverlay
2525
public Rect rect { get { return m_Rect; } }
2626
public Rect contentRect { get { return m_ContentRect; } }
2727

28-
public AnimEditorOverlay()
29-
{
30-
}
31-
3228
public void Initialize()
3329
{
3430
if (m_PlayHeadCursor == null)

Editor/Mono/Animation/AnimationWindow/CurveEditorRectangleTool.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ private DragMode dragMode
147147
}
148148
}
149149

150-
public CurveEditorRectangleTool()
151-
{
152-
}
153-
154150
public override void Initialize(TimeArea timeArea)
155151
{
156152
base.Initialize(timeArea);

Editor/Mono/Animation/AnimationWindow/DopeSheetEditorRectangleTool.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ struct ToolLayout
8989

9090
private bool isDragging { get { return m_IsDragging || m_DopeSheetEditor.isDragging; } }
9191

92-
public DopeSheetEditorRectangleTool()
93-
{
94-
}
95-
9692
public override void Initialize(TimeArea timeArea)
9793
{
9894
base.Initialize(timeArea);

Editor/Mono/Animation/AnimationWindow/RectangleTool.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ public Rect contentRect
6666
}
6767
}
6868

69-
public RectangleTool()
70-
{
71-
}
72-
7369
public virtual void Initialize(TimeArea timeArea)
7470
{
7571
m_TimeArea = timeArea;

Editor/Mono/Audio/Mixer/GUI/AudioMixerWindow.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ void UpdateAfterAssetChange()
175175
AudioMixerUtility.RepaintAudioMixerAndInspectors();
176176
}
177177

178-
public AudioMixerWindow()
179-
{
180-
}
181-
182178
public static void Create()
183179
{
184180
var win = GetWindow<AudioMixerWindow>(typeof(ProjectBrowser)); // From usability tests we decided to auto dock together with project browser to prevent the mixer window keep going behind the main window on OSX

Editor/Mono/Collab/Collab.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ public static Collab instance
118118
}
119119
}
120120

121-
public Collab()
122-
{
123-
// Nothing to do
124-
}
125-
126121
static Collab()
127122
{
128123
s_Instance = new Collab();

Editor/Mono/Collab/CollabDialogs.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ public static CollabCannotPublishDialog ShowCollabWindow(string infoMessage)
112112
static GUIContent IssuesText = EditorGUIUtility.TextContent("Issues:");
113113
static GUIContent AcceptText = EditorGUIUtility.TextContent("Accept");
114114

115-
public CollabCannotPublishDialog()
116-
{
117-
}
118-
119115
public Vector2 scrollPosition;
120116
public string InfoMessage;
121117

Editor/Mono/DataWatchService.cs

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using UnityEngine;
8+
using UnityEngine.Experimental.RMGUI;
9+
using Object = UnityEngine.Object;
10+
11+
namespace UnityEditor
12+
{
13+
class DataWatchHandle : IDataWatchHandle
14+
{
15+
public readonly int id;
16+
public WeakReference service;
17+
18+
public Object watched { get; private set; }
19+
20+
public DataWatchHandle(int id, DataWatchService service, Object watched)
21+
{
22+
this.id = id;
23+
this.service = new WeakReference(service);
24+
this.watched = watched;
25+
}
26+
27+
public bool disposed
28+
{
29+
get
30+
{
31+
return ReferenceEquals(watched, null);
32+
}
33+
}
34+
35+
public void Dispose()
36+
{
37+
if (disposed)
38+
{
39+
throw new InvalidOperationException("DataWatchHandle was already disposed of");
40+
}
41+
if (service != null && service.IsAlive)
42+
{
43+
(service.Target as DataWatchService).RemoveWatch(this);
44+
}
45+
service = null;
46+
watched = null;
47+
}
48+
}
49+
50+
internal class DataWatchService : IDataWatchService
51+
{
52+
private HashSet<Object> m_DirtySet = new HashSet<Object>();
53+
54+
struct Spy
55+
{
56+
public readonly int handleID;
57+
public readonly VisualElement watcher;
58+
public readonly Action onDataChanged;
59+
60+
public Spy(int handleID, VisualElement watcher, Action onDataChanged)
61+
{
62+
this.handleID = handleID;
63+
this.watcher = watcher;
64+
this.onDataChanged = onDataChanged;
65+
}
66+
}
67+
68+
struct Watchers
69+
{
70+
public List<Spy> spyList;
71+
public ChangeTrackerHandle tracker;
72+
}
73+
74+
private Dictionary<int, DataWatchHandle> m_Handles = new Dictionary<int, DataWatchHandle>();
75+
private Dictionary<Object, Watchers> m_Watched = new Dictionary<Object, Watchers>();
76+
77+
public DataWatchService()
78+
{
79+
// TODO probably just do this when panel becomes active and stop when being inactive
80+
Undo.postprocessModifications += PostProcessUndo;
81+
}
82+
83+
~DataWatchService()
84+
{
85+
Undo.postprocessModifications -= PostProcessUndo;
86+
}
87+
88+
// callback to watch undo stack for changes
89+
// TODO: add the hook before animation strips some changes in record mode
90+
public UndoPropertyModification[] PostProcessUndo(UndoPropertyModification[] modifications)
91+
{
92+
foreach (var m in modifications)
93+
{
94+
var cv = m.currentValue;
95+
if (cv == null)
96+
continue;
97+
if (m_Watched.ContainsKey(cv.target))
98+
{
99+
m_DirtySet.Add(cv.target);
100+
}
101+
}
102+
return modifications;
103+
}
104+
105+
// go through all trackers and poll their native revisions
106+
public void PollNativeData()
107+
{
108+
foreach (var w in m_Watched)
109+
{
110+
// Unity Object can be destroyed without us knowing
111+
// They will compare to null but the C# object is still valid
112+
// Other wise we check the object for changes
113+
if (w.Key == null || w.Value.tracker.PollForChanges())
114+
{
115+
m_DirtySet.Add(w.Key);
116+
}
117+
}
118+
}
119+
120+
public void ProcessNotificationQueue()
121+
{
122+
PollNativeData();
123+
124+
// copy because dirty call could come in while we roll along
125+
var tmpDirty = m_DirtySet;
126+
m_DirtySet = new HashSet<Object>();
127+
128+
// since callbacks when being invoked we make copies for safe iteration
129+
var tmpSpys = new List<Spy>();
130+
131+
// get the set of Dirties from C++ and clear it.
132+
foreach (var o in tmpDirty)
133+
{
134+
Watchers watchers;
135+
if (m_Watched.TryGetValue(o, out watchers))
136+
{
137+
tmpSpys.Clear();
138+
tmpSpys.AddRange(watchers.spyList);
139+
140+
foreach (Spy spy in tmpSpys)
141+
{
142+
if (spy.watcher.panel != null)
143+
{
144+
// for any watches trigger callbacks
145+
spy.onDataChanged();
146+
}
147+
else
148+
{
149+
Debug.Log("Leaking Data Spies from element: " + spy.watcher);
150+
}
151+
}
152+
}
153+
}
154+
155+
tmpDirty.Clear();
156+
}
157+
158+
static int s_WatchID;
159+
160+
public IDataWatchHandle AddWatch(VisualElement watcher, Object watched, Action onDataChanged)
161+
{
162+
if (watched == null)
163+
throw new ArgumentException("Object watched cannot be null");
164+
165+
DataWatchHandle handle = new DataWatchHandle(++s_WatchID, this, watched);
166+
m_Handles[handle.id] = handle;
167+
168+
Watchers watchers;
169+
if (!m_Watched.TryGetValue(watched, out watchers))
170+
{
171+
watchers = new Watchers
172+
{
173+
spyList = new List<Spy>(),
174+
tracker = ChangeTrackerHandle.AcquireTracker(watched),
175+
};
176+
m_Watched[watched] = watchers;
177+
}
178+
watchers.spyList.Add(new Spy(handle.id, watcher, onDataChanged));
179+
return handle;
180+
}
181+
182+
public void RemoveWatch(IDataWatchHandle handle)
183+
{
184+
DataWatchHandle handleImpl = (DataWatchHandle)handle;
185+
186+
if (m_Handles.Remove(handleImpl.id))
187+
{
188+
Watchers watchers;
189+
if (m_Watched.TryGetValue(handleImpl.watched, out watchers))
190+
{
191+
List<Spy> spyList = watchers.spyList;
192+
for (int i = 0; i < spyList.Count; i++)
193+
{
194+
Spy spy = spyList[i];
195+
if (spy.handleID == handleImpl.id)
196+
{
197+
spyList.RemoveAt(i);
198+
if (watchers.spyList.Count == 0)
199+
{
200+
watchers.tracker.ReleaseTracker();
201+
m_Watched.Remove(handleImpl.watched);
202+
}
203+
return;
204+
}
205+
}
206+
}
207+
}
208+
throw new ArgumentException("Data watch was not registered");
209+
}
210+
}
211+
}
212+

Editor/Mono/EditorGUI.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2544,7 +2544,9 @@ private static int PopupInternal(Rect position, string label, int selectedIndex,
25442544
private static int PopupInternal(Rect position, GUIContent label, int selectedIndex, GUIContent[] displayedOptions, GUIStyle style)
25452545
{
25462546
int id = GUIUtility.GetControlID(s_PopupHash, FocusType.Keyboard, position);
2547-
return DoPopup(PrefixLabel(position, id, label), id, selectedIndex, displayedOptions, style);
2547+
if (label != null)
2548+
position = PrefixLabel(position, id, label);
2549+
return DoPopup(position, id, selectedIndex, displayedOptions, style);
25482550
}
25492551

25502552
// Called from PropertyField
@@ -3126,7 +3128,7 @@ private static void ObjectFieldInternal(Rect position, SerializedProperty proper
31263128
allowSceneObjects = true;
31273129
}
31283130
}
3129-
DoObjectField(position, position, id, null, null, property, null, allowSceneObjects, style);
3131+
DoObjectField(position, position, id, null, objType, property, null, allowSceneObjects, style);
31303132
}
31313133

31323134
/// *listonly*
@@ -3247,7 +3249,20 @@ internal static Object ValidateObjectFieldAssignment(Object[] references, System
32473249
if (EditorSceneManager.preventCrossSceneReferences && CheckForCrossSceneReferencing(references[0], property.serializedObject.targetObject))
32483250
return null;
32493251

3250-
return references[0];
3252+
if (objType != null)
3253+
{
3254+
foreach (Object i in references)
3255+
{
3256+
if (i != null && objType.IsAssignableFrom(i.GetType()))
3257+
{
3258+
return i;
3259+
}
3260+
}
3261+
}
3262+
else
3263+
{
3264+
return references[0];
3265+
}
32513266
}
32523267

32533268
// If array, test against the target arrayElementType, if not test against the target Type.

0 commit comments

Comments
 (0)