Skip to content

Commit 0771998

Browse files
author
Unity Technologies
committed
Unity 2019.1.8f1 C# reference source code
1 parent 522c96e commit 0771998

8 files changed

Lines changed: 112 additions & 39 deletions

File tree

Editor/Mono/GameView/GameView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ void InitializeZoomArea()
312312

313313
public void OnEnable()
314314
{
315+
prevSizeGroupType = (int)currentSizeGroupType;
315316
titleContent = GetLocalizedTitleContent();
316317
UpdateZoomAreaAndParent();
317318
dontClearBackground = true;

Editor/Mono/PostprocessScene.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
// Copyright (c) Unity Technologies. For terms of use, see
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

5+
using System;
56
using UnityEngine;
67
using UnityEditor.Build;
8+
using System.Text;
9+
using UnityEngine.SceneManagement;
710

811
namespace UnityEditor
912
{
@@ -16,7 +19,50 @@ public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, Build.Report
1619
PlayerSettings.GetBatchingForPlatform(EditorUserBuildSettings.activeBuildTarget, out staticBatching, out dynamicBatching);
1720
if (staticBatching != 0)
1821
{
19-
InternalStaticBatchingUtility.Combine(null, true, true);
22+
InternalStaticBatchingUtility.Combine(null, true, true, new EditorStaticBatcherGOSorter(scene));
23+
}
24+
}
25+
26+
internal class EditorStaticBatcherGOSorter : InternalStaticBatchingUtility.StaticBatcherGOSorter
27+
{
28+
Scene scene;
29+
30+
public EditorStaticBatcherGOSorter(Scene scene)
31+
{
32+
this.scene = scene;
33+
}
34+
35+
private static long GetStableHash(UnityEngine.Object instance, string guid)
36+
{
37+
var lfid = UnityEditor.Unsupported.GetFileIDHint(instance);
38+
39+
using (var md5Hash = System.Security.Cryptography.MD5.Create())
40+
{
41+
var bytes = Encoding.ASCII.GetBytes(guid);
42+
md5Hash.TransformBlock(bytes, 0, bytes.Length, null, 0);
43+
bytes = BitConverter.GetBytes(lfid);
44+
md5Hash.TransformFinalBlock(bytes, 0, bytes.Length);
45+
return BitConverter.ToInt64(md5Hash.Hash, 0);
46+
}
47+
}
48+
49+
public override long GetMaterialId(Renderer renderer)
50+
{
51+
if (renderer == null || renderer.sharedMaterial == null)
52+
return 0;
53+
54+
string path = AssetDatabase.GetAssetPath(renderer.sharedMaterial);
55+
string guid = AssetDatabase.AssetPathToGUID(path);
56+
return GetStableHash(renderer.sharedMaterial, guid);
57+
}
58+
59+
public override long GetRendererId(Renderer renderer)
60+
{
61+
if (renderer == null)
62+
return -1;
63+
64+
string guid = AssetDatabase.AssetPathToGUID(scene.path);
65+
return GetStableHash(renderer, guid);
2066
}
2167
}
2268
}

Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStage.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ internal PrefabStage()
133133

134134
internal bool LoadStage(string prefabPath)
135135
{
136+
if (!File.Exists(prefabPath))
137+
{
138+
Debug.LogError("LoadStage with an invalid path: Prefab file not found " + prefabPath);
139+
return false;
140+
}
141+
136142
if (isValid)
137143
Cleanup();
138144

@@ -322,6 +328,10 @@ void HandlePrefabChangedOnDisk()
322328
if (m_PrefabWasChangedOnDisk)
323329
{
324330
m_PrefabWasChangedOnDisk = false;
331+
332+
if (!File.Exists(m_PrefabAssetPath))
333+
return;
334+
325335
if (HasSceneBeenModified())
326336
{
327337
var title = L10n.Tr("Prefab Has Been Changed on Disk");

Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStageUtility.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -311,31 +311,31 @@ static void AppendEnvironmentName(Transform transform, object userData)
311311
static Scene CreateDefaultPreviewScene()
312312
{
313313
Scene previewScene = EditorSceneManager.NewPreviewScene();
314-
Unsupported.SetOverrideLightingSettings(previewScene);
315314

316315
// Setup default render settings for this preview scene
316+
Unsupported.SetOverrideLightingSettings(previewScene);
317317
UnityEngine.RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
318-
UnityEngine.RenderSettings.customReflection = GetDefaultReflection(); // ensure chrome materials do not render balck
318+
UnityEngine.RenderSettings.customReflection = GetDefaultReflection(); // ensure chrome materials do not render black
319319
UnityEngine.RenderSettings.skybox = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Skybox.mat") as Material;
320320
UnityEngine.RenderSettings.ambientMode = AmbientMode.Skybox;
321+
UnityEditorInternal.InternalEditorUtility.CalculateAmbientProbeFromSkybox();
321322
Unsupported.RestoreOverrideLightingSettings();
322323

323324
return previewScene;
324325
}
325326

326-
static Cubemap s_DefaultHDRI;
327+
static Cubemap s_DefaultReflection;
327328
static Cubemap GetDefaultReflection()
328329
{
329-
if (s_DefaultHDRI == null)
330+
const string path = "PrefabMode/DefaultReflectionForPrefabMode.exr";
331+
if (s_DefaultReflection == null)
330332
{
331-
s_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.exr") as Cubemap;
332-
if (s_DefaultHDRI == null)
333-
s_DefaultHDRI = EditorGUIUtility.Load("LookDevView/DefaultHDRI.asset") as Cubemap;
333+
s_DefaultReflection = EditorGUIUtility.Load(path) as Cubemap;
334334
}
335335

336-
if (s_DefaultHDRI == null)
337-
Debug.LogError("Could not find DefaultHDRI");
338-
return s_DefaultHDRI;
336+
if (s_DefaultReflection == null)
337+
Debug.LogError("Could not find: " + path);
338+
return s_DefaultReflection;
339339
}
340340

341341
internal static void DestroyPreviewScene(Scene previewScene)

Editor/Mono/SceneManagement/StageManager/StageNavigationManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public void ChangingStageStarted(StageNavigationItem previousStageItem)
612612
m_EventData = new EventData();
613613
m_EventData.existingStage = GetStageType(previousStageItem);
614614
m_EventData.existingBreadcrumbCount = StageNavigationManager.instance.stageHistory.Length;
615-
if (previousStageItem.isPrefabStage)
615+
if (previousStageItem.prefabStage != null)
616616
{
617617
m_EventData.didUserModify = previousStageItem.prefabStage.analyticsDidUserModify;
618618
m_EventData.didUserSave = previousStageItem.prefabStage.analyticsDidUserSave;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Unity 2019.1.7f1 C# reference source code
1+
## Unity 2019.1.8f1 C# reference source code
22

33
The C# part of the Unity engine and editor source code.
44
May be used for reference purposes only.

Runtime/Export/StaticBatching/CombineForStaticBatching.cs

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
using System.Collections;
88
using System.Collections.Generic;
99
using System.Linq;
10+
using System.Text;
1011

1112
namespace UnityEngine
1213
{
1314
public sealed partial class StaticBatchingUtility
1415
{
1516
static public void Combine(GameObject staticBatchRoot)
1617
{
17-
InternalStaticBatchingUtility.CombineRoot(staticBatchRoot);
18+
InternalStaticBatchingUtility.CombineRoot(staticBatchRoot, null);
1819
}
1920

2021
static public void Combine(GameObject[] gos, GameObject staticBatchRoot)
2122
{
22-
InternalStaticBatchingUtility.CombineGameObjects(gos, staticBatchRoot, false);
23+
InternalStaticBatchingUtility.CombineGameObjects(gos, staticBatchRoot, false, null);
2324
}
2425
}
2526

@@ -29,12 +30,12 @@ internal class InternalStaticBatchingUtility
2930
const int MaxVerticesInBatch = 64000; // a little bit less than 64K - just in case
3031
const string CombinedMeshPrefix = "Combined Mesh";
3132

32-
static public void CombineRoot(UnityEngine.GameObject staticBatchRoot)
33+
public static void CombineRoot(UnityEngine.GameObject staticBatchRoot, StaticBatcherGOSorter sorter)
3334
{
34-
Combine(staticBatchRoot, false, false);
35+
Combine(staticBatchRoot, false, false, sorter);
3536
}
3637

37-
static public void Combine(UnityEngine.GameObject staticBatchRoot, bool combineOnlyStatic, bool isEditorPostprocessScene)
38+
static public void Combine(UnityEngine.GameObject staticBatchRoot, bool combineOnlyStatic, bool isEditorPostprocessScene, StaticBatcherGOSorter sorter)
3839
{
3940
GameObject[] gos = (GameObject[])UnityEngine.Object.FindObjectsOfType(typeof(GameObject));
4041

@@ -53,10 +54,28 @@ static public void Combine(UnityEngine.GameObject staticBatchRoot, bool combineO
5354

5455
gos = filteredGos.ToArray();
5556

56-
CombineGameObjects(gos, staticBatchRoot, isEditorPostprocessScene);
57+
CombineGameObjects(gos, staticBatchRoot, isEditorPostprocessScene, sorter);
5758
}
5859

59-
static public void CombineGameObjects(GameObject[] gos, UnityEngine.GameObject staticBatchRoot, bool isEditorPostprocessScene)
60+
public static GameObject[] SortGameObjectsForStaticbatching(GameObject[] gos, StaticBatcherGOSorter sorter)
61+
{
62+
gos = gos.OrderBy(x =>
63+
{
64+
Renderer aRenderer = StaticBatcherGOSorter.GetRenderer(x as GameObject);
65+
return sorter.GetMaterialId(aRenderer);
66+
}).ThenBy(y =>
67+
{
68+
Renderer aRenderer = StaticBatcherGOSorter.GetRenderer(y as GameObject);
69+
return sorter.GetLightmapIndex(aRenderer);
70+
}).ThenBy(z =>
71+
{
72+
Renderer aRenderer = StaticBatcherGOSorter.GetRenderer(z as GameObject);
73+
return sorter.GetRendererId(aRenderer);
74+
}).ToArray();
75+
return gos;
76+
}
77+
78+
static public void CombineGameObjects(GameObject[] gos, UnityEngine.GameObject staticBatchRoot, bool isEditorPostprocessScene, StaticBatcherGOSorter sorter)
6079
{
6180
Matrix4x4 staticBatchInverseMatrix = Matrix4x4.identity;
6281
Transform staticBatchRootTransform = null;
@@ -70,7 +89,7 @@ static public void CombineGameObjects(GameObject[] gos, UnityEngine.GameObject s
7089
int verticesInBatch = 0;
7190
List<MeshSubsetCombineUtility.MeshContainer> meshes = new List<MeshSubsetCombineUtility.MeshContainer>();
7291

73-
Array.Sort(gos, new SortGO());
92+
gos = SortGameObjectsForStaticbatching(gos, sorter ?? new StaticBatcherGOSorter());
7493

7594
foreach (GameObject go in gos)
7695
{
@@ -220,37 +239,24 @@ static private void MakeBatch(List<MeshSubsetCombineUtility.MeshContainer> meshe
220239
}
221240
}
222241

223-
internal class SortGO : IComparer
242+
public class StaticBatcherGOSorter
224243
{
225-
int IComparer.Compare(object a, object b)
226-
{
227-
if (a == b)
228-
return 0;
229-
230-
Renderer aRenderer = GetRenderer(a as GameObject);
231-
Renderer bRenderer = GetRenderer(b as GameObject);
232-
233-
int compare = GetMaterialId(aRenderer).CompareTo(GetMaterialId(bRenderer));
234-
if (compare == 0)
235-
compare = GetLightmapIndex(aRenderer).CompareTo(GetLightmapIndex(bRenderer));
236-
return compare;
237-
}
238-
239-
static private int GetMaterialId(Renderer renderer)
244+
public virtual long GetMaterialId(Renderer renderer)
240245
{
241246
if (renderer == null || renderer.sharedMaterial == null)
242247
return 0;
248+
243249
return renderer.sharedMaterial.GetInstanceID();
244250
}
245251

246-
static private int GetLightmapIndex(Renderer renderer)
252+
public int GetLightmapIndex(Renderer renderer)
247253
{
248254
if (renderer == null)
249255
return -1;
250256
return renderer.lightmapIndex;
251257
}
252258

253-
static private Renderer GetRenderer(GameObject go)
259+
public static Renderer GetRenderer(GameObject go)
254260
{
255261
if (go == null)
256262
return null;
@@ -260,6 +266,13 @@ static private Renderer GetRenderer(GameObject go)
260266

261267
return filter.GetComponent<Renderer>();
262268
}
269+
270+
public virtual long GetRendererId(Renderer renderer)
271+
{
272+
if (renderer == null)
273+
return -1;
274+
return renderer.GetInstanceID();
275+
}
263276
}
264277
}
265278
} // namespace UnityEngine

Runtime/Export/WSA/WSAApplication.bindings.cs

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

55
using System;
66
using UnityEngine.Bindings;
7+
using UnityEngine.Scripting;
78

89
namespace UnityEngine.WSA
910
{
@@ -49,12 +50,14 @@ public static string advertisingIdentifier
4950

5051
private static extern string GetAppArguments();
5152

53+
[RequiredByNativeCode]
5254
internal static void InvokeWindowSizeChangedEvent(int width, int height)
5355
{
5456
if (windowSizeChanged != null)
5557
windowSizeChanged.Invoke(width, height);
5658
}
5759

60+
[RequiredByNativeCode]
5861
internal static void InvokeWindowActivatedEvent(WindowActivationState state)
5962
{
6063
if (windowActivated != null) windowActivated.Invoke(state);

0 commit comments

Comments
 (0)