Skip to content

Commit 95eee03

Browse files
author
Unity Technologies
committed
Unity 2018.3.0b7 C# reference source code
1 parent 4236176 commit 95eee03

71 files changed

Lines changed: 1156 additions & 654 deletions

File tree

Some content is hidden

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

Editor/Mono/2D/SpriteEditorModule/SpriteFrameModule/SpriteFrameModuleBaseView.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,9 @@ private void AddMainUI(VisualElement mainView)
200200
if (hasSelected)
201201
{
202202
var border = selectedSpriteBorder;
203-
border.y = evt.newValue;
203+
border.w = evt.newValue;
204204
selectedSpriteBorder = border;
205-
m_BorderFieldT.SetValueWithoutNotify((long)selectedSpriteBorder.y);
205+
m_BorderFieldT.SetValueWithoutNotify((long)selectedSpriteBorder.w);
206206
evt.StopPropagation();
207207
}
208208
});
@@ -225,9 +225,9 @@ private void AddMainUI(VisualElement mainView)
225225
if (hasSelected)
226226
{
227227
var border = selectedSpriteBorder;
228-
border.w = evt.newValue;
228+
border.y = evt.newValue;
229229
selectedSpriteBorder = border;
230-
m_BorderFieldB.SetValueWithoutNotify((long)selectedSpriteBorder.w);
230+
m_BorderFieldB.SetValueWithoutNotify((long)selectedSpriteBorder.y);
231231
}
232232
});
233233

@@ -335,9 +335,9 @@ protected void PopulateSpriteFrameInspectorField()
335335
m_PositionFieldH.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.height));
336336
var spriteBorder = selectedSpriteBorder;
337337
m_BorderFieldL.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.x));
338-
m_BorderFieldT.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.y));
338+
m_BorderFieldT.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.w));
339339
m_BorderFieldR.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.z));
340-
m_BorderFieldB.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.w));
340+
m_BorderFieldB.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.y));
341341
m_PivotField.SetValueWithoutNotify(selectedSpriteAlignment);
342342
m_PivotUnitModeField.SetValueWithoutNotify(m_PivotUnitMode);
343343
Vector2 pivot = selectedSpritePivotInCurUnitMode;

Editor/Mono/Animation/AnimationWindow/CurveEditor.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public CurveWrapper()
5151
setAxisUiScalarsCallback = null;
5252
}
5353

54+
// Fix for case 1086532 - Audio source inspector leaks memory
55+
~CurveWrapper()
56+
{
57+
if (m_Renderer != null)
58+
m_Renderer.FlushCache();
59+
}
60+
5461
internal enum SelectionMode
5562
{
5663
None = 0,

Editor/Mono/EditorHandles/FreeMove.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static Vector3 Do(int id, Vector3 position, Quaternion rotation, float si
2222
Vector3 worldPosition = Handles.matrix.MultiplyPoint(position);
2323
Matrix4x4 origMatrix = Handles.matrix;
2424

25-
VertexSnapping.HandleKeyAndMouseMove(id);
25+
VertexSnapping.HandleMouseMove(id);
2626

2727
Event evt = Event.current;
2828
switch (evt.GetTypeForControl(id))
@@ -162,7 +162,7 @@ public static Vector3 Do(int id, Vector3 position, Quaternion rotation, float si
162162
Vector3 worldPosition = Handles.matrix.MultiplyPoint(position);
163163
Matrix4x4 origMatrix = Handles.matrix;
164164

165-
VertexSnapping.HandleKeyAndMouseMove(id);
165+
VertexSnapping.HandleMouseMove(id);
166166

167167
Event evt = Event.current;
168168
switch (evt.GetTypeForControl(id))

Editor/Mono/EditorHandles/PositionHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static Vector3 DoPositionHandle_Internal(PositionHandleIds ids, Vector3 position
322322
}
323323
}
324324

325-
VertexSnapping.HandleKeyAndMouseMove(ids.xyz);
325+
VertexSnapping.HandleMouseMove(ids.xyz);
326326
if (param.ShouldShow(PositionHandleParam.Handle.XYZ) && (isHot && ids.xyz == GUIUtility.hotControl || !isHot))
327327
{
328328
color = ToActiveColorSpace(centerColor);

Editor/Mono/EditorHandles/VertexSnapping.cs

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,35 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using UnityEngine;
6-
using UnityEditor;
6+
using UnityEditor.ShortcutManagement;
77

88
namespace UnityEditor
99
{
1010
internal class VertexSnapping
1111
{
1212
private static Vector3 s_VertexSnappingOffset = Vector3.zero;
1313

14-
// This method handles KeyUp, KeyDown and MouseMove for doing vertex snapping.
14+
[Shortcut("Scene View/Toggle Vertex Snapping", typeof(SceneView), "#v")]
15+
private static void ToggleVertexSnappingViaShortcut()
16+
{
17+
int id = GUIUtility.hotControl;
18+
if (Tools.vertexDragging)
19+
DisableVertexSnapping(id);
20+
else
21+
EnableVertexSnapping(id);
22+
}
23+
24+
[ClutchShortcut("Scene View/Vertex Snapping", typeof(SceneView), "v")]
25+
private static void ToggleVertexSnappingViaClutchShortcut(ShortcutArguments arguments)
26+
{
27+
int id = GUIUtility.hotControl;
28+
if (arguments.state == ShortcutState.Begin)
29+
EnableVertexSnapping(id);
30+
else
31+
DisableVertexSnapping(id);
32+
}
33+
34+
// This method handles MouseMove for doing vertex snapping.
1535
// To ensure correct behaviour the caller must do on it's own:
1636
// - On MouseDown and MouseUp (if event is ours to use):
1737
// HandleUtility.ignoreRaySnapObjects = null;
@@ -29,52 +49,13 @@ internal class VertexSnapping
2949
//
3050
// This is not the most elegant code-reuse solution,
3151
// but still a step up from the copy-pasted code that was used before.
32-
public static void HandleKeyAndMouseMove(int id)
52+
public static void HandleMouseMove(int id)
3353
{
34-
Event evt = Event.current;
35-
switch (evt.GetTypeForControl(id))
54+
var evt = Event.current;
55+
if (evt.GetTypeForControl(id) == EventType.MouseMove && Tools.vertexDragging)
3656
{
37-
case EventType.MouseMove:
38-
{
39-
if (Tools.vertexDragging)
40-
{
41-
EnableVertexSnapping(id);
42-
evt.Use();
43-
}
44-
break;
45-
}
46-
case EventType.KeyDown:
47-
{
48-
// Vertex selection
49-
if (!EditorGUIUtility.editingTextField && evt.keyCode == KeyCode.V)
50-
{
51-
// We are searching for a vertex in our selection
52-
if (!Tools.vertexDragging && !evt.shift)
53-
EnableVertexSnapping(id);
54-
55-
evt.Use();
56-
}
57-
break;
58-
}
59-
case EventType.KeyUp:
60-
{
61-
// Vertex selection
62-
if (!EditorGUIUtility.editingTextField && evt.keyCode == KeyCode.V)
63-
{
64-
if (evt.shift)
65-
Tools.vertexDragging = !Tools.vertexDragging; // toggle vertex dragging
66-
else if (Tools.vertexDragging)
67-
Tools.vertexDragging = false; // stop vertex dragging
68-
69-
if (Tools.vertexDragging)
70-
EnableVertexSnapping(id);
71-
else
72-
DisableVertexSnapping(id);
73-
74-
evt.Use();
75-
}
76-
break;
77-
}
57+
EnableVertexSnapping(id);
58+
evt.Use();
7859
}
7960
}
8061

Editor/Mono/GUI/CreateAssetUtility.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System.IO;
66
using UnityEditor.ProjectWindowCallback;
7+
using UnityEditor.Utils;
78
using UnityEngine;
89

910

@@ -44,7 +45,7 @@ public Texture2D icon
4445

4546
public string folder
4647
{
47-
get { return Path.GetDirectoryName(m_Path); }
48+
get { return Path.GetDirectoryName(m_Path).ConvertSeparatorsToUnity(); }
4849
}
4950

5051
public string extension
@@ -77,19 +78,23 @@ static bool IsPathDataValid(string filePath)
7778
// Selection changes when calling BeginNewAsset if it succeeds
7879
public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndAction, string filePath, Texture2D icon, string newAssetResourceFile)
7980
{
81+
//Sanitize input
82+
string sanitizedFilePath = filePath != null ? filePath.ConvertSeparatorsToUnity() : filePath;
83+
string sanitizedNewAssetResourceFile = newAssetResourceFile != null ? newAssetResourceFile.ConvertSeparatorsToUnity() : newAssetResourceFile;
84+
8085
string uniquePath;
81-
if (!filePath.StartsWith("assets/", System.StringComparison.CurrentCultureIgnoreCase))
86+
if (!sanitizedFilePath.StartsWith("assets/", System.StringComparison.CurrentCultureIgnoreCase))
8287
{
83-
uniquePath = AssetDatabase.GetUniquePathNameAtSelectedPath(filePath);
88+
uniquePath = AssetDatabase.GetUniquePathNameAtSelectedPath(sanitizedFilePath);
8489
}
8590
else
8691
{
87-
uniquePath = AssetDatabase.GenerateUniqueAssetPath(filePath);
92+
uniquePath = AssetDatabase.GenerateUniqueAssetPath(sanitizedFilePath);
8893
}
8994

9095
if (!IsPathDataValid(uniquePath))
9196
{
92-
Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", uniquePath, filePath);
97+
Debug.LogErrorFormat("Invalid generated unique path '{0}' (input path '{1}')", uniquePath, sanitizedFilePath);
9398
Clear();
9499
return false;
95100
}
@@ -98,7 +103,7 @@ public bool BeginNewAssetCreation(int instanceID, EndNameEditAction newAssetEndA
98103
m_Path = uniquePath;
99104
m_Icon = icon;
100105
m_EndAction = newAssetEndAction;
101-
m_ResourceFile = newAssetResourceFile;
106+
m_ResourceFile = sanitizedNewAssetResourceFile;
102107

103108
// Change selection to none or instanceID
104109
Selection.activeObject = EditorUtility.InstanceIDToObject(instanceID);

Editor/Mono/GUI/Tools/BuiltinTools.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ static Vector3 MoveHandlesGUI(Rect rect, Vector3 pivot, Quaternion rotation)
663663
corners[2] = rotation * new Vector2(rect.xMax, rect.yMax) + pivot;
664664
corners[3] = rotation * new Vector2(rect.x, rect.yMax) + pivot;
665665

666-
VertexSnapping.HandleKeyAndMouseMove(id);
666+
VertexSnapping.HandleMouseMove(id);
667667

668668
bool supportsRectSnapping = Selection.transforms.Length == 1 &&
669669
UnityEditorInternal.InternalEditorUtility.SupportsRectLayout(Selection.activeTransform) &&

Editor/Mono/GUI/TreeView/AssetOrGameObjectTreeViewDragging.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ public override void StartDrag(TreeViewItem draggedItem, List<int> draggedItemID
160160

161161
public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewItem targetItem, bool perform, DropPosition dropPos)
162162
{
163-
// Scene dragging logic
164-
DragAndDropVisualMode dragSceneResult = DoDragScenes(parentItem as GameObjectTreeViewItem, targetItem as GameObjectTreeViewItem, perform, dropPos);
165-
if (dragSceneResult != DragAndDropVisualMode.None)
166-
return dragSceneResult;
167-
168163
// Allow client to handle drag
169164
if (m_CustomDragHandling != null)
170165
{
@@ -173,6 +168,11 @@ public override DragAndDropVisualMode DoDrag(TreeViewItem parentItem, TreeViewIt
173168
return dragResult;
174169
}
175170

171+
// Scene dragging logic
172+
DragAndDropVisualMode dragSceneResult = DoDragScenes(parentItem as GameObjectTreeViewItem, targetItem as GameObjectTreeViewItem, perform, dropPos);
173+
if (dragSceneResult != DragAndDropVisualMode.None)
174+
return dragSceneResult;
175+
176176
if (targetItem != null && !IsDropTargetUserModifiable(targetItem as GameObjectTreeViewItem, dropPos))
177177
return DragAndDropVisualMode.Rejected;
178178

Editor/Mono/GameView/GameViewSizes.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,12 @@ private void InitBuiltinGroups()
197197
// iOS
198198
GameViewSize k_iPhone_750p_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 750, 1334, "iPhone 1334x750 Portrait");
199199
GameViewSize k_iPhone_750p_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 1334, 750, "iPhone 1334x750 Landscape");
200-
GameViewSize k_iPhone_X_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 1125, 2436, "iPhoneX 2436x1125 Portrait");
201-
GameViewSize k_iPhone_X_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 2436, 1125, "iPhoneX 2436x1125 Landscape");
200+
GameViewSize k_iPhone_X_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 1125, 2436, "iPhone X/XS 2436x1125 Portrait");
201+
GameViewSize k_iPhone_X_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 2436, 1125, "iPhone X/XS 2436x1125 Landscape");
202+
GameViewSize k_iPhone_828p_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 828, 1792, "iPhone XR 1792x828 Portrait");
203+
GameViewSize k_iPhone_828p_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 1792, 828, "iPhone XR 1792x828 Landscape");
204+
GameViewSize k_iPhone_1242p_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 1242, 2688, "iPhone XS Max 2688x1242 Portrait");
205+
GameViewSize k_iPhone_1242p_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 2688, 1242, "iPhone XS Max 2688x1242 Landscape");
202206

203207
GameViewSize k_iPad_1536p_Landscape = new GameViewSize(GameViewSizeType.FixedResolution, 2048, 1536, "iPad 2048x1536 Landscape");
204208
GameViewSize k_iPad_1536p_Portrait = new GameViewSize(GameViewSizeType.FixedResolution, 1536, 2048, "iPad 2048x1536 Portrait");
@@ -232,6 +236,8 @@ private void InitBuiltinGroups()
232236
k_iPhone_750p_Portrait, k_iPhone_750p_Landscape,
233237
k_1080p_Portrait, k_1080p_Landscape,
234238
k_iPhone_X_Portrait, k_iPhone_X_Landscape,
239+
k_iPhone_828p_Portrait, k_iPhone_828p_Landscape,
240+
k_iPhone_1242p_Portrait, k_iPhone_1242p_Landscape,
235241
k_iPad_1536p_Landscape, k_iPad_1536p_Portrait,
236242
k_iPad_2048p_Landscape, k_iPad_2048p_Portrait,
237243
k_iPad_1668p_Landscape, k_iPad_1668p_Portrait,

Editor/Mono/Inspector/Editor.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -763,25 +763,19 @@ protected virtual bool ShouldHideOpenButton()
763763
internal virtual void OnHeaderIconGUI(Rect iconRect)
764764
{
765765
Texture2D icon = null;
766-
if (!HasPreviewGUI())
766+
767+
// Fetch isLoadingAssetPreview to ensure that there is no situation where a preview needs a repaint because it hasn't finished loading yet.
768+
bool isLoadingAssetPreview = AssetPreview.IsLoadingAssetPreview(target.GetInstanceID());
769+
icon = AssetPreview.GetAssetPreview(target);
770+
if (!icon)
767771
{
768-
// Fetch isLoadingAssetPreview to ensure that there is no situation where a preview needs a repaint because it hasn't finished loading yet.
769-
bool isLoadingAssetPreview = AssetPreview.IsLoadingAssetPreview(target.GetInstanceID());
770-
icon = AssetPreview.GetAssetPreview(target);
771-
if (!icon)
772-
{
773-
// We have a static preview it just hasn't been loaded yet. Repaint until we have it loaded.
774-
if (isLoadingAssetPreview)
775-
Repaint();
776-
icon = AssetPreview.GetMiniThumbnail(target);
777-
}
772+
// We have a static preview it just hasn't been loaded yet. Repaint until we have it loaded.
773+
if (isLoadingAssetPreview)
774+
Repaint();
775+
icon = AssetPreview.GetMiniThumbnail(target);
778776
}
779777

780-
if (HasPreviewGUI())
781-
// OnPreviewGUI must have all events; not just Repaint, or else the control IDs will mis-match.
782-
OnPreviewGUI(iconRect, BaseStyles.inspectorBigInner);
783-
else if (icon)
784-
GUI.Label(iconRect, icon, BaseStyles.centerStyle);
778+
GUI.Label(iconRect, icon, BaseStyles.centerStyle);
785779
}
786780

787781
internal virtual void OnHeaderTitleGUI(Rect titleRect, string header)
@@ -816,9 +810,10 @@ internal virtual void DrawHeaderHelpAndSettingsGUI(Rect r)
816810
// draw the header, and then start a new vertical block with the same style.
817811
private void DrawHeaderFromInsideHierarchy()
818812
{
813+
var style = GUILayoutUtility.topLevel.style;
819814
EditorGUILayout.EndVertical();
820815
OnHeaderGUI();
821-
EditorGUILayout.BeginVertical(GUILayoutUtility.topLevel.style);
816+
EditorGUILayout.BeginVertical(style);
822817
}
823818

824819
internal static Rect DrawHeaderGUI(Editor editor, string header)

0 commit comments

Comments
 (0)