Skip to content

Commit 1fea95a

Browse files
author
Unity Technologies
committed
Unity 2017.4.3f1 C# reference source code
1 parent 5945c7f commit 1fea95a

File tree

9 files changed

+98
-27
lines changed

9 files changed

+98
-27
lines changed

Editor/Mono/BuildPlayerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ private static void GUIBuildButtons(IBuildWindowExtension buildWindowExtension,
865865
GUI.enabled = enableBuildButton;
866866
if (GUILayout.Button(buildButton, GUILayout.Width(Styles.kButtonWidth)))
867867
{
868-
CallBuildMethods(true, BuildOptions.ShowBuiltPlayer | BuildOptions.StrictMode);
868+
CallBuildMethods(true, BuildOptions.ShowBuiltPlayer);
869869
GUIUtility.ExitGUI();
870870
}
871871
// Build and Run button

Editor/Mono/CustomEditorAttributes.cs

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace UnityEditor
1414
/// Remap Viewed type to inspector type
1515
internal class CustomEditorAttributes
1616
{
17-
private static readonly List<MonoEditorType> kSCustomEditors = new List<MonoEditorType>();
18-
private static readonly List<MonoEditorType> kSCustomMultiEditors = new List<MonoEditorType>();
17+
private static readonly Dictionary<Type, List<MonoEditorType>> kSCustomEditors = new Dictionary<Type, List<MonoEditorType>>();
18+
private static readonly Dictionary<Type, List<MonoEditorType>> kSCustomMultiEditors = new Dictionary<Type, List<MonoEditorType>>();
1919
private static bool s_Initialized;
2020

2121
class MonoEditorType
@@ -32,7 +32,8 @@ internal static Type FindCustomEditorType(UnityEngine.Object o, bool multiEdit)
3232
return FindCustomEditorTypeByType(o.GetType(), multiEdit);
3333
}
3434

35-
internal static Type FindCustomEditorTypeByType(System.Type type, bool multiEdit)
35+
private static List<MonoEditorType> s_SearchCache = new List<MonoEditorType>();
36+
internal static Type FindCustomEditorTypeByType(Type type, bool multiEdit)
3637
{
3738
if (!s_Initialized)
3839
{
@@ -51,28 +52,60 @@ internal static Type FindCustomEditorTypeByType(System.Type type, bool multiEdit
5152
{
5253
for (Type inspected = type; inspected != null; inspected = inspected.BaseType)
5354
{
54-
// Capture for closure
55-
var inspected1 = inspected;
56-
var pass1 = pass;
55+
List<MonoEditorType> foundEditors;
56+
if (!editors.TryGetValue(inspected, out foundEditors))
57+
{
58+
if (!inspected.IsGenericType)
59+
continue;
60+
61+
inspected = inspected.GetGenericTypeDefinition();
62+
63+
if (!editors.TryGetValue(inspected, out foundEditors))
64+
continue;
65+
}
66+
67+
s_SearchCache.Clear();
68+
foreach (var result in foundEditors)
69+
{
70+
if (!IsAppropriateEditor(result, inspected, type != inspected, pass == 1))
71+
continue;
72+
73+
s_SearchCache.Add(result);
74+
}
5775

58-
var validEditors = editors.Where(x => IsAppropriateEditor(x, inspected1, type != inspected1, pass1 == 1));
76+
Type toUse = null;
5977

6078
// we have a render pipeline...
6179
// we need to select the one with the correct RP asset
6280
if (GraphicsSettings.renderPipelineAsset != null)
6381
{
6482
var rpType = GraphicsSettings.renderPipelineAsset.GetType();
65-
foreach (var editor in validEditors)
83+
foreach (var editor in s_SearchCache)
6684
{
6785
if (editor.m_RenderPipelineType == rpType)
68-
return editor.m_InspectorType;
86+
{
87+
toUse = editor.m_InspectorType;
88+
break;
89+
}
6990
}
7091
}
7192

7293
// no RP, fallback!
73-
var found = validEditors.FirstOrDefault(x => x.m_RenderPipelineType == null);
74-
if (found != null)
75-
return found.m_InspectorType;
94+
if (toUse == null)
95+
{
96+
foreach (var editor in s_SearchCache)
97+
{
98+
if (editor.m_RenderPipelineType == null)
99+
{
100+
toUse = editor.m_InspectorType;
101+
break;
102+
}
103+
}
104+
}
105+
106+
s_SearchCache.Clear();
107+
if (toUse != null)
108+
return toUse;
76109
}
77110
}
78111
return null;
@@ -106,10 +139,13 @@ internal static void Rebuild(Assembly assembly)
106139
{
107140
// Suppress a warning on TweakMode, we did this bad in the default project folder
108141
// and it's going to be too hard for customers to figure out how to fix it and also quite pointless.
109-
if (type.FullName == "TweakMode" && type.IsEnum && inspectAttr.m_InspectedType.FullName == "BloomAndFlares")
142+
if (type.FullName == "TweakMode" && type.IsEnum &&
143+
inspectAttr.m_InspectedType.FullName == "BloomAndFlares")
110144
continue;
111145

112-
Debug.LogWarning(type.Name + " uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
146+
Debug.LogWarning(
147+
type.Name +
148+
" uses the CustomEditor attribute but does not inherit from Editor.\nYou must inherit from Editor. See the Editor class script documentation.");
113149
}
114150
else
115151
{
@@ -120,9 +156,25 @@ internal static void Rebuild(Assembly assembly)
120156
var attr = inspectAttr as CustomEditorForRenderPipelineAttribute;
121157
if (attr != null)
122158
t.m_RenderPipelineType = attr.renderPipelineType;
123-
kSCustomEditors.Add(t);
159+
160+
List<MonoEditorType> editors;
161+
if (!kSCustomEditors.TryGetValue(inspectAttr.m_InspectedType, out editors))
162+
{
163+
editors = new List<MonoEditorType>();
164+
kSCustomEditors[inspectAttr.m_InspectedType] = editors;
165+
}
166+
editors.Add(t);
167+
124168
if (type.GetCustomAttributes(typeof(CanEditMultipleObjects), false).Length > 0)
125-
kSCustomMultiEditors.Add(t);
169+
{
170+
List<MonoEditorType> multiEditors;
171+
if (!kSCustomMultiEditors.TryGetValue(inspectAttr.m_InspectedType, out multiEditors))
172+
{
173+
multiEditors = new List<MonoEditorType>();
174+
kSCustomMultiEditors[inspectAttr.m_InspectedType] = multiEditors;
175+
}
176+
multiEditors.Add(t);
177+
}
126178
}
127179
}
128180
}

Editor/Mono/EditorGUI.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public sealed partial class EditorGUI
9898
internal const int kInspTitlebarIconWidth = 16;
9999
internal const int kWindowToolbarHeight = 17;
100100
private static string kEnabledPropertyName = "m_Enabled";
101+
private const string k_MultiEditValueString = "<multi>";
101102

102103
private static float[] s_Vector2Floats = {0, 0};
103104
private static int[] s_Vector2Ints = { 0, 0 };
@@ -477,7 +478,10 @@ public string OnGUI(int id, string value, out bool changed)
477478
m_CommitCommandSentOnLostFocus = false;
478479
// Only set changed to true if the value has actually changed. Otherwise EditorGUI.EndChangeCheck will report false positives,
479480
// which could for example cause unwanted undo's to be registered (in the case of e.g. editing terrain resolution, this can cause several seconds of delay)
480-
changed = value != controlThatHadFocusValue;
481+
if (!showMixedValue || controlThatHadFocusValue != k_MultiEditValueString)
482+
changed = value != controlThatHadFocusValue;
483+
else
484+
changed = false;
481485
evt.Use();
482486
messageControl = 0;
483487
return controlThatHadFocusValue;
@@ -666,7 +670,7 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
666670

667671
if (showMixedValue)
668672
{
669-
text = string.Empty;
673+
text = k_MultiEditValueString;
670674
}
671675

672676
// If we have keyboard control and our window have focus, we need to sync up the editor.
@@ -1005,7 +1009,10 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
10051009
string drawText;
10061010
if (editor.IsEditingControl(id))
10071011
{
1008-
drawText = passwordField ? "".PadRight(editor.text.Length, '*') : editor.text;
1012+
if (showMixedValue && editor.text == k_MultiEditValueString)
1013+
drawText = string.Empty;
1014+
else
1015+
drawText = passwordField ? "".PadRight(editor.text.Length, '*') : editor.text;
10091016
}
10101017
else if (showMixedValue)
10111018
{

Editor/Mono/Inspector/AvatarPreview.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public void DoRenderPreview(Rect previewRect, GUIStyle background)
648648
mainFloorAlpha = is2D ? 0.5f : 1;
649649
}
650650

651-
Quaternion floorRot = is2D ? Quaternion.Euler(0, -90, 90) : Quaternion.identity;
651+
Quaternion floorRot = is2D ? Quaternion.Euler(-90, 0, 0) : Quaternion.identity;
652652
Vector3 floorPos = new Vector3(0, 0, 0);
653653
floorPos = m_ReferenceInstance.transform.position;
654654
floorPos.y = mainFloorHeight;
@@ -669,6 +669,9 @@ public void DoRenderPreview(Rect previewRect, GUIStyle background)
669669
previewUtility.camera.transform.position = camPos;
670670
previewUtility.camera.transform.rotation = camRot;
671671

672+
// Texture offset - negative in order to compensate the floor movement.
673+
Vector2 textureOffset = -new Vector2(floorPos.x, is2D ? floorPos.y : floorPos.z);
674+
672675
if (is2D)
673676
previewUtility.camera.orthographicSize = 2.0f * m_ZoomFactor;
674677
// Render main floor
@@ -679,7 +682,7 @@ public void DoRenderPreview(Rect previewRect, GUIStyle background)
679682
Material mat = m_FloorMaterial;
680683
Matrix4x4 matrix = Matrix4x4.TRS(floorPos, floorRot, Vector3.one * kFloorScale * m_AvatarScale);
681684

682-
mat.mainTextureOffset = -new Vector2(floorPos.x, floorPos.z) * kFloorScale * 0.08f * (1.0f / m_AvatarScale);
685+
mat.mainTextureOffset = textureOffset * kFloorScale * 0.08f * (1.0f / m_AvatarScale);
683686
mat.SetTexture("_ShadowTexture", shadowMap);
684687
mat.SetMatrix("_ShadowTextureMatrix", shadowMatrix);
685688
mat.SetVector("_Alphas", new Vector4(kFloorAlpha * mainFloorAlpha, kFloorShadowAlpha * mainFloorAlpha, 0, 0));
@@ -698,7 +701,7 @@ public void DoRenderPreview(Rect previewRect, GUIStyle background)
698701
floorPos.y = floorHeight;
699702

700703
Material mat = m_FloorMaterialSmall;
701-
mat.mainTextureOffset = -new Vector2(floorPos.x, floorPos.z) * kFloorScaleSmall * 0.08f;
704+
mat.mainTextureOffset = textureOffset * kFloorScaleSmall * 0.08f;
702705
mat.SetTexture("_ShadowTexture", shadowMap);
703706
mat.SetMatrix("_ShadowTextureMatrix", shadowMatrix);
704707
mat.SetVector("_Alphas", new Vector4(kFloorAlpha * floorAlpha, 0, 0, 0));

Editor/Mono/Inspector/CanvasEditor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ void OnDisable()
124124

125125
private void AllRootCanvases()
126126
{
127+
if (PlayerSettings.virtualRealitySupported && (m_RenderMode.enumValueIndex == (int)RenderMode.ScreenSpaceOverlay))
128+
{
129+
EditorGUILayout.HelpBox("Using a render mode of ScreenSpaceOverlay while VR is enabled is not recommended for an optimal VR experience", MessageType.Warning);
130+
}
131+
127132
EditorGUILayout.PropertyField(m_RenderMode);
128133

129134
m_OverlayMode.target = m_RenderMode.intValue == 0;

Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ private ApiCompatibilityLevel[] GetAvailableApiCompatibilityLevels(BuildTargetGr
20042004
if (EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest)
20052005
return only_4_x_profiles;
20062006

2007-
if (activeBuildTargetGroup == BuildTargetGroup.WSA || activeBuildTargetGroup == BuildTargetGroup.XboxOne)
2007+
if (activeBuildTargetGroup == BuildTargetGroup.WSA)
20082008
return allProfiles;
20092009

20102010
return only_2_0_profiles;

Editor/Src/CloudServicesSettings/PackageUtils/ScriptBindings/PackageUtils.bindings.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ internal class PackageUtils
2222
private Dictionary<string, UpmPackageInfo> m_outdatedPackages = new Dictionary<string, UpmPackageInfo>();
2323

2424
extern private static bool WaitForPackageManagerOperation(long operationId, string progressBarText);
25+
extern private static bool IsPackageManagerDisabled();
2526

2627
public static PackageUtils instance
2728
{
@@ -38,6 +39,9 @@ static PackageUtils()
3839

3940
public void RetrievePackageInfo()
4041
{
42+
if (IsPackageManagerDisabled())
43+
return;
44+
4145
if (NativeClient.List(out m_listOperationId) == NativeClient.StatusCode.Error)
4246
{
4347
Debug.LogWarning("Failed to call list packages!");

README.md

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

artifacts/generated/common/runtime/RectTransformBindings.gen.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ public void GetWorldCorners(Vector3[] fourCornersArray)
257257
}
258258

259259
GetLocalCorners(fourCornersArray);
260-
Transform wt = transform;
261260

261+
Matrix4x4 mat = transform.localToWorldMatrix;
262262
for (int i = 0; i < 4; i++)
263-
fourCornersArray[i] = wt.TransformPoint(fourCornersArray[i]);
263+
fourCornersArray[i] = mat.MultiplyPoint(fourCornersArray[i]);
264264
}
265265

266266

0 commit comments

Comments
 (0)