Skip to content

Commit bad6201

Browse files
author
Unity Technologies
committed
Unity 2018.4.1f1 C# reference source code
1 parent 8676800 commit bad6201

9 files changed

Lines changed: 120 additions & 37 deletions

File tree

Editor/Mono/PointEditor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ public static bool SelectPoints(IEditablePoint points, Transform cloudTransform,
175175
// Go over all the points and add them if they are inside the rect
176176
for (int i = 0; i < points.Count; i++)
177177
{
178-
var point = HandleUtility.WorldToGUIPoint(points.GetPosition(i));
179-
if (r.Contains(point))
178+
var point = HandleUtility.WorldToGUIPointWithDepth(points.GetPosition(i));
179+
180+
// the point has to be within the selection and in front of the camera
181+
if (r.Contains(point) && point.z > 0.0f)
180182
{
181183
if (EditorGUI.actionKey)
182184
{

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/PrefabStageUtility.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ static GameObject FindPrefabRoot(string prefabAssetPath, GameObject[] environmen
197197
// Fast path (most common): check all roots first
198198
foreach (var prefabRoot in rootsAfterLoadingPrefab)
199199
{
200+
if (prefabRoot == null)
201+
continue;
202+
200203
UInt64 id = GetPrefabOrVariantFileID(prefabRoot);
201204
if (id == prefabAssetRootFileID)
202205
return prefabRoot;
@@ -205,6 +208,9 @@ static GameObject FindPrefabRoot(string prefabAssetPath, GameObject[] environmen
205208
// If not found in list of roots then check descendants
206209
foreach (var root in rootsAfterLoadingPrefab)
207210
{
211+
if (root == null)
212+
continue;
213+
208214
var prefabRoot = FindFirstGameObjectThatMatchesFileID(root.transform, prefabAssetRootFileID);
209215
if (prefabRoot != null)
210216
return prefabRoot;

Editor/Mono/Scripting/APIUpdater/APIUpdaterAssemblyHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public static bool DoesAssemblyRequireUpgrade(string assemblyFullPath)
123123

124124
private static string AssemblySearchPathArgument()
125125
{
126-
var searchPath = Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Managed") + ","
126+
var searchPath = "+" + Path.Combine(MonoInstallationFinder.GetFrameWorksFolder(), "Managed") + ","
127127
+ "+" + Path.Combine(EditorApplication.applicationContentsPath, "UnityExtensions/Unity") + ","
128128
+ "+" + Application.dataPath;
129129

Modules/CloudServicesSettingsEditor/CrashReporting/Managed/CrashReporting.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static string ServiceBaseUrl
2121
{
2222
get
2323
{
24-
string configUrl = UnityConnect.instance.GetConfigurationURL(CloudConfigUrl.CloudPerfEvents);
24+
string configUrl = CrashReportingSettings.GetEventUrl();
2525
if (!string.IsNullOrEmpty(configUrl))
2626
{
2727
return configUrl;
@@ -70,6 +70,8 @@ public static string GetUsymUploadAuthToken()
7070
return environmentValue;
7171
}
7272

73+
CrashReportingSettings.EnsureConnectReady();
74+
7375
string accessToken = UnityConnect.instance.GetAccessToken();
7476
if (string.IsNullOrEmpty(accessToken))
7577
{

Modules/CloudServicesSettingsEditor/CrashReporting/ScriptBindings/CrashReportingSettings.bindings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public static partial class CrashReportingSettings
2525

2626
internal static extern string GetEventUrl();
2727
internal static extern void SetEventUrl(string eventUrl);
28+
29+
internal static extern void EnsureConnectReady();
2830
}
2931

3032
}

Modules/TerrainEditor/TerrainInspector.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -855,11 +855,23 @@ void SaveInspectorSettings()
855855

856856
public void OnEnable()
857857
{
858-
// Acquire active inspector ownership if there is no other inspector active.
859-
if (s_activeTerrainInspector == 0)
860-
s_activeTerrainInspector = GetInstanceID();
861-
if (s_activeTerrainInspectorInstance == null)
862-
s_activeTerrainInspectorInstance = this;
858+
if (s_activeTerrainInspector == 0 || s_activeTerrainInspectorInstance == null)
859+
{
860+
var inspectors = InspectorWindow.GetInspectors();
861+
foreach (var inspector in inspectors)
862+
{
863+
var editors = inspector.tracker.activeEditors;
864+
foreach (var editor in editors)
865+
{
866+
if (editor == this)
867+
{
868+
// Acquire active inspector ownership if there is no other inspector active.
869+
s_activeTerrainInspector = GetInstanceID();
870+
s_activeTerrainInspectorInstance = this;
871+
}
872+
}
873+
}
874+
}
863875

864876
m_ShowBuiltinSpecularSettings.valueChanged.AddListener(Repaint);
865877
m_ShowCustomMaterialSettings.valueChanged.AddListener(Repaint);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Unity 2018.4.0f1 C# reference source code
1+
## Unity 2018.4.1f1 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

0 commit comments

Comments
 (0)