Skip to content

Commit 487226b

Browse files
author
Unity Technologies
committed
Unity 2019.3.0b6 C# reference source code
1 parent a953895 commit 487226b

File tree

54 files changed

+647
-271
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

+647
-271
lines changed

Editor/Mono/Annotation/AnnotationWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static public void IconChanged()
143143
float GetTopSectionHeight()
144144
{
145145
const int numberOfControls = 3;
146-
return EditorGUI.kSingleLineHeight * numberOfControls + EditorGUI.kControlVerticalSpacing * numberOfControls;
146+
return EditorGUI.kSingleLineHeight * numberOfControls + EditorGUI.kControlVerticalSpacing * (numberOfControls - 1) + EditorStyles.inspectorBig.padding.bottom;
147147
}
148148

149149
void OnEnable()
@@ -536,7 +536,7 @@ void DrawListHeader(string header, List<AInfo> elements, Rect rect, ref bool hea
536536

537537
// Column headers
538538
Rect columnRect = rect;
539-
columnRect.y -= gizmoTextSize.y - 3;
539+
columnRect.y -= gizmoTextSize.y + 3;
540540
columnRect.x = rect.width - gizmoTextRightAlign;
541541
GUI.Label(columnRect, gizmoText, m_Styles.columnHeaderStyle);
542542

Editor/Mono/CSPreProcess.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private static ProcessStartInfo GetJamStartInfo(bool includeModules)
3535
moduleArgs.Append(" ").Append(target);
3636
}
3737

38-
return new ProcessStartInfo
38+
var psi = new ProcessStartInfo
3939
{
4040
WorkingDirectory = Unsupported.GetBaseUnityDeveloperFolder(),
4141
RedirectStandardOutput = true,
@@ -44,6 +44,18 @@ private static ProcessStartInfo GetJamStartInfo(bool includeModules)
4444
Arguments = moduleArgs.ToString(),
4545
FileName = "perl",
4646
};
47+
48+
var path = Environment.GetEnvironmentVariable("PATH") ?? "";
49+
// on macOS the typical mercurial path might not be in our environment variable, so add it for executing jam
50+
if (Application.platform == RuntimePlatform.OSXEditor)
51+
{
52+
var localBin = "/usr/local/bin";
53+
if (!path.Contains(localBin))
54+
path = $"{path}:{localBin}";
55+
}
56+
psi.EnvironmentVariables["PATH"] = path;
57+
58+
return psi;
4759
}
4860

4961
private static CompilerMessage[] ParseResults(string text)

Editor/Mono/CodeEditor/DefaultExternalCodeEditor.cs

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

5-
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.IO;
87
using System.Linq;
@@ -17,6 +16,7 @@ internal class DefaultExternalCodeEditor : IExternalCodeEditor
1716
static bool IsOSX => Application.platform == RuntimePlatform.OSXEditor;
1817

1918
string m_ChosenInstallation;
19+
2020
const string k_ArgumentKey = "kScriptEditorArgs";
2121
const string k_DefaultArgument = "$(File)";
2222

@@ -35,25 +35,40 @@ string Arguments
3535
// The year 2021: Delete mac hack.
3636
if (Application.platform == RuntimePlatform.OSXEditor)
3737
{
38-
var oldMac = EditorPrefs.GetString("kScriptEditorArgs_" + m_ChosenInstallation);
38+
var oldMac = EditorPrefs.GetString("kScriptEditorArgs_" + Installation);
3939
if (!string.IsNullOrEmpty(oldMac))
4040
{
4141
EditorPrefs.SetString(k_ArgumentKey, oldMac);
4242
}
4343
}
4444

45-
return EditorPrefs.GetString(k_ArgumentKey + m_ChosenInstallation, k_DefaultArgument);
45+
return EditorPrefs.GetString(k_ArgumentKey + Installation, k_DefaultArgument);
4646
}
4747
set
4848
{
4949
if (Application.platform == RuntimePlatform.OSXEditor)
5050
{
51-
EditorPrefs.SetString("kScriptEditorArgs_" + m_ChosenInstallation, value);
51+
EditorPrefs.SetString("kScriptEditorArgs_" + Installation, value);
5252
}
5353

54-
EditorPrefs.SetString(k_ArgumentKey + m_ChosenInstallation, value);
54+
EditorPrefs.SetString(k_ArgumentKey + Installation, value);
5555
}
5656
}
57+
58+
string Installation
59+
{
60+
get
61+
{
62+
if (m_ChosenInstallation == null)
63+
m_ChosenInstallation = CodeEditor.CurrentEditorInstallation;
64+
return m_ChosenInstallation;
65+
}
66+
set
67+
{
68+
m_ChosenInstallation = value;
69+
}
70+
}
71+
5772
public CodeEditor.Installation[] Installations { get; }
5873
public bool TryGetInstallationForPath(string editorPath, out CodeEditor.Installation installation)
5974
{
@@ -84,7 +99,6 @@ public void SyncAll()
8499

85100
public void Initialize(string editorInstallationPath)
86101
{
87-
m_ChosenInstallation = editorInstallationPath;
88102
}
89103

90104
static string[] defaultExtensions
@@ -115,6 +129,11 @@ public bool OpenProject(string path, int line, int column)
115129
}
116130

117131
string applicationPath = EditorPrefs.GetString("kScriptsDefaultApp");
132+
if (string.IsNullOrEmpty(applicationPath.Trim()))
133+
{
134+
return false;
135+
}
136+
118137

119138
if (IsOSX)
120139
{

Editor/Mono/EditorGUI.cs

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Event = UnityEngine.Event;
1818
using UnityEditor.Build;
1919
using UnityEditor.StyleSheets;
20+
using UnityEditor.VersionControl;
2021
using UnityEngine.Internal;
2122

2223
namespace UnityEditor
@@ -553,27 +554,28 @@ public void SendEvent()
553554
}
554555
}
555556

556-
private static void ShowTextEditorPopupMenu()
557+
static void ShowTextEditorPopupMenu()
557558
{
558559
GenericMenu pm = new GenericMenu();
559-
if (s_RecycledEditor.hasSelection && !s_RecycledEditor.isPasswordField)
560+
var enabled = GUI.enabled;
561+
562+
// Cut
563+
if (RecycledTextEditor.s_AllowContextCutOrPaste)
560564
{
561-
if (RecycledTextEditor.s_AllowContextCutOrPaste)
562-
{
565+
if (s_RecycledEditor.hasSelection && !s_RecycledEditor.isPasswordField && enabled)
563566
pm.AddItem(EditorGUIUtility.TrTextContent("Cut"), false, new PopupMenuEvent(EventCommandNames.Cut, GUIView.current).SendEvent);
564-
}
565-
pm.AddItem(EditorGUIUtility.TrTextContent("Copy"), false, new PopupMenuEvent(EventCommandNames.Copy, GUIView.current).SendEvent);
567+
else
568+
pm.AddDisabledItem(EditorGUIUtility.TrTextContent("Cut"));
566569
}
570+
571+
// Copy -- when GUI is disabled, allow Copy even with no selection (will copy everything)
572+
if ((s_RecycledEditor.hasSelection || !enabled) && !s_RecycledEditor.isPasswordField)
573+
pm.AddItem(EditorGUIUtility.TrTextContent("Copy"), false, new PopupMenuEvent(EventCommandNames.Copy, GUIView.current).SendEvent);
567574
else
568-
{
569-
if (RecycledTextEditor.s_AllowContextCutOrPaste)
570-
{
571-
pm.AddDisabledItem(EditorGUIUtility.TrTextContent("Cut"));
572-
}
573575
pm.AddDisabledItem(EditorGUIUtility.TrTextContent("Copy"));
574-
}
575576

576-
if (s_RecycledEditor.CanPaste() && RecycledTextEditor.s_AllowContextCutOrPaste)
577+
// Paste
578+
if (s_RecycledEditor.CanPaste() && RecycledTextEditor.s_AllowContextCutOrPaste && enabled)
577579
{
578580
pm.AddItem(EditorGUIUtility.TrTextContent("Paste"), false, new PopupMenuEvent(EventCommandNames.Paste, GUIView.current).SendEvent);
579581
}
@@ -742,6 +744,34 @@ static bool MightBePrintableKey(Event evt)
742744
}
743745
}
744746

747+
static EventType GetEventTypeForControlAllowDisabledContextMenuPaste(Event evt, int id)
748+
{
749+
// UI is enabled: regular code path
750+
var wasEnabled = GUI.enabled;
751+
if (wasEnabled)
752+
return evt.GetTypeForControl(id);
753+
754+
// UI is disabled: get type as if it was enabled
755+
GUI.enabled = true;
756+
var type = evt.GetTypeForControl(id);
757+
GUI.enabled = false;
758+
759+
// these events are always processed, no matter the enabled/disabled state (IMGUI::GetEventType)
760+
if (type == EventType.Repaint || type == EventType.Layout || type == EventType.Used)
761+
return type;
762+
763+
// allow context / right click, and "Copy" commands
764+
if (type == EventType.ContextClick)
765+
return type;
766+
if (type == EventType.MouseDown && evt.button == 1)
767+
return type;
768+
if ((type == EventType.ValidateCommand || type == EventType.ExecuteCommand) && evt.commandName == EventCommandNames.Copy)
769+
return type;
770+
771+
// ignore all other events for disabled controls
772+
return EventType.Ignore;
773+
}
774+
745775
// Should we select all text from the current field when the mouse goes up?
746776
// (We need to keep track of this to support both SwipeSelection & initial click selects all)
747777
internal static string DoTextField(RecycledTextEditor editor, int id, Rect position, string text, GUIStyle style, string allowedletters, out bool changed, bool reset, bool multiline, bool passwordField)
@@ -806,7 +836,9 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
806836
bool mayHaveChanged = false;
807837
string textBeforeKey = editor.text;
808838

809-
switch (evt.GetTypeForControl(id))
839+
var wasEnabled = GUI.enabled;
840+
841+
switch (GetEventTypeForControlAllowDisabledContextMenuPaste(evt, id))
810842
{
811843
case EventType.ValidateCommand:
812844
if (GUIUtility.keyboardControl == id)
@@ -853,7 +885,10 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
853885
mayHaveChanged = true;
854886
break;
855887
case EventCommandNames.Copy:
856-
editor.Copy();
888+
if (wasEnabled)
889+
editor.Copy();
890+
else if (!passwordField)
891+
GUIUtility.systemCopyBuffer = text;
857892
evt.Use();
858893
break;
859894
case EventCommandNames.Paste:
@@ -1007,8 +1042,11 @@ internal static string DoTextField(RecycledTextEditor editor, int id, Rect posit
10071042
if (!editor.IsEditingControl(id))
10081043
{ // First click: focus before showing popup
10091044
GUIUtility.keyboardControl = id;
1010-
editor.BeginEditing(id, text, position, style, multiline, passwordField);
1011-
editor.MoveCursorToPosition(Event.current.mousePosition);
1045+
if (wasEnabled)
1046+
{
1047+
editor.BeginEditing(id, text, position, style, multiline, passwordField);
1048+
editor.MoveCursorToPosition(Event.current.mousePosition);
1049+
}
10121050
}
10131051
ShowTextEditorPopupMenu();
10141052
Event.current.Use();
@@ -2492,18 +2530,30 @@ internal static GenericMenu FillPropertyContextMenu(SerializedProperty property,
24922530
if (Event.current.shift)
24932531
{
24942532
if (pm.GetItemCount() > 0)
2495-
{
24962533
pm.AddSeparator("");
2497-
}
24982534
pm.AddItem(EditorGUIUtility.TrTextContent("Print Property Path"), false, e => Debug.Log(((SerializedProperty)e).propertyPath), propertyWithPath);
24992535
}
25002536

2537+
// If property is a reference and we're using VCS, add item to check it out
2538+
if (propertyWithPath.propertyType == SerializedPropertyType.ObjectReference && Provider.isActive)
2539+
{
2540+
var obj = propertyWithPath.objectReferenceValue;
2541+
if (obj != null && !AssetDatabase.IsOpenForEdit(obj))
2542+
{
2543+
if (pm.GetItemCount() > 0)
2544+
pm.AddSeparator("");
2545+
pm.AddItem(
2546+
new GUIContent(L10n.Tr("Check Out") + " '" + obj.name + "'"),
2547+
false,
2548+
o => AssetDatabase.MakeEditable(AssetDatabase.GetAssetOrScenePath((Object)o)),
2549+
obj);
2550+
}
2551+
}
2552+
25012553
if (EditorApplication.contextualPropertyMenu != null)
25022554
{
25032555
if (pm.GetItemCount() > 0)
2504-
{
25052556
pm.AddSeparator("");
2506-
}
25072557
EditorApplication.contextualPropertyMenu(pm, property);
25082558
}
25092559

@@ -3919,7 +3969,10 @@ private static Rect RectFieldNoIndent(Rect position, Rect value)
39193969
s_Vector2Floats[0] = value.x;
39203970
s_Vector2Floats[1] = value.y;
39213971
BeginChangeCheck();
3922-
MultiFloatField(position, s_XYLabels, s_Vector2Floats);
3972+
// Right align the text
3973+
var oldAlignment = EditorStyles.label.alignment;
3974+
EditorStyles.label.alignment = TextAnchor.MiddleRight;
3975+
MultiFloatFieldInternal(position, s_XYLabels, s_Vector2Floats, kMiniLabelW);
39233976
if (EndChangeCheck())
39243977
{
39253978
value.x = s_Vector2Floats[0];
@@ -3929,12 +3982,13 @@ private static Rect RectFieldNoIndent(Rect position, Rect value)
39293982
s_Vector2Floats[0] = value.width;
39303983
s_Vector2Floats[1] = value.height;
39313984
BeginChangeCheck();
3932-
MultiFloatField(position, s_WHLabels, s_Vector2Floats);
3985+
MultiFloatFieldInternal(position, s_WHLabels, s_Vector2Floats, kMiniLabelW);
39333986
if (EndChangeCheck())
39343987
{
39353988
value.width = s_Vector2Floats[0];
39363989
value.height = s_Vector2Floats[1];
39373990
}
3991+
EditorStyles.label.alignment = oldAlignment;
39383992
return value;
39393993
}
39403994

@@ -4170,7 +4224,7 @@ public static void MultiFloatField(Rect position, GUIContent[] subLabels, float[
41704224
MultiFloatFieldInternal(position, subLabels, values);
41714225
}
41724226

4173-
internal static void MultiFloatFieldInternal(Rect position, GUIContent[] subLabels, float[] values)
4227+
internal static void MultiFloatFieldInternal(Rect position, GUIContent[] subLabels, float[] values, float prefixLabelWidth = -1)
41744228
{
41754229
int eCount = values.Length;
41764230
float w = (position.width - (eCount - 1) * kSpacingSubLabel) / eCount;
@@ -4180,7 +4234,7 @@ internal static void MultiFloatFieldInternal(Rect position, GUIContent[] subLabe
41804234
indentLevel = 0;
41814235
for (int i = 0; i < values.Length; i++)
41824236
{
4183-
EditorGUIUtility.labelWidth = EditorGUI.CalcPrefixLabelWidth(subLabels[i]);
4237+
EditorGUIUtility.labelWidth = prefixLabelWidth > 0 ? prefixLabelWidth : EditorGUI.CalcPrefixLabelWidth(subLabels[i]);
41844238
values[i] = FloatField(nr, subLabels[i], values[i]);
41854239
nr.x += w + kSpacingSubLabel;
41864240
}
@@ -4361,7 +4415,10 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
43614415
bool hovered = position.Contains(evt.mousePosition);
43624416
bool hoveredEyedropper = new Rect(position.x + position.width - kEyedropperSize, position.y, kEyedropperSize, position.height).Contains(evt.mousePosition);
43634417

4364-
switch (evt.GetTypeForControl(id))
4418+
var wasEnabled = GUI.enabled;
4419+
var eventType = GetEventTypeForControlAllowDisabledContextMenuPaste(evt, id);
4420+
4421+
switch (eventType)
43654422
{
43664423
case EventType.MouseDown:
43674424
if (showEyedropper)
@@ -4387,7 +4444,7 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
43874444
GUIUtility.keyboardControl = id;
43884445

43894446
var names = new[] { L10n.Tr("Copy"), L10n.Tr("Paste") };
4390-
var enabled = new[] {true, ColorClipboard.HasColor()};
4447+
var enabled = new[] {true, wasEnabled && ColorClipboard.HasColor()};
43914448
var currentView = GUIView.current;
43924449

43934450
EditorUtility.DisplayCustomMenu(
@@ -4415,7 +4472,7 @@ private static Color DoColorField(Rect position, int id, Color value, bool showE
44154472

44164473
if (showEyedropper)
44174474
{
4418-
if (hoveredEyedropper)
4475+
if (hoveredEyedropper && wasEnabled)
44194476
{
44204477
GUIUtility.keyboardControl = id;
44214478
EyeDropper.Start(GUIView.current);

0 commit comments

Comments
 (0)