Skip to content

Commit ba3d17e

Browse files
author
Unity Technologies
committed
Unity 2017.4.1f1 C# reference source code
1 parent 79ced16 commit ba3d17e

File tree

26 files changed

+3476
-3394
lines changed

26 files changed

+3476
-3394
lines changed

Editor/Mono/BuildPipeline/AssemblyStripper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,9 @@ private static string GetMethodPreserveBlacklistContents(RuntimeClassRegistry rc
290290
var assemblyName = assembly.Key;
291291
// Convert assembly names to monolithic Unity Engine if target platform requires it.
292292
if (AssemblyHelper.IsUnityEngineModule(assemblyName) && !BuildPipeline.IsFeatureSupported("ENABLE_MODULAR_UNITYENGINE_ASSEMBLIES", target))
293-
sb.AppendLine(string.Format("\t<assembly fullname=\"{0}\">", "UnityEngine"));
293+
sb.AppendLine(string.Format("\t<assembly fullname=\"{0}\" ignoreIfMissing=\"1\">", "UnityEngine"));
294294
else
295-
sb.AppendLine(string.Format("\t<assembly fullname=\"{0}\">", assemblyName));
295+
sb.AppendLine(string.Format("\t<assembly fullname=\"{0}\" ignoreIfMissing=\"1\">", assemblyName));
296296
var groupedByType = assembly.GroupBy(m => m.fullTypeName);
297297
foreach (var type in groupedByType)
298298
{

Editor/Mono/ConsoleWindow.cs

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System;
66
using System.Globalization;
77
using UnityEngine;
8-
using UnityEditor;
9-
using System.Collections;
108
using System.Collections.Generic;
119
using System.Linq;
1210
using System.Text;
@@ -163,20 +161,16 @@ protected override void OnGUIMenu(Rect connectRect, List<ProfilerChoise> profile
163161
{
164162
if (additionalMenuItems == null)
165163
{
166-
additionalMenuItems = new List<string>();
167-
additionalMenuItems.Add("Player Logging");
164+
additionalMenuItems = new List<string> {"Player Logging"};
168165
if (Unsupported.IsDeveloperBuild())
169166
additionalMenuItems.Add("Full Log (Development Editor only)");
170167
additionalMenuItems.Add("");
171168
}
172169

173-
var names = additionalMenuItems.Concat(profilers.Select(p => p.Name));
174-
175-
var enabled = new List<bool>();
170+
var names = additionalMenuItems.Concat(profilers.Select(p => p.Name)).ToArray();
176171

177172
// "Player Logging" field is always enabled.
178-
enabled.Add(true);
179-
173+
var enabled = new List<bool> {true};
180174
var selected = new List<int>();
181175

182176
var connected = PlayerConnectionLogReceiver.instance.State != PlayerConnectionLogReceiver.ConnectionState.Disconnected;
@@ -197,7 +191,7 @@ protected override void OnGUIMenu(Rect connectRect, List<ProfilerChoise> profile
197191
else
198192
{
199193
// everything but first menu item is disabled.
200-
enabled.AddRange(new bool[names.Count() - 1]);
194+
enabled.AddRange(new bool[names.Length - 1]);
201195
}
202196

203197
int index = profilers.FindIndex(p => p.IsSelected());
@@ -206,13 +200,14 @@ protected override void OnGUIMenu(Rect connectRect, List<ProfilerChoise> profile
206200

207201
var seperators = new bool[enabled.Count];
208202
seperators[additionalMenuItems.Count - 1] = true;
209-
EditorUtility.DisplayCustomMenuWithSeparators(connectRect, names.ToArray(), enabled.ToArray(), seperators, selected.ToArray(), SelectClick, profilers);
203+
EditorUtility.DisplayCustomMenuWithSeparators(connectRect, names, enabled.ToArray(), seperators, selected.ToArray(), SelectClick, profilers);
210204
}
211205
}
212206

213207
ConsoleAttachProfilerUI m_AttachProfilerUI = new ConsoleAttachProfilerUI();
214208

215-
enum Mode
209+
[Flags]
210+
internal enum Mode
216211
{
217212
Error = 1 << 0,
218213
Assert = 1 << 1,
@@ -602,33 +597,27 @@ void OnGUI()
602597

603598
GUILayout.EndHorizontal();
604599

605-
m_ListView.totalRows = LogEntries.StartGettingEntries();
606-
607600
SplitterGUILayout.BeginVerticalSplit(spl);
608601
int rowHeight = RowHeight;
609602
EditorGUIUtility.SetIconSize(new Vector2(rowHeight, rowHeight));
610603
GUIContent tempContent = new GUIContent();
611604
int id = GUIUtility.GetControlID(0);
612605

613606
/////@TODO: Make Frame selected work with ListViewState
614-
try
607+
using (new GettingLogEntriesScope(m_ListView))
615608
{
616-
bool selected = false;
609+
int selectedRow = -1;
610+
bool openSelectedItem = false;
617611
bool collapsed = HasFlag(ConsoleFlags.Collapse);
618612
foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, Constants.Box))
619613
{
620614
if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
621615
{
616+
selectedRow = m_ListView.row;
622617
if (e.clickCount == 2)
623-
{
624-
LogEntries.RowGotDoubleClicked(m_ListView.row);
625-
}
626-
627-
selected = true;
618+
openSelectedItem = true;
628619
}
629-
630-
// Paint list view element
631-
if (e.type == EventType.Repaint)
620+
else if (e.type == EventType.Repaint)
632621
{
633622
int mode = 0;
634623
string text = null;
@@ -647,7 +636,6 @@ void OnGUI()
647636
GUIStyle errorModeStyle = GetStyleForErrorMode(mode, false, Constants.LogStyleLineCount == 1);
648637
errorModeStyle.Draw(el.position, tempContent, id, m_ListView.row == el.row);
649638

650-
651639
if (collapsed)
652640
{
653641
Rect badgeRect = el.position;
@@ -661,13 +649,12 @@ void OnGUI()
661649
}
662650
}
663651

664-
if (selected)
652+
if (selectedRow != -1)
665653
{
666654
if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
667655
m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1;
668656
}
669657

670-
671658
// Make sure the selected entry is up to date
672659
if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
673660
{
@@ -691,20 +678,23 @@ void OnGUI()
691678
// Open entry using return key
692679
if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) && (e.keyCode == KeyCode.Return) && (m_ListView.row != 0))
693680
{
694-
LogEntries.RowGotDoubleClicked(m_ListView.row);
695-
Event.current.Use();
681+
selectedRow = m_ListView.row;
682+
openSelectedItem = true;
696683
}
697684

698685
if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
699686
ms_LVHeight = ListViewGUI.ilvState.rectHeight;
687+
688+
if (openSelectedItem)
689+
{
690+
LogEntries.RowGotDoubleClicked(selectedRow);
691+
Event.current.Use();
692+
}
700693
}
701-
finally
702-
{
703-
LogEntries.EndGettingEntries();
704-
EditorGUIUtility.SetIconSize(Vector2.zero);
705-
}
706694

707-
// Display active text (We want wordwrapped text with a vertical scrollbar)
695+
EditorGUIUtility.SetIconSize(Vector2.zero);
696+
697+
// Display active text (We want word wrapped text with a vertical scrollbar)
708698
m_TextScroll = GUILayout.BeginScrollView(m_TextScroll, Constants.Box);
709699
float height = Constants.MessageStyle.CalcHeight(GUIContent.Temp(m_ActiveText), position.width);
710700
EditorGUILayout.SelectableLabel(m_ActiveText, Constants.MessageStyle, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true), GUILayout.MinHeight(height));
@@ -806,4 +796,28 @@ private void AddStackTraceLoggingMenu(GenericMenu menu)
806796
}
807797
}
808798
}
799+
800+
internal class GettingLogEntriesScope : IDisposable
801+
{
802+
private bool m_Disposed;
803+
804+
public GettingLogEntriesScope(ListViewState listView)
805+
{
806+
listView.totalRows = LogEntries.StartGettingEntries();
807+
}
808+
809+
public void Dispose()
810+
{
811+
if (m_Disposed)
812+
return;
813+
LogEntries.EndGettingEntries();
814+
m_Disposed = true;
815+
}
816+
817+
~GettingLogEntriesScope()
818+
{
819+
if (!m_Disposed)
820+
Debug.LogError("Scope was not disposed! You should use the 'using' keyword or manually call Dispose.");
821+
}
822+
}
809823
}

Editor/Mono/GameView/GameView.cs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,23 @@ internal Vector2 targetSize // Size of render target in pixels
178178
}
179179

180180
// Area of the render target in zoom content space (it is centered in content space)
181-
Rect targetInContent { get { return EditorGUIUtility.PixelsToPoints(new Rect(-0.5f * targetSize, targetSize)); } }
181+
Rect targetInContent
182+
{
183+
get
184+
{
185+
var targetSizeCached = targetSize;
186+
return EditorGUIUtility.PixelsToPoints(new Rect(-0.5f * targetSizeCached, targetSizeCached));
187+
}
188+
}
182189

183190
Rect targetInView // Area of the render target in zoom view space
184191
{
185192
get
186193
{
194+
var targetInContentCached = targetInContent;
187195
return new Rect(
188-
m_ZoomArea.DrawingToViewTransformPoint(targetInContent.position),
189-
m_ZoomArea.DrawingToViewTransformVector(targetInContent.size)
196+
m_ZoomArea.DrawingToViewTransformPoint(targetInContentCached.position),
197+
m_ZoomArea.DrawingToViewTransformVector(targetInContentCached.size)
190198
);
191199
}
192200
}
@@ -225,18 +233,24 @@ Rect viewInParent // The view area in parent view space
225233

226234
Rect targetInParent // Area of the render target in parent view space
227235
{
228-
get { return new Rect(targetInView.position + viewInParent.position, targetInView.size); }
236+
get
237+
{
238+
var targetInViewCached = targetInView;
239+
return new Rect(targetInViewCached.position + viewInParent.position, targetInViewCached.size);
240+
}
229241
}
230242

231243
Rect clippedTargetInParent // targetInParent, but clipped to viewInParent to discard outside mouse events
232244
{
233245
get
234246
{
247+
var targetInParentCached = targetInParent;
248+
var viewInParentCached = viewInParent;
235249
var clippedTargetInParent = Rect.MinMaxRect(
236-
Mathf.Max(targetInParent.xMin, viewInParent.xMin),
237-
Mathf.Max(targetInParent.yMin, viewInParent.yMin),
238-
Mathf.Min(targetInParent.xMax, viewInParent.xMax),
239-
Mathf.Min(targetInParent.yMax, viewInParent.yMax)
250+
Mathf.Max(targetInParentCached.xMin, viewInParentCached.xMin),
251+
Mathf.Max(targetInParentCached.yMin, viewInParentCached.yMin),
252+
Mathf.Min(targetInParentCached.xMax, viewInParentCached.xMax),
253+
Mathf.Min(targetInParentCached.yMax, viewInParentCached.yMax)
240254
);
241255
return clippedTargetInParent;
242256
}
@@ -640,10 +654,11 @@ private void ConfigureZoomArea()
640654
{
641655
m_ZoomArea.rect = viewInWindow;
642656
// Sliders are sized with respect to canvas
643-
m_ZoomArea.hBaseRangeMin = targetInContent.xMin;
644-
m_ZoomArea.vBaseRangeMin = targetInContent.yMin;
645-
m_ZoomArea.hBaseRangeMax = targetInContent.xMax;
646-
m_ZoomArea.vBaseRangeMax = targetInContent.yMax;
657+
var targetInContentCached = targetInContent;
658+
m_ZoomArea.hBaseRangeMin = targetInContentCached.xMin;
659+
m_ZoomArea.vBaseRangeMin = targetInContentCached.yMin;
660+
m_ZoomArea.hBaseRangeMax = targetInContentCached.xMax;
661+
m_ZoomArea.vBaseRangeMax = targetInContentCached.yMax;
647662
// Restrict zooming
648663
m_ZoomArea.hScaleMin = m_ZoomArea.vScaleMin = minScale;
649664
m_ZoomArea.hScaleMax = m_ZoomArea.vScaleMax = maxScale;
@@ -652,16 +667,17 @@ private void ConfigureZoomArea()
652667
private void EnforceZoomAreaConstraints()
653668
{
654669
var shownArea = m_ZoomArea.shownArea;
670+
var targetInContentCached = targetInContent;
655671

656672
// When zoomed out, we disallow panning by automatically centering the view
657-
if (shownArea.width > targetInContent.width)
673+
if (shownArea.width > targetInContentCached.width)
658674
{
659675
shownArea.x = -0.5f * shownArea.width;
660676
}
661677
else
662678
// When zoomed in, we prevent panning outside the render area
663679
{
664-
shownArea.x = Mathf.Clamp(shownArea.x, targetInContent.xMin, targetInContent.xMax - shownArea.width);
680+
shownArea.x = Mathf.Clamp(shownArea.x, targetInContentCached.xMin, targetInContentCached.xMax - shownArea.width);
665681
}
666682
// Horizontal and vertical are separated because otherwise we get weird behaviour when only one is zoomed out
667683
if (shownArea.height > targetInContent.height)
@@ -670,7 +686,7 @@ private void EnforceZoomAreaConstraints()
670686
}
671687
else
672688
{
673-
shownArea.y = Mathf.Clamp(shownArea.y, targetInContent.yMin, targetInContent.yMax - shownArea.height);
689+
shownArea.y = Mathf.Clamp(shownArea.y, targetInContentCached.yMin, targetInContentCached.yMax - shownArea.height);
674690
}
675691

676692
m_ZoomArea.shownArea = shownArea;
@@ -706,8 +722,9 @@ private void OnGUI()
706722

707723
// We hide sliders when playing, and also when we are zoomed out beyond canvas edges
708724
var playing = EditorApplication.isPlaying && !EditorApplication.isPaused;
709-
m_ZoomArea.hSlider = !playing && m_ZoomArea.shownArea.width < targetInContent.width;
710-
m_ZoomArea.vSlider = !playing && m_ZoomArea.shownArea.height < targetInContent.height;
725+
var targetInContentCached = targetInContent;
726+
m_ZoomArea.hSlider = !playing && m_ZoomArea.shownArea.width < targetInContentCached.width;
727+
m_ZoomArea.vSlider = !playing && m_ZoomArea.shownArea.height < targetInContentCached.height;
711728
m_ZoomArea.enableMouseInput = !playing;
712729
ConfigureZoomArea();
713730

Editor/Mono/GameView/GameViewSize.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,53 @@ public string baseText
3131
get {return m_BaseText; }
3232
set
3333
{
34+
var oldBaseText = m_BaseText;
3435
m_BaseText = value;
3536
if (m_BaseText.Length > kMaxBaseTextLength)
3637
m_BaseText = m_BaseText.Substring(0, kMaxBaseTextLength);
37-
Changed();
38+
if (m_BaseText != oldBaseText)
39+
Changed();
3840
}
3941
}
4042
public GameViewSizeType sizeType
4143
{
4244
get { return m_SizeType; }
4345
set
4446
{
45-
m_SizeType = value; Clamp(); Changed();
47+
var oldSizeType = m_SizeType;
48+
m_SizeType = value;
49+
Clamp();
50+
if (m_SizeType != oldSizeType)
51+
Changed();
4652
}
4753
}
4854
public int width
4955
{
5056
get { return m_Width; }
51-
set { m_Width = value; Clamp(); Changed(); }
57+
set
58+
{
59+
var oldWidth = m_Width;
60+
m_Width = value;
61+
Clamp();
62+
if (m_Width != oldWidth)
63+
Changed();
64+
}
5265
}
5366
public int height
5467
{
5568
get { return m_Height; }
56-
set { m_Height = value; Clamp(); Changed(); }
69+
set
70+
{
71+
var oldHeight = m_Height;
72+
m_Height = value;
73+
Clamp();
74+
if (m_Height != oldHeight)
75+
Changed();
76+
}
5777
}
5878

5979
void Clamp()
6080
{
61-
int orgWidth = m_Width;
62-
int orgHeight = m_Height;
63-
6481
int minValue = 0;
6582
switch (sizeType)
6683
{
@@ -77,9 +94,6 @@ void Clamp()
7794

7895
m_Width = Mathf.Clamp(m_Width, minValue, kMaxResolutionOrAspect);
7996
m_Height = Mathf.Clamp(m_Height, minValue, kMaxResolutionOrAspect);
80-
81-
if (m_Width != orgWidth || m_Height != orgHeight)
82-
Changed();
8397
}
8498

8599
public GameViewSize(GameViewSizeType type, int width, int height, string baseText)
@@ -101,7 +115,6 @@ public void Set(GameViewSize other)
101115
width = other.width;
102116
height = other.height;
103117
baseText = other.baseText;
104-
Changed();
105118
}
106119

107120
public bool isFreeAspectRatio

0 commit comments

Comments
 (0)