Skip to content

Commit bbf1350

Browse files
author
Unity Technologies
committed
Unity 2019.3.0f5 C# reference source code
1 parent 013f129 commit bbf1350

File tree

54 files changed

+591
-275
lines changed

Some content is hidden

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

54 files changed

+591
-275
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,6 @@ public static class SpriteAtlasExtensions
9696
extern internal static Texture2D[] GetPreviewAlphaTextures(this SpriteAtlas spriteAtlas);
9797
extern internal static TextureFormat GetTextureFormat(this SpriteAtlas spriteAtlas, BuildTarget target);
9898
extern internal static Sprite[] GetPackedSprites(this SpriteAtlas spriteAtlas);
99+
extern internal static Hash128 GetStoredHash(this SpriteAtlas spriteAtlas);
99100
}
100101
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Unity C# reference source
2+
// Copyright (c) Unity Technologies. For terms of use, see
3+
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
4+
5+
using UnityEngine;
6+
7+
namespace UnityEditor
8+
{
9+
struct CameraProjectionCache
10+
{
11+
Matrix4x4 worldToClip;
12+
Rect viewport;
13+
float screen;
14+
15+
public CameraProjectionCache(Camera camera, float screenHeight)
16+
{
17+
worldToClip = camera.projectionMatrix * camera.worldToCameraMatrix;
18+
viewport = camera.pixelRect;
19+
screen = screenHeight;
20+
}
21+
22+
public Vector2 WorldToScreenPoint(Vector3 point)
23+
{
24+
Vector3 clip = worldToClip.MultiplyPoint(point);
25+
26+
return new Vector2(
27+
viewport.x + (1.0f + clip.x) * viewport.width * 0.5f,
28+
viewport.y + (1.0f + clip.y) * viewport.height * 0.5f);
29+
}
30+
31+
public Vector2 WorldToGUIPoint(Vector3 point)
32+
{
33+
return ScreenToGUIPoint(WorldToScreenPoint(point));
34+
}
35+
36+
public Vector2 GUIToScreenPoint(Vector2 point)
37+
{
38+
var pixels = EditorGUIUtility.PointsToPixels(point);
39+
pixels.y = screen - pixels.y;
40+
return pixels;
41+
}
42+
43+
public Vector2 ScreenToGUIPoint(Vector2 point)
44+
{
45+
point.y = screen - point.y;
46+
return GUIClip.Clip(EditorGUIUtility.PixelsToPoints(point));
47+
}
48+
}
49+
}

Editor/Mono/EditorGUI.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,9 +1682,7 @@ internal static string ToolbarSearchField(int id, Rect position, string text, bo
16821682
if (Event.current.type == EventType.MouseUp && buttonRect.Contains(Event.current.mousePosition))
16831683
{
16841684
s_RecycledEditor.text = text = "";
1685-
GUIUtility.keyboardControl = 0;
16861685
GUI.changed = true;
1687-
Event.current.Use();
16881686
}
16891687
text = DoTextField(s_RecycledEditor, id, textRect, text, showWithPopupArrow ? EditorStyles.toolbarSearchFieldPopup : EditorStyles.toolbarSearchField, null, out dummy, false, false, false);
16901688
GUI.Button(buttonRect, GUIContent.none,

Editor/Mono/GUI/TreeView/GameObjectTreeViewGUI.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ override protected void DrawItemBackground(Rect rect, int row, TreeViewItem item
308308
{
309309
var gameObject = (GameObject)goItem.objectPPTR;
310310
if (gameObject != null && SubSceneGUI.IsSubSceneHeader(gameObject))
311-
SubSceneGUI.DrawSubSceneHeaderBackground(rect, gameObject);
311+
{
312+
SubSceneGUI.DrawSubSceneHeaderBackground(rect, k_BaseIndent, k_IndentWidth, gameObject);
313+
}
312314
}
313315
}
314316

@@ -359,7 +361,9 @@ protected override void OnAdditionalGUI(Rect rect, int row, TreeViewItem item, b
359361
{
360362
m_ContentRectRight = PrefabModeButton(goItem, rect);
361363
if (SubSceneGUI.IsUsingSubScenes() && !showingSearchResults)
362-
SubSceneGUI.DrawVerticalLine(rect, (GameObject)goItem.objectPPTR);
364+
{
365+
SubSceneGUI.DrawVerticalLine(rect, k_BaseIndent, k_IndentWidth, (GameObject)goItem.objectPPTR);
366+
}
363367
}
364368

365369
if (SceneHierarchy.s_Debug)

Editor/Mono/GUI/TreeView/SubSceneGUI.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static class SubSceneGUI
1414
static Dictionary<Scene, SceneHierarchyHooks.SubSceneInfo> m_SceneToSubSceneMap = new Dictionary<Scene, SceneHierarchyHooks.SubSceneInfo>();
1515
static Dictionary<SceneAsset, SceneHierarchyHooks.SubSceneInfo> m_SceneAssetToSubSceneMap = new Dictionary<SceneAsset, SceneHierarchyHooks.SubSceneInfo>();
1616
const int kMaxSubSceneIterations = 100;
17+
static float s_HalfFoldoutWidth = 6f;
18+
static float s_SubSceneHeaderIndentAdjustment = -2f;
1719

1820
internal static void FetchSubSceneInfo()
1921
{
@@ -215,9 +217,9 @@ internal static Scene GetSubScene(GameObject gameObject)
215217
return default(Scene);
216218
}
217219

218-
internal static void DrawSubSceneHeaderBackground(Rect rect, GameObject gameObject)
220+
internal static void DrawSubSceneHeaderBackground(Rect rect, float baseIndent, float indentWidth, GameObject gameObject)
219221
{
220-
float indent = CalcIndentOfSubSceneHeader(gameObject);
222+
float indent = CalcIndentOfSubSceneHeader(gameObject, baseIndent, indentWidth);
221223
if (indent < 0)
222224
{
223225
Debug.LogError("Only call DrawSubSceneHeaderBackground if IsSubSceneHeader() is true");
@@ -232,7 +234,7 @@ internal static void DrawSubSceneHeaderBackground(Rect rect, GameObject gameObje
232234
GUI.color = oldColor;
233235
}
234236

235-
static float CalcIndentOfSubSceneHeader(GameObject gameObject)
237+
static float CalcIndentOfSubSceneHeader(GameObject gameObject, float baseIndent, float indentWidth)
236238
{
237239
SceneHierarchyHooks.SubSceneInfo subSceneInfo;
238240
if (gameObject == null || !m_SubSceneHeadersMap.TryGetValue(gameObject, out subSceneInfo))
@@ -241,9 +243,7 @@ static float CalcIndentOfSubSceneHeader(GameObject gameObject)
241243
int hierarchyDepth = CalculateHierarchyDepthOfSubScene(subSceneInfo);
242244
if (hierarchyDepth > 0)
243245
{
244-
float indentWidth = 14f;
245-
float indent = hierarchyDepth * indentWidth;
246-
return indent;
246+
return baseIndent + s_SubSceneHeaderIndentAdjustment + (hierarchyDepth * indentWidth);
247247
}
248248
return -1f;
249249
}
@@ -252,7 +252,7 @@ static float CalcIndentOfSubSceneHeader(GameObject gameObject)
252252
static SceneHierarchyHooks.SubSceneInfo s_LastSubSceneInfo;
253253
static Rect s_LastRectCalculated;
254254

255-
internal static Rect GetRectForVerticalLine(Rect rowRect, Scene scene)
255+
internal static Rect GetRectForVerticalLine(Rect rowRect, float baseIndent, float indentWidth, Scene scene)
256256
{
257257
// Fast path: reuse last rect if same scene
258258
if (s_LastSubSceneInfo.isValid && s_LastSubSceneInfo.scene == scene)
@@ -269,38 +269,40 @@ internal static Rect GetRectForVerticalLine(Rect rowRect, Scene scene)
269269
if (s_LastSubSceneInfo.color.a == 0)
270270
return new Rect();
271271

272-
float indent = CalcIndentOfVerticalLine(s_LastSubSceneInfo);
272+
float indent = CalcIndentOfVerticalLine(s_LastSubSceneInfo, baseIndent, indentWidth);
273273
if (indent < 0)
274274
return new Rect();
275275

276276
s_LastRectCalculated = rowRect;
277-
s_LastRectCalculated.x += indent;
277+
s_LastRectCalculated.x += indent;
278278
s_LastRectCalculated.width = 1;
279279

280280
return s_LastRectCalculated;
281281
}
282282

283-
internal static void DrawVerticalLine(Rect rowRect, GameObject gameObject)
283+
internal static void DrawVerticalLine(Rect rowRect, float baseIndent, float indentWidth, GameObject gameObject)
284284
{
285285
if (gameObject == null)
286286
return;
287287

288288
if (Event.current.type == EventType.Repaint)
289289
{
290-
Rect lineRect = GetRectForVerticalLine(rowRect, gameObject.scene);
290+
Scene scene = gameObject.scene;
291+
Rect lineRect = GetRectForVerticalLine(rowRect, baseIndent, indentWidth, scene);
291292
if (lineRect.width > 0f)
292-
EditorGUI.DrawRect(lineRect, GetColorForSubScene(gameObject.scene));
293+
{
294+
Color color = GetColorForSubScene(scene);
295+
GUI.DrawTexture(lineRect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 1, color, color, color, color, Vector4.zero, Vector4.zero, false);
296+
}
293297
}
294298
}
295299

296-
static float CalcIndentOfVerticalLine(SceneHierarchyHooks.SubSceneInfo subSceneInfo)
300+
static float CalcIndentOfVerticalLine(SceneHierarchyHooks.SubSceneInfo subSceneInfo, float baseIndent, float indentWidth)
297301
{
298302
int hierarchyDepth = CalculateHierarchyDepthOfSubScene(subSceneInfo);
299303
if (hierarchyDepth > 0)
300304
{
301-
float indentWidth = 14f;
302-
float indent = hierarchyDepth * indentWidth;
303-
return indent;
305+
return baseIndent + hierarchyDepth * indentWidth + s_HalfFoldoutWidth;
304306
}
305307
return -1f;
306308
}

Editor/Mono/GUID.bindings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,8 @@ public override string ToString()
134134

135135
[NativeMethod(Name = "GenerateGUID", IsFreeFunction = true)]
136136
extern private static GUID GenerateGUIDInternal();
137+
138+
[NativeMethod(Name = "CreateGUIDFromSInt64", IsFreeFunction = true)]
139+
extern internal static GUID CreateGUIDFromSInt64(long value);
137140
}
138141
}

Editor/Mono/HandleUtility.cs

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public static Vector3 ClosestPointToDisc(Vector3 center, Vector3 normal, float r
334334
public static float DistanceToArc(Vector3 center, Vector3 normal, Vector3 from, float angle, float radius)
335335
{
336336
Handles.SetDiscSectionPoints(m_ArcPointsBuffer, center, normal, from, angle, radius);
337-
return DistanceToPolyLineOnPlane(m_ArcPointsBuffer, center, normal);
337+
return DistanceToPolyLine(m_ArcPointsBuffer);
338338
}
339339

340340
// Get the nearest 3D point.
@@ -347,64 +347,25 @@ public static Vector3 ClosestPointToArc(Vector3 center, Vector3 normal, Vector3
347347
// Pixel distance from mouse pointer to a polyline.
348348
public static float DistanceToPolyLine(params Vector3[] points)
349349
{
350-
Camera cam = Camera.current;
351-
Matrix4x4 handlesMatrix = Handles.matrix;
352-
float screenHeight = Screen.height;
350+
Matrix4x4 handleMatrix = Handles.matrix;
351+
CameraProjectionCache cam = new CameraProjectionCache(Camera.current, Screen.height);
352+
Vector2 mouse = Event.current.mousePosition;
353353

354-
Vector2 point = Event.current.mousePosition;
355-
Vector3 p1 = WorldToGUIPointWithDepth(points[0], cam, handlesMatrix, screenHeight);
356-
Vector3 p2 = WorldToGUIPointWithDepth(points[1], cam, handlesMatrix, screenHeight);
357-
float dist = DistanceToLineInternal(point, p1, p2);
354+
Vector2 p1 = cam.WorldToGUIPoint(handleMatrix.MultiplyPoint3x4(points[0]));
355+
Vector2 p2 = cam.WorldToGUIPoint(handleMatrix.MultiplyPoint3x4(points[1]));
356+
float dist = DistanceToLineInternal(mouse, p1, p2);
358357

359358
for (int i = 2; i < points.Length; i++)
360359
{
361360
p1 = p2;
362-
p2 = WorldToGUIPointWithDepth(points[i], cam, handlesMatrix, screenHeight);
363-
364-
float d = DistanceToLineInternal(point, p1, p2);
361+
p2 = cam.WorldToGUIPoint(handleMatrix.MultiplyPoint3x4(points[i]));
362+
float d = DistanceToLineInternal(mouse, p1, p2);
365363
if (d < dist)
366364
dist = d;
367365
}
368366
return dist;
369367
}
370368

371-
// Pixel distance from mouse pointer to a polyline on a 2D plane.
372-
internal static float DistanceToPolyLineOnPlane(Vector3[] points, Vector3 center, Vector3 normal)
373-
{
374-
Plane p = new Plane(normal, center);
375-
376-
Vector2 point = Event.current.mousePosition;
377-
Ray r = GUIPointToWorldRay(point);
378-
379-
float enter;
380-
if (!p.Raycast(r, out enter))
381-
return DistanceToPolyLine(points);
382-
383-
Vector3 intersect = r.GetPoint(enter);
384-
385-
Vector3 p1 = points[0];
386-
Vector3 p2 = points[1];
387-
float dist = DistanceToLineInternal(intersect, p1, p2);
388-
389-
Vector3 s1 = Vector3.zero, s2 = Vector3.zero;
390-
391-
for (int i = 2; i < points.Length; i++)
392-
{
393-
p1 = p2;
394-
p2 = points[i];
395-
396-
float d = DistanceToLineInternal(intersect, p1, p2);
397-
if (d < dist)
398-
{
399-
dist = d;
400-
s1 = p1;
401-
s2 = p2;
402-
}
403-
}
404-
405-
return DistanceToLineInternal(point, WorldToGUIPoint(s1), WorldToGUIPoint(s2));
406-
}
407-
408369
// Get the nearest 3D point.
409370
public static Vector3 ClosestPointToPolyLine(params Vector3[] vertices)
410371
{

0 commit comments

Comments
 (0)