Skip to content

Commit 3c2fbfe

Browse files
author
Unity Technologies
committed
Unity 2020.2.0a8 C# reference source code
1 parent 3417c31 commit 3c2fbfe

File tree

360 files changed

+4477
-3191
lines changed

Some content is hidden

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

360 files changed

+4477
-3191
lines changed

Editor/Mono/2D/SpriteAtlas/EditorSpriteAtlas.bindings.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ public class SpriteAtlasUtility
1717
extern public static void PackAllAtlases(BuildTarget target, bool canCancel = true);
1818

1919
[FreeFunction("PackSpriteAtlases")]
20-
extern public static void PackAtlases(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true);
20+
extern internal static void PackAtlasesInternal(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true, bool invokedFromImporter = false, bool unloadSprites = false);
21+
22+
public static void PackAtlases(SpriteAtlas[] atlases, BuildTarget target, bool canCancel = true)
23+
{
24+
PackAtlasesInternal(atlases, target, canCancel, false, true);
25+
}
2126
}
2227

2328
[StructLayout(LayoutKind.Sequential)]

Editor/Mono/Animation/AnimationWindow/AnimationWindowControl.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,14 @@ private void ResampleAnimation(ResampleFlags flags)
648648

649649
if (usePlayableGraph)
650650
{
651-
if (HasFlag(flags, ResampleFlags.RebuildGraph) || !m_Graph.IsValid())
651+
var isValidGraph = m_Graph.IsValid();
652+
if (isValidGraph)
653+
{
654+
var playableOutput = (AnimationPlayableOutput)m_Graph.GetOutput(0);
655+
isValidGraph = playableOutput.GetTarget() == (Animator)animationPlayer;
656+
}
657+
658+
if (HasFlag(flags, ResampleFlags.RebuildGraph) || !isValidGraph)
652659
{
653660
RebuildGraph((Animator)animationPlayer);
654661
}

Editor/Mono/Animation/AnimationWindow/AnimationWindowState.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,18 @@ public void ForceRefresh()
353353
refresh = RefreshType.Everything;
354354
}
355355

356+
private void PurgeSelection()
357+
{
358+
Object.DestroyImmediate(m_Selection);
359+
m_Selection = null;
360+
}
361+
356362
public void OnEnable()
357363
{
358364
hideFlags = HideFlags.HideAndDontSave;
359365
AnimationUtility.onCurveWasModified += CurveWasModified;
360366
Undo.undoRedoPerformed += UndoRedoPerformed;
367+
AssemblyReloadEvents.beforeAssemblyReload += PurgeSelection;
361368

362369
// NoOps...
363370
onStartLiveEdit += () => {};
@@ -373,6 +380,7 @@ public void OnDisable()
373380
{
374381
AnimationUtility.onCurveWasModified -= CurveWasModified;
375382
Undo.undoRedoPerformed -= UndoRedoPerformed;
383+
AssemblyReloadEvents.beforeAssemblyReload -= PurgeSelection;
376384

377385
m_ControlInterface.OnDisable();
378386
}

Editor/Mono/Annotation/SceneViewCameraWindow.cs

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using System;
6+
using UnityEditor.ShortcutManagement;
67
using UnityEngine;
78

89
namespace UnityEditor
@@ -11,17 +12,17 @@ public class SceneViewCameraWindow : PopupWindowContent
1112
{
1213
static class Styles
1314
{
14-
static bool s_Initialized;
15-
public static GUIStyle settingsArea;
15+
public static readonly GUIContent copyPlacementLabel = EditorGUIUtility.TrTextContent("Copy Placement");
16+
public static readonly GUIContent pastePlacementLabel = EditorGUIUtility.TrTextContent("Paste Placement");
17+
public static readonly GUIContent copySettingsLabel = EditorGUIUtility.TrTextContent("Copy Settings");
18+
public static readonly GUIContent pasteSettingsLabel = EditorGUIUtility.TrTextContent("Paste Settings");
19+
public static readonly GUIContent resetSettingsLabel = EditorGUIUtility.TrTextContent("Reset Settings");
1620

17-
public static void Init()
18-
{
19-
if (s_Initialized)
20-
return;
21-
22-
s_Initialized = true;
21+
public static readonly GUIStyle settingsArea;
2322

24-
settingsArea = new GUIStyle()
23+
static Styles()
24+
{
25+
settingsArea = new GUIStyle
2526
{
2627
border = new RectOffset(4, 4, 4, 4),
2728
};
@@ -39,11 +40,6 @@ public static void Init()
3940
GUIContent m_EasingEnabled;
4041
GUIContent m_SceneCameraLabel = EditorGUIUtility.TrTextContent("Scene Camera");
4142
GUIContent m_NavigationLabel = EditorGUIUtility.TrTextContent("Navigation");
42-
GUIContent m_CopyPlacementLabel = EditorGUIUtility.TrTextContent("Copy Placement");
43-
GUIContent m_PastePlacementLabel = EditorGUIUtility.TrTextContent("Paste Placement");
44-
GUIContent m_CopySettingsLabel = EditorGUIUtility.TrTextContent("Copy Settings");
45-
GUIContent m_PasteSettingsLabel = EditorGUIUtility.TrTextContent("Paste Settings");
46-
GUIContent m_ResetSettingsLabel = EditorGUIUtility.TrTextContent("Reset Settings");
4743

4844
const int kFieldCount = 12;
4945
const int kWindowWidth = 290;
@@ -102,8 +98,6 @@ public override void OnGUI(Rect rect)
10298

10399
void Draw()
104100
{
105-
Styles.Init();
106-
107101
var settings = m_SceneView.cameraSettings;
108102

109103
m_Scroll = GUILayout.BeginScrollView(m_Scroll);
@@ -117,7 +111,7 @@ void Draw()
117111
GUILayout.Label(m_SceneCameraLabel, EditorStyles.boldLabel);
118112
GUILayout.FlexibleSpace();
119113
if (GUILayout.Button(EditorGUI.GUIContents.titleSettingsIcon, EditorStyles.iconButton))
120-
ShowContextMenu();
114+
ShowContextMenu(m_SceneView);
121115
GUILayout.EndHorizontal();
122116

123117
EditorGUIUtility.labelWidth = kPrefixLabelWidth;
@@ -212,55 +206,97 @@ void DrawClipPlanesField(GUIContent label, ref float near, ref float far, float
212206
EditorGUIUtility.labelWidth = oldLabelWidth;
213207
}
214208

215-
void ShowContextMenu()
209+
internal static void ShowContextMenu(SceneView view)
216210
{
217211
var menu = new GenericMenu();
218-
menu.AddItem(m_CopyPlacementLabel, false, CopyPlacement);
219-
if (Clipboard.HasCustomValue<TransformWorldPlacement>())
220-
menu.AddItem(m_PastePlacementLabel, false, PastePlacement);
212+
menu.AddItem(Styles.copyPlacementLabel, false, () => CopyPlacement(view));
213+
if (CanPastePlacement())
214+
menu.AddItem(Styles.pastePlacementLabel, false, () => PastePlacement(view));
221215
else
222-
menu.AddDisabledItem(m_PastePlacementLabel);
223-
menu.AddItem(m_CopySettingsLabel, false, CopySettings);
216+
menu.AddDisabledItem(Styles.pastePlacementLabel);
217+
menu.AddItem(Styles.copySettingsLabel, false, () => CopySettings(view));
224218
if (Clipboard.HasCustomValue<SceneView.CameraSettings>())
225-
menu.AddItem(m_PasteSettingsLabel, false, PasteSettings);
219+
menu.AddItem(Styles.pasteSettingsLabel, false, () => PasteSettings(view));
226220
else
227-
menu.AddDisabledItem(m_PasteSettingsLabel);
228-
menu.AddItem(m_ResetSettingsLabel, false, ResetSettings);
221+
menu.AddDisabledItem(Styles.pasteSettingsLabel);
222+
menu.AddItem(Styles.resetSettingsLabel, false, () => ResetSettings(view));
229223

230224
menu.ShowAsContext();
231225
}
232226

233-
void CopyPlacement()
227+
// ReSharper disable once UnusedMember.Local - called by a shortcut
228+
[Shortcut("Camera/Copy Placement")]
229+
static void CopyPlacementShortcut()
230+
{
231+
// if we are interacting with a game view, copy the main camera placement
232+
var playView = PlayModeView.GetLastFocusedPlayModeView();
233+
if (playView != null && (EditorWindow.focusedWindow == playView || EditorWindow.mouseOverWindow == playView))
234+
{
235+
var cam = Camera.main;
236+
if (cam != null)
237+
Clipboard.SetCustomValue(new TransformWorldPlacement(cam.transform));
238+
}
239+
// otherwise copy the last active scene view placement
240+
else
241+
{
242+
var sceneView = SceneView.lastActiveSceneView;
243+
if (sceneView != null)
244+
CopyPlacement(sceneView);
245+
}
246+
}
247+
248+
static void CopyPlacement(SceneView view)
249+
{
250+
Clipboard.SetCustomValue(new TransformWorldPlacement(view.camera.transform));
251+
}
252+
253+
// ReSharper disable once UnusedMember.Local - called by a shortcut
254+
[Shortcut("Camera/Paste Placement")]
255+
static void PastePlacementShortcut()
234256
{
235-
Clipboard.SetCustomValue(new TransformWorldPlacement(m_SceneView.camera.transform));
257+
var sceneView = SceneView.lastActiveSceneView;
258+
if (sceneView == null) return;
259+
if (CanPastePlacement())
260+
PastePlacement(sceneView);
236261
}
237262

238-
void PastePlacement()
263+
static bool CanPastePlacement()
239264
{
240-
var tr = m_SceneView.camera.transform;
265+
return Clipboard.HasCustomValue<TransformWorldPlacement>();
266+
}
267+
268+
static void PastePlacement(SceneView view)
269+
{
270+
var tr = view.camera.transform;
241271
var placement = Clipboard.GetCustomValue<TransformWorldPlacement>();
242272
tr.position = placement.position;
243273
tr.rotation = placement.rotation;
244274
tr.localScale = placement.scale;
245-
m_SceneView.AlignViewToObject(tr);
246-
m_SceneView.Repaint();
275+
276+
// Similar to what AlignViewToObject does, except we need to do that instantly
277+
// in case the shortcut key was pressed while FPS camera controls (right click drag)
278+
// were active.
279+
view.size = 10;
280+
view.LookAt(tr.position + tr.forward * view.cameraDistance, tr.rotation, view.size, view.orthographic, true);
281+
282+
view.Repaint();
247283
}
248284

249-
void CopySettings()
285+
static void CopySettings(SceneView view)
250286
{
251-
Clipboard.SetCustomValue(m_SceneView.cameraSettings);
287+
Clipboard.SetCustomValue(view.cameraSettings);
252288
}
253289

254-
void PasteSettings()
290+
static void PasteSettings(SceneView view)
255291
{
256-
m_SceneView.cameraSettings = Clipboard.GetCustomValue<SceneView.CameraSettings>();
257-
m_SceneView.Repaint();
292+
view.cameraSettings = Clipboard.GetCustomValue<SceneView.CameraSettings>();
293+
view.Repaint();
258294
}
259295

260-
void ResetSettings()
296+
static void ResetSettings(SceneView view)
261297
{
262-
m_SceneView.ResetCameraSettings();
263-
m_SceneView.Repaint();
298+
view.ResetCameraSettings();
299+
view.Repaint();
264300
}
265301
}
266302
}

Editor/Mono/AssetPipeline/TextureUtil.bindings.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ public static int GetRuntimeMemorySize(Texture t)
3636
[FreeFunction]
3737
public static extern TextureUsageMode GetUsageMode(Texture t);
3838

39+
[FreeFunction]
40+
public static extern bool IsNormalMapUsageMode(TextureUsageMode usageMode);
41+
42+
[FreeFunction]
43+
public static extern bool IsRGBMUsageMode(TextureUsageMode usageMode);
44+
45+
[FreeFunction]
46+
public static extern bool IsDoubleLDRUsageMode(TextureUsageMode usageMode);
47+
3948
[FreeFunction]
4049
public static extern int GetBytesFromTextureFormat(TextureFormat inFormat);
4150

@@ -57,6 +66,9 @@ public static int GetRuntimeMemorySize(Texture t)
5766
[FreeFunction]
5867
public static extern bool IsAlphaOnlyTextureFormat(TextureFormat format);
5968

69+
[FreeFunction]
70+
public static extern bool IsHDRFormat(TextureFormat format);
71+
6072
[FreeFunction]
6173
public static extern bool HasAlphaTextureFormat(TextureFormat format);
6274

@@ -77,6 +89,9 @@ public static bool IsDepthRTFormat(RenderTextureFormat format)
7789
[FreeFunction]
7890
public static extern bool HasMipMap(Texture t);
7991

92+
[FreeFunction]
93+
public static extern bool NeedsExposureControl(Texture t);
94+
8095
[FreeFunction]
8196
public static extern int GetGPUWidth(Texture t);
8297

0 commit comments

Comments
 (0)