Skip to content

Commit 806e5e6

Browse files
author
Unity Technologies
committed
Unity 2020.1.0a7 C# reference source code
1 parent 32bd3a1 commit 806e5e6

File tree

271 files changed

+11123
-8340
lines changed

Some content is hidden

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

271 files changed

+11123
-8340
lines changed

Editor/Mono/Annotation/AnnotationWindow.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -580,12 +580,8 @@ void DrawListElement(Rect rect, bool even, AInfo ainfo)
580580

581581
// Icon toggle
582582
Rect iconRect = new Rect(rect.width - iconRightAlign + 2, rect.y + (rect.height - iconSize) * 0.5f, iconSize, iconSize); // +2 because the given rect is shortened by 2px before this method call
583-
Texture thumb = null;
584583
if (ainfo.m_ScriptClass != "")
585584
{
586-
// Icon for scripts
587-
thumb = EditorGUIUtility.GetIconForObject(EditorGUIUtility.GetScript(ainfo.m_ScriptClass));
588-
589585
Rect div = iconRect;
590586
div.x += 18;
591587
div.y += 1;
@@ -622,22 +618,16 @@ void DrawListElement(Rect rect, bool even, AInfo ainfo)
622618
}
623619
}
624620
}
625-
else
626-
{
627-
// Icon for builtin components
628-
if (ainfo.HasIcon())
629-
thumb = AssetPreview.GetMiniTypeThumbnailFromClassID(ainfo.m_ClassID);
630-
}
631621

632-
if (thumb != null)
622+
if (ainfo.Thumb != null)
633623
{
634624
if (!ainfo.m_IconEnabled)
635625
{
636626
GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, disabledAlpha);
637627
tooltip = "";
638628
}
639629

640-
iconToggleContent.image = thumb;
630+
iconToggleContent.image = ainfo.Thumb;
641631
if (GUI.Button(iconRect, iconToggleContent, GUIStyle.none))
642632
{
643633
ainfo.m_IconEnabled = !ainfo.m_IconEnabled;
@@ -711,6 +701,33 @@ public AInfo(bool gizmoEnabled, bool iconEnabled, int flags, int classID, string
711701
public string m_ScriptClass;
712702
public string m_DisplayText;
713703
public int m_Flags;
704+
private Object m_Script;
705+
public Object Script
706+
{
707+
get
708+
{
709+
if (m_Script == null && m_ScriptClass != "")
710+
m_Script = EditorGUIUtility.GetScript(m_ScriptClass);
711+
return m_Script;
712+
}
713+
}
714+
private Texture2D m_Thumb;
715+
public Texture2D Thumb
716+
{
717+
get
718+
{
719+
if (m_Thumb == null)
720+
{
721+
// Icon for scripts
722+
if (Script != null)
723+
m_Thumb = EditorGUIUtility.GetIconForObject(m_Script);
724+
// Icon for builtin components
725+
else if (HasIcon())
726+
m_Thumb = AssetPreview.GetMiniTypeThumbnailFromClassID(m_ClassID);
727+
}
728+
return m_Thumb;
729+
}
730+
}
714731

715732
public bool HasGizmo()
716733
{

Editor/Mono/AssemblyHelper.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,12 @@ public static string[] GetDefaultAssemblySearchPaths()
263263
foreach (var asm in precompiledAssemblies)
264264
searchPaths.Add(Path.GetDirectoryName(asm.Path));
265265

266+
// Add Unity compiled assembly output directory.
267+
// Required for MonoBehaviour derived types like UIBehaviour that
268+
// were previous in a precompiled UnityEngine.UI.dll, but are now
269+
// compiled in a package.
270+
searchPaths.Add("Library/ScriptAssemblies");
271+
266272
return searchPaths.ToArray();
267273
}
268274

Editor/Mono/AssetDatabase/AssetDatabase.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
using System;
66
using System.Collections.Generic;
7+
using UnityEditor.VersionControl;
78
using UnityEngine.Scripting;
89
using uei = UnityEngine.Internal;
910

@@ -77,5 +78,24 @@ public static void IsOpenForEdit(string[] assetOrMetaFilePaths, List<string> out
7778
AssetModificationProcessorInternal.IsOpenForEdit(assetOrMetaFilePaths, outNotEditablePaths, statusQueryOptions);
7879
UnityEngine.Profiling.Profiler.EndSample();
7980
}
81+
82+
public static bool MakeEditable(string path)
83+
{
84+
if (path == null)
85+
throw new ArgumentNullException(nameof(path));
86+
return MakeEditable(new[] {path});
87+
}
88+
89+
public static bool MakeEditable(string[] paths, string prompt = null, List<string> outNotEditablePaths = null)
90+
{
91+
if (paths == null)
92+
throw new ArgumentNullException(nameof(paths));
93+
94+
ChangeSet changeSet = null;
95+
if (!Provider.HandlePreCheckoutCallback(ref paths, ref changeSet))
96+
return false;
97+
98+
return Provider.MakeEditableImpl(paths, prompt, changeSet, outNotEditablePaths);
99+
}
80100
}
81101
}

Editor/Mono/AssetModificationProcessor.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,22 +121,20 @@ static void OnWillCreateAsset(string path)
121121
}
122122
}
123123

124+
// ReSharper disable once UnusedMember.Local - invoked from native code
124125
static void FileModeChanged(string[] assets, UnityEditor.VersionControl.FileMode mode)
125126
{
126-
// Make sure that all assets are checked out in version control and
127-
// that we have the most recent status
128-
if (Provider.enabled)
129-
{
130-
var editableAssets = new string[assets.Length];
131-
if (Provider.MakeEditable(assets, editableAssets))
132-
{
133-
// TODO: handle partial results from MakeEditable i.e. editableassets
134-
Provider.SetFileMode(assets, mode);
135-
}
136-
}
127+
if (!Provider.enabled)
128+
return;
129+
130+
// we'll want to re-serialize these assets in different (text vs binary) mode;
131+
// make sure they are editable first
132+
AssetDatabase.MakeEditable(assets);
133+
Provider.SetFileMode(assets, mode);
137134
}
138135

139136
// Postprocess on all assets once an automatic import has completed
137+
// ReSharper disable once UnusedMember.Local - invoked from native code
140138
static void OnWillSaveAssets(string[] assets, out string[] assetsThatShouldBeSaved, out string[] assetsThatShouldBeReverted, bool explicitlySaveAsset)
141139
{
142140
assetsThatShouldBeReverted = new string[0];
@@ -179,16 +177,15 @@ static void OnWillSaveAssets(string[] assets, out string[] assetsThatShouldBeSav
179177
AssetDatabase.IsOpenForEdit(assetsThatShouldBeSaved, assetsNotOpened, StatusQueryOptions.ForceUpdate);
180178
assets = assetsNotOpened.ToArray();
181179

182-
// Try to checkout if needed. This may fail but is caught below.
183-
var editableAssets = new string[assets.Length];
184-
if (assets.Length != 0 && !Provider.MakeEditable(assets, editableAssets))
180+
// Try to checkout if needed
181+
var notEditableAssets = new List<string>();
182+
if (assets.Length != 0 && !AssetDatabase.MakeEditable(assets, null, notEditableAssets))
185183
{
186184
// only save assets that can be made editable (not locked by someone else, etc.),
187185
// unless we are in the behavior mode that just overwrites everything anyway
188186
if (!EditorUserSettings.overwriteFailedCheckoutAssets)
189187
{
190-
editableAssets = editableAssets.Where(a => a != null).ToArray();
191-
assetsThatShouldBeReverted = assets.Except(editableAssets).ToArray();
188+
assetsThatShouldBeReverted = notEditableAssets.ToArray();
192189
assetsThatShouldBeSaved = assetsThatShouldBeSaved.Except(assetsThatShouldBeReverted).ToArray();
193190
}
194191
}

Editor/Mono/AssetPipeline/AssetImporter.bindings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public Dictionary<SourceAssetIdentifier, Object> GetExternalObjectMap()
139139
}
140140

141141
[FreeFunction("AssetImporterBindings::RegisterImporter")]
142-
extern internal static void RegisterImporter(Type importer, int importerVersion, int queuePos, string fileExt, bool supportsImportDependencyHinting, bool autoSelect);
142+
extern internal static void RegisterImporter(Type importer, int importerVersion, int queuePos, string fileExt, bool supportsImportDependencyHinting, bool autoSelect, bool allowCaching);
143143

144144
[FreeFunction("AssetImporterBindings::SupportsRemappedAssetType", HasExplicitThis = true, IsThreadSafe = true)]
145145
public extern bool SupportsRemappedAssetType(Type type);

Editor/Mono/BuildPipeline.bindings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ public enum BuildOptions
110110
//StripUnityVersion = 1 << 27
111111

112112
// Enable C# code instrumentation for the player.
113-
EnableDeepProfilingSupport = 1 << 28
113+
EnableDeepProfilingSupport = 1 << 28,
114+
115+
// The BuildReport object returned by BuildPipeline.BuildPlayer will contain more details (about build times and contents), at the cost of a slightly (typically, a few percents) longer build time
116+
DetailedBuildReport = 1 << 29
114117
}
115118

116119
// Asset Bundle building options.

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: 20 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

Editor/Mono/ContainerWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ internal bool IsNotDocked()
198198
return ( // hallelujah
199199

200200
(m_ShowMode == (int)ShowMode.Utility || m_ShowMode == (int)ShowMode.AuxWindow) ||
201-
(m_ShowMode == (int)ShowMode.MainWindow && (rootView is HostView || rootView is MainView)) ||
201+
(m_ShowMode == (int)ShowMode.MainWindow && rootView is HostView) ||
202202
(rootView is SplitView &&
203203
rootView.children.Length == 1 &&
204204
rootView.children[0] is DockArea &&

Editor/Mono/Delayer.cs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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 System;
6+
7+
namespace UnityEditor
8+
{
9+
internal class Delayer
10+
{
11+
private double m_LastExecutionTime;
12+
private readonly Action<object> m_Action;
13+
private readonly double m_DebounceDelay;
14+
private object m_Context;
15+
private readonly bool m_IsThrottle;
16+
17+
public static Delayer Throttle(Action<object> action, double delay = 0.2)
18+
{
19+
return new Delayer(action, delay, true);
20+
}
21+
22+
public static Delayer Debounce(Action<object> action, double delay = 0.2)
23+
{
24+
return new Delayer(action, delay, false);
25+
}
26+
27+
public void Execute(object context = null)
28+
{
29+
m_Context = context;
30+
if (m_IsThrottle)
31+
{
32+
if (m_LastExecutionTime == 0)
33+
Throttle();
34+
}
35+
else
36+
{
37+
m_LastExecutionTime = EditorApplication.timeSinceStartup;
38+
Debounce();
39+
}
40+
}
41+
42+
private Delayer(Action<object> action, double delay, bool isThrottle)
43+
{
44+
m_Action = action;
45+
m_DebounceDelay = delay;
46+
m_IsThrottle = isThrottle;
47+
}
48+
49+
private void Debounce()
50+
{
51+
EditorApplication.delayCall -= Debounce;
52+
var currentTime = EditorApplication.timeSinceStartup;
53+
if (m_LastExecutionTime != 0 && currentTime - m_LastExecutionTime > m_DebounceDelay)
54+
{
55+
m_Action(m_Context);
56+
m_LastExecutionTime = 0;
57+
}
58+
else
59+
{
60+
EditorApplication.delayCall += Debounce;
61+
}
62+
}
63+
64+
private void Throttle()
65+
{
66+
EditorApplication.delayCall -= Throttle;
67+
var currentTime = EditorApplication.timeSinceStartup;
68+
if (m_LastExecutionTime != 0 && currentTime - m_LastExecutionTime > m_DebounceDelay)
69+
{
70+
m_Action(m_Context);
71+
m_LastExecutionTime = 0;
72+
}
73+
else
74+
{
75+
if (m_LastExecutionTime == 0)
76+
m_LastExecutionTime = currentTime;
77+
EditorApplication.delayCall += Throttle;
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)