Skip to content

Commit 15a169e

Browse files
author
Unity Technologies
committed
Unity 2017.3.0f2 C# reference source code
1 parent b91ee44 commit 15a169e

30 files changed

+345
-140
lines changed

Editor/Mono/GUI/DockArea.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ protected override void OldOnGUI()
254254
// Call reset GUI state as first thing so GUI.color is correct when drawing window decoration.
255255
EditorGUIUtility.ResetGUIState();
256256

257+
// Exit if the window was destroyed after entering play mode or on domain-reload.
258+
if (window == null)
259+
return;
260+
257261
// Add CursorRects
258262
SplitView sp = parent as SplitView;
259263

Editor/Mono/Grid/GridSnapping.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ namespace UnityEditor
1010
internal static class GridSnapping
1111
{
1212
public static Func<Vector3, Vector3> snapPosition;
13+
public static Func<bool> activeFunc;
1314

1415
public static bool active
1516
{
16-
get { return snapPosition != null; }
17+
get { return (activeFunc != null ? activeFunc() : false); }
1718
}
1819

1920
public static Vector3 Snap(Vector3 position)
2021
{
21-
if (active)
22+
if (snapPosition != null)
2223
return snapPosition(position);
2324
return position;
2425
}

Editor/Mono/ImportSettings/SubstanceImporterInspector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ internal class SubstanceImporterInspector : Editor
2020
private const float kPreviewWidth = 60;
2121
private const float kPreviewHeight = kPreviewWidth + 16;
2222
private const int kMaxRows = 2;
23+
private const string kDeprecationWarning = "Built-in support for Substance Designer materials has been deprecated and will be removed in Unity 2018.1. To continue using Substance Designer materials in Unity 2018.1, you will need to install a suitable third-party external importer from the Asset Store.";
2324

2425
private static SubstanceArchive s_LastSelectedPackage = null;
2526
private static string s_CachedSelectedMaterialInstanceName = null;
@@ -181,6 +182,7 @@ public override void OnInspectorGUI()
181182
if (materialEditor)
182183
{
183184
materialEditor.DrawHeader();
185+
EditorGUILayout.HelpBox(kDeprecationWarning, MessageType.Warning);
184186
materialEditor.OnInspectorGUI();
185187
}
186188
}

Editor/Mono/Inspector/AssemblyDefinitionImporterInspector.cs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.IO;
88
using System.Linq;
9-
using UnityEditor.Scripting;
109
using UnityEditorInternal;
1110
using UnityEditor.Scripting.ScriptCompilation;
1211
using UnityEditor.Experimental.AssetImporters;
@@ -19,11 +18,28 @@ namespace UnityEditor
1918
[CanEditMultipleObjects]
2019
internal class AssemblyDefinitionImporterInspector : AssetImporterEditor
2120
{
21+
internal class Styles
22+
{
23+
public static readonly GUIContent name = EditorGUIUtility.TrTextContent("Name");
24+
public static readonly GUIContent references = EditorGUIUtility.TrTextContent("References");
25+
public static readonly GUIContent platforms = EditorGUIUtility.TrTextContent("Platforms");
26+
public static readonly GUIContent anyPlatform = EditorGUIUtility.TrTextContent("Any Platform");
27+
public static readonly GUIContent includePlatforms = EditorGUIUtility.TrTextContent("Include Platforms");
28+
public static readonly GUIContent excludePlatforms = EditorGUIUtility.TrTextContent("Exclude Platforms");
29+
public static readonly GUIContent selectAll = EditorGUIUtility.TrTextContent("Select all");
30+
public static readonly GUIContent deselectAll = EditorGUIUtility.TrTextContent("Deselect all");
31+
public static readonly GUIContent apply = EditorGUIUtility.TrTextContent("Apply");
32+
public static readonly GUIContent revert = EditorGUIUtility.TrTextContent("Revert");
33+
public static readonly GUIContent loadError = EditorGUIUtility.TrTextContent("Load error");
34+
}
35+
36+
GUIStyle m_TextStyle;
37+
2238
internal enum MixedBool : int
2339
{
2440
Mixed = -1,
25-
True = 0,
26-
False = 1
41+
False = 0,
42+
True = 1
2743
}
2844

2945
internal class AssemblyDefinitionReference
@@ -55,7 +71,6 @@ public string path
5571

5672
AssemblyDefintionState m_State;
5773
ReorderableList m_ReferencesList;
58-
GUIStyle m_TextStyle;
5974

6075
public override bool showImportedObject { get { return false; } }
6176

@@ -85,22 +100,22 @@ public override void OnInspectorGUI()
85100
using (new EditorGUI.DisabledScope(true))
86101
{
87102
var value = string.Join(", ", m_TargetStates.Select(t => t.name).ToArray());
88-
EditorGUILayout.TextField("Name", value, EditorStyles.textField);
103+
EditorGUILayout.TextField(Styles.name, value, EditorStyles.textField);
89104
}
90105
}
91106
else
92107
{
93-
m_State.name = EditorGUILayout.TextField("Name", m_State.name, EditorStyles.textField);
108+
m_State.name = EditorGUILayout.TextField(Styles.name, m_State.name, EditorStyles.textField);
94109
}
95110

96-
GUILayout.Label("References", EditorStyles.boldLabel);
111+
GUILayout.Label(Styles.references, EditorStyles.boldLabel);
97112
m_ReferencesList.DoLayoutList();
98113

99-
GUILayout.Label("Platforms", EditorStyles.boldLabel);
114+
GUILayout.Label(Styles.platforms, EditorStyles.boldLabel);
100115
EditorGUILayout.BeginVertical(GUI.skin.box);
101116

102117
var compatibleWithAnyPlatform = m_State.compatibleWithAnyPlatform;
103-
m_State.compatibleWithAnyPlatform = ToggleWithMixedValue("Any Platform", m_State.compatibleWithAnyPlatform);
118+
m_State.compatibleWithAnyPlatform = ToggleWithMixedValue(Styles.anyPlatform, m_State.compatibleWithAnyPlatform);
104119

105120
if (compatibleWithAnyPlatform == MixedBool.Mixed && m_State.compatibleWithAnyPlatform != MixedBool.Mixed)
106121
{
@@ -120,25 +135,25 @@ public override void OnInspectorGUI()
120135

121136
if (m_State.compatibleWithAnyPlatform != MixedBool.Mixed)
122137
{
123-
GUILayout.Label(m_State.compatibleWithAnyPlatform == MixedBool.False ? "Exclude Platforms" : "Include Platforms", EditorStyles.boldLabel);
138+
GUILayout.Label(m_State.compatibleWithAnyPlatform == MixedBool.True ? Styles.excludePlatforms : Styles.includePlatforms, EditorStyles.boldLabel);
124139

125140
for (int i = 0; i < platforms.Length; ++i)
126141
{
127-
m_State.platformCompatibility[i] = ToggleWithMixedValue(platforms[i].DisplayName, m_State.platformCompatibility[i]);
142+
m_State.platformCompatibility[i] = ToggleWithMixedValue(new GUIContent(platforms[i].DisplayName), m_State.platformCompatibility[i]);
128143
}
129144

130145
EditorGUILayout.Space();
131146

132147
GUILayout.BeginHorizontal();
133148

134-
if (GUILayout.Button("Select all"))
149+
if (GUILayout.Button(Styles.selectAll))
135150
{
136-
SetPlatformCompatibility(m_State, MixedBool.False);
151+
SetPlatformCompatibility(m_State, MixedBool.True);
137152
}
138153

139-
if (GUILayout.Button("Deselect all"))
154+
if (GUILayout.Button(Styles.deselectAll))
140155
{
141-
SetPlatformCompatibility(m_State, MixedBool.True);
156+
SetPlatformCompatibility(m_State, MixedBool.False);
142157
}
143158

144159
GUILayout.FlexibleSpace();
@@ -159,12 +174,12 @@ public override void OnInspectorGUI()
159174

160175
using (new EditorGUI.DisabledScope(!m_State.modified))
161176
{
162-
if (GUILayout.Button("Revert"))
177+
if (GUILayout.Button(Styles.revert))
163178
{
164179
LoadAssemblyDefinitionFiles();
165180
}
166181

167-
if (GUILayout.Button("Apply"))
182+
if (GUILayout.Button(Styles.apply))
168183
{
169184
SaveAndUpdateAssemblyDefinitionStates(m_State, m_TargetStates);
170185
}
@@ -208,15 +223,15 @@ static void UpdatePlatformCompatibility(MixedBool compatibleWithAnyPlatform, Ass
208223
}
209224
}
210225

211-
static MixedBool ToggleWithMixedValue(string title, MixedBool value)
226+
static MixedBool ToggleWithMixedValue(GUIContent title, MixedBool value)
212227
{
213228
EditorGUI.showMixedValue = value == MixedBool.Mixed;
214229

215230
EditorGUI.BeginChangeCheck();
216231

217-
bool newBoolValue = EditorGUILayout.Toggle(title, value == MixedBool.False);
232+
bool newBoolValue = EditorGUILayout.Toggle(title, value == MixedBool.True);
218233
if (EditorGUI.EndChangeCheck())
219-
return newBoolValue ? MixedBool.False : MixedBool.True;
234+
return newBoolValue ? MixedBool.True : MixedBool.False;
220235

221236
EditorGUI.showMixedValue = false;
222237
return value;
@@ -240,12 +255,12 @@ static void SetPlatformCompatibility(AssemblyDefintionState state, MixedBool com
240255

241256
static MixedBool InverseCompability(MixedBool compatibility)
242257
{
243-
if (compatibility == MixedBool.False)
244-
return MixedBool.True;
245-
246258
if (compatibility == MixedBool.True)
247259
return MixedBool.False;
248260

261+
if (compatibility == MixedBool.False)
262+
return MixedBool.True;
263+
249264
return MixedBool.Mixed;
250265
}
251266

@@ -254,7 +269,7 @@ void ShowLoadErrorExceptionGUI(Exception e)
254269
if (m_TextStyle == null)
255270
m_TextStyle = "ScriptText";
256271

257-
GUILayout.Label("Load Error", EditorStyles.boldLabel);
272+
GUILayout.Label(Styles.loadError, EditorStyles.boldLabel);
258273
Rect rect = GUILayoutUtility.GetRect(EditorGUIUtility.TempContent(e.Message), m_TextStyle);
259274
EditorGUI.HelpBox(rect, e.Message, MessageType.Error);
260275
}
@@ -383,7 +398,7 @@ static AssemblyDefintionState LoadAssemblyDefintionState(string path)
383398
throw new AssemblyDefinitionException(string.Format("Reference assembly definition file '{0}' not found", referencePath), path);
384399

385400
assemblyDefinitionFile.data = CustomScriptAssemblyData.FromJson(assemblyDefinitionFile.asset.text);
386-
assemblyDefinitionFile.displayValue = MixedBool.True;
401+
assemblyDefinitionFile.displayValue = MixedBool.False;
387402
state.references.Add(assemblyDefinitionFile);
388403
}
389404
catch (AssemblyDefinitionException e)
@@ -398,25 +413,25 @@ static AssemblyDefintionState LoadAssemblyDefintionState(string path)
398413
var platforms = Compilation.CompilationPipeline.GetAssemblyDefinitionPlatforms();
399414
state.platformCompatibility = new MixedBool[platforms.Length];
400415

401-
state.compatibleWithAnyPlatform = MixedBool.False;
416+
state.compatibleWithAnyPlatform = MixedBool.True;
402417
string[] dataPlatforms = null;
403418

404419
if (data.includePlatforms != null && data.includePlatforms.Length > 0)
405420
{
406-
state.compatibleWithAnyPlatform = MixedBool.True;
421+
state.compatibleWithAnyPlatform = MixedBool.False;
407422
dataPlatforms = data.includePlatforms;
408423
}
409424
else if (data.excludePlatforms != null && data.excludePlatforms.Length > 0)
410425
{
411-
state.compatibleWithAnyPlatform = MixedBool.False;
426+
state.compatibleWithAnyPlatform = MixedBool.True;
412427
dataPlatforms = data.excludePlatforms;
413428
}
414429

415430
if (dataPlatforms != null)
416431
foreach (var platform in dataPlatforms)
417432
{
418433
var platformIndex = GetPlatformIndex(platforms, platform);
419-
state.platformCompatibility[platformIndex] = MixedBool.False;
434+
state.platformCompatibility[platformIndex] = MixedBool.True;
420435
}
421436

422437
return state;
@@ -486,13 +501,13 @@ static void SaveAssemblyDefinitionState(AssemblyDefintionState state)
486501

487502
for (int i = 0; i < platforms.Length; ++i)
488503
{
489-
if (state.platformCompatibility[i] == MixedBool.False)
504+
if (state.platformCompatibility[i] == MixedBool.True)
490505
dataPlatforms.Add(platforms[i].Name);
491506
}
492507

493508
if (dataPlatforms.Any())
494509
{
495-
if (state.compatibleWithAnyPlatform == MixedBool.False)
510+
if (state.compatibleWithAnyPlatform == MixedBool.True)
496511
data.excludePlatforms = dataPlatforms.ToArray();
497512
else
498513
data.includePlatforms = dataPlatforms.ToArray();

Editor/Mono/Inspector/Editor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,14 +670,15 @@ static internal bool IsAppropriateFileOpenForEdit(UnityObject assetObject, out s
670670
if (assetObject == null)
671671
return false;
672672

673+
StatusQueryOptions opts = EditorUserSettings.allowAsyncStatusUpdate ? StatusQueryOptions.UseCachedAsync : StatusQueryOptions.UseCachedIfPossible;
673674
if (AssetDatabase.IsNativeAsset(assetObject))
674675
{
675-
if (!AssetDatabase.IsOpenForEdit(assetObject, out message, StatusQueryOptions.UseCachedIfPossible))
676+
if (!AssetDatabase.IsOpenForEdit(assetObject, out message, opts))
676677
return false;
677678
}
678679
else if (AssetDatabase.IsForeignAsset(assetObject))
679680
{
680-
if (!AssetDatabase.IsMetaFileOpenForEdit(assetObject, out message, StatusQueryOptions.UseCachedIfPossible))
681+
if (!AssetDatabase.IsMetaFileOpenForEdit(assetObject, out message, opts))
681682
return false;
682683
}
683684

Editor/Mono/Inspector/EditorSettingsInspector.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ public override void OnInspectorGUI()
316316
EditorUserSettings.WorkOffline = workOfflineNew;
317317
EditorApplication.RequestRepaintAllViews();
318318
}
319+
320+
EditorUserSettings.allowAsyncStatusUpdate = EditorGUILayout.Toggle("Allow Async Update", EditorUserSettings.allowAsyncStatusUpdate);
319321
}
320322

321323
if (Provider.hasCheckoutSupport)
@@ -525,6 +527,7 @@ private void DrawOverlayDescriptions()
525527
DrawOverlayDescription(Asset.States.Conflicted);
526528
DrawOverlayDescription(Asset.States.LockedLocal);
527529
DrawOverlayDescription(Asset.States.LockedRemote);
530+
DrawOverlayDescription(Asset.States.Updating);
528531
GUILayout.EndVertical();
529532
GUILayout.EndHorizontal();
530533
}

Editor/Mono/Inspector/MonoScriptInspector.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,30 @@ public override void OnInspectorGUI()
189189
{
190190
if (targets.Length == 1)
191191
{
192-
GUILayout.Label("Assembly Information", EditorStyles.boldLabel);
193-
194192
var assetPath = AssetDatabase.GetAssetPath(target);
195-
var assembly = Compilation.CompilationPipeline.GetAssemblyNameFromScriptPath(assetPath);
196-
EditorGUILayout.LabelField("Filename", assembly);
197-
198-
var assemblyDefinitionFile = Compilation.CompilationPipeline.GetAssemblyDefinitionFilePathFromScriptPath(assetPath);
193+
var assemblyName = Compilation.CompilationPipeline.GetAssemblyNameFromScriptPath(assetPath);
199194

200-
if (assemblyDefinitionFile != null)
195+
// assemblyName is null for MonoScript's inside assemblies.
196+
if (assemblyName != null)
201197
{
202-
var assemblyDefintionFileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(assemblyDefinitionFile);
198+
GUILayout.Label("Assembly Information", EditorStyles.boldLabel);
199+
200+
EditorGUILayout.LabelField("Filename", assemblyName);
201+
202+
var assemblyDefinitionFile = Compilation.CompilationPipeline.GetAssemblyDefinitionFilePathFromScriptPath(assetPath);
203203

204-
using (new EditorGUI.DisabledScope(true))
204+
if (assemblyDefinitionFile != null)
205205
{
206-
EditorGUILayout.ObjectField("Definition File", assemblyDefintionFileAsset, typeof(TextAsset), false);
206+
var assemblyDefintionFileAsset = AssetDatabase.LoadAssetAtPath<TextAsset>(assemblyDefinitionFile);
207+
208+
using (new EditorGUI.DisabledScope(true))
209+
{
210+
EditorGUILayout.ObjectField("Definition File", assemblyDefintionFileAsset, typeof(TextAsset), false);
211+
}
207212
}
208-
}
209213

210-
EditorGUILayout.Space();
214+
EditorGUILayout.Space();
215+
}
211216
}
212217

213218
base.OnInspectorGUI();

Editor/Mono/ObjectSelector.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,14 @@ internal void Show(UnityObject obj, Type requiredType, SerializedProperty proper
258258

259259
if (property != null)
260260
{
261-
ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType);
262-
// case 951876: built-in types do not actually have reflectable fields, so their object types must be extracted from the type string
263-
// this works because built-in types will only ever have serialized references to other built-in types, which this window's filter expects as unqualified names
264261
if (requiredType == null)
265-
m_RequiredType = s_MatchPPtrTypeName.Match(property.type).Groups[1].Value;
262+
{
263+
ScriptAttributeUtility.GetFieldInfoFromProperty(property, out requiredType);
264+
// case 951876: built-in types do not actually have reflectable fields, so their object types must be extracted from the type string
265+
// this works because built-in types will only ever have serialized references to other built-in types, which this window's filter expects as unqualified names
266+
if (requiredType == null)
267+
m_RequiredType = s_MatchPPtrTypeName.Match(property.type).Groups[1].Value;
268+
}
266269

267270
obj = property.objectReferenceValue;
268271
m_ObjectBeingEdited = property.serializedObject.targetObject;

0 commit comments

Comments
 (0)