Skip to content

Commit fe10d41

Browse files
author
Unity Technologies
committed
Unity 2019.2.0f1 C# reference source code
1 parent ca13d8f commit fe10d41

32 files changed

Lines changed: 2380 additions & 160 deletions

Editor/Mono/AssetPostprocessor.cs

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using System.Reflection;
1414
using Object = UnityEngine.Object;
1515
using UnityEditor.Experimental.AssetImporters;
16+
using UnityEditorInternal;
17+
using Unity.CodeEditor;
1618

1719
namespace UnityEditor
1820
{
@@ -86,8 +88,16 @@ static void PostprocessAllAssets(string[] importedAssets, string[] addedAssets,
8688
}
8789

8890
Profiler.BeginSample("SyncVS.PostprocessSyncProject");
89-
///@TODO: we need addedAssets for SyncVS. Make this into a proper API and write tests
90-
CodeEditorProjectSync.PostprocessSyncProject(importedAssets, addedAssets, deletedAssets, movedAssets, movedFromPathAssets);
91+
#pragma warning disable 618
92+
if (ScriptEditorUtility.GetScriptEditorFromPath(CodeEditor.CurrentEditorInstallation) == ScriptEditorUtility.ScriptEditor.Other)
93+
{
94+
CodeEditorProjectSync.PostprocessSyncProject(importedAssets, addedAssets, deletedAssets, movedAssets, movedFromPathAssets);
95+
}
96+
else
97+
{
98+
///@TODO: we need addedAssets for SyncVS. Make this into a proper API and write tests
99+
SyncVS.PostprocessSyncProject(importedAssets, addedAssets, deletedAssets, movedAssets, movedFromPathAssets);
100+
}
91101
Profiler.EndSample();
92102
}
93103

@@ -100,6 +110,67 @@ static void PreprocessAssembly(string pathName)
100110
}
101111
}
102112

113+
//This is undocumented, and a "safeguard" for when visualstudio gets a new release that is incompatible with ours, so that users can postprocess our csproj to fix it.
114+
//(or just completely replace them). Hopefully we'll never need this.
115+
static internal void CallOnGeneratedCSProjectFiles()
116+
{
117+
object[] args = {};
118+
foreach (var method in AllPostProcessorMethodsNamed("OnGeneratedCSProjectFiles"))
119+
{
120+
InvokeMethod(method, args);
121+
}
122+
}
123+
124+
//This callback is used by C# code editors to modify the .sln file.
125+
static internal string CallOnGeneratedSlnSolution(string path, string content)
126+
{
127+
foreach (var method in AllPostProcessorMethodsNamed("OnGeneratedSlnSolution"))
128+
{
129+
object[] args = { path, content };
130+
object returnValue = InvokeMethod(method, args);
131+
132+
if (method.ReturnType == typeof(string))
133+
content = (string)returnValue;
134+
}
135+
136+
return content;
137+
}
138+
139+
// This callback is used by C# code editors to modify the .csproj files.
140+
static internal string CallOnGeneratedCSProject(string path, string content)
141+
{
142+
foreach (var method in AllPostProcessorMethodsNamed("OnGeneratedCSProject"))
143+
{
144+
object[] args = { path, content };
145+
object returnValue = InvokeMethod(method, args);
146+
147+
if (method.ReturnType == typeof(string))
148+
content = (string)returnValue;
149+
}
150+
151+
return content;
152+
}
153+
154+
//This callback is used by UnityVS to take over project generation from unity
155+
static internal bool OnPreGeneratingCSProjectFiles()
156+
{
157+
object[] args = {};
158+
bool result = false;
159+
foreach (var method in AllPostProcessorMethodsNamed("OnPreGeneratingCSProjectFiles"))
160+
{
161+
object returnValue = InvokeMethod(method, args);
162+
163+
if (method.ReturnType == typeof(bool))
164+
result = result | (bool)returnValue;
165+
}
166+
return result;
167+
}
168+
169+
private static IEnumerable<MethodInfo> AllPostProcessorMethodsNamed(string callbackName)
170+
{
171+
return GetCachedAssetPostprocessorClasses().Select(assetPostprocessorClass => assetPostprocessorClass.GetMethod(callbackName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static)).Where(method => method != null);
172+
}
173+
103174
internal class CompareAssetImportPriority : IComparer
104175
{
105176
int IComparer.Compare(System.Object xo, System.Object yo)
@@ -193,6 +264,16 @@ static void CleanupPostprocessors()
193264
}
194265
}
195266

267+
static bool ImplementsAnyOfTheses(Type type, string[] methods)
268+
{
269+
foreach (var method in methods)
270+
{
271+
if (type.GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null)
272+
return true;
273+
}
274+
return false;
275+
}
276+
196277
[RequiredByNativeCode]
197278
static string GetMeshProcessorsHashString()
198279
{
@@ -207,11 +288,20 @@ static string GetMeshProcessorsHashString()
207288
{
208289
var inst = Activator.CreateInstance(assetPostprocessorClass) as AssetPostprocessor;
209290
var type = inst.GetType();
210-
bool hasPreProcessMethod = type.GetMethod("OnPreprocessModel", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
211-
bool hasPostprocessMeshHierarchy = type.GetMethod("OnPostprocessMeshHierarchy", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
212-
bool hasPostProcessMethod = type.GetMethod("OnPostprocessModel", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance) != null;
291+
bool hasAnyPostprocessMethod = ImplementsAnyOfTheses(type, new[]
292+
{
293+
"OnPreprocessModel",
294+
"OnPostprocessMeshHierarchy",
295+
"OnPostprocessModel",
296+
"OnPreprocessAnimation",
297+
"OnPostprocessAnimation",
298+
"OnPostprocessGameObjectWithAnimatedUserProperties",
299+
"OnPostprocessGameObjectWithUserProperties",
300+
"OnPostprocessMaterial",
301+
"OnAssignMaterialModel"
302+
});
213303
uint version = inst.GetVersion();
214-
if (version != 0 && (hasPreProcessMethod || hasPostprocessMeshHierarchy || hasPostProcessMethod))
304+
if (version != 0 && hasAnyPostprocessMethod)
215305
{
216306
versionsByType.Add(type.FullName, version);
217307
}

Editor/Mono/CodeEditor/CodeEditor.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ static bool OnOpenAsset(int instanceID, int line, int column)
4141
var selected = EditorUtility.InstanceIDToObject(instanceID);
4242
var assetPath = AssetDatabase.GetAssetPath(selected);
4343

44+
#pragma warning disable 618
45+
if (ScriptEditorUtility.GetScriptEditorFromPath(CurrentEditorInstallation) != ScriptEditorUtility.ScriptEditor.Other)
46+
{
47+
return false;
48+
}
49+
4450
if (string.IsNullOrEmpty(assetPath))
4551
{
4652
return false;
@@ -144,7 +150,7 @@ internal Dictionary<string, string> GetFoundScriptEditorPaths()
144150
return result;
145151
}
146152

147-
static void AddIfPathExists(string name, string path, Dictionary<string, string> list)
153+
internal static void AddIfPathExists(string name, string path, Dictionary<string, string> list)
148154
{
149155
if (list.ContainsKey(path))
150156
return;
@@ -164,6 +170,11 @@ public static void Register(IExternalCodeEditor externalCodeEditor)
164170
Editor.m_ExternalCodeEditors.Add(externalCodeEditor);
165171
}
166172

173+
public static void Unregister(IExternalCodeEditor externalCodeEditor)
174+
{
175+
Editor.m_ExternalCodeEditors.Remove(externalCodeEditor);
176+
}
177+
167178
public static IExternalCodeEditor CurrentEditor => Editor.Current;
168179

169180
public static string CurrentEditorInstallation => Editor.EditorInstallation.Path;

Editor/Mono/CodeEditor/CodeEditorProjectSync.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ static void OpenProjectFileUnlessInBatchMode()
5353
if (InternalEditorUtility.inBatchMode)
5454
return;
5555

56-
CodeEditor.Editor.Current.OpenProject();
56+
#pragma warning disable 618
57+
if (ScriptEditorUtility.GetScriptEditorFromPath(CodeEditor.CurrentEditorInstallation) == ScriptEditorUtility.ScriptEditor.Other)
58+
{
59+
CodeEditor.Editor.Current.OpenProject();
60+
}
61+
else
62+
{
63+
InternalEditorUtility.OpenFileAtLineExternal("", -1, -1);
64+
}
5765
}
5866
}
5967
}

Editor/Mono/CodeEditor/SyncVS.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@
55
using System;
66
using System.Security.Cryptography;
77
using System.Text;
8+
using Unity.CodeEditor;
9+
using UnityEditorInternal;
810

911
namespace UnityEditor
1012
{
11-
class SyncVS
13+
partial class SyncVS
1214
{
1315
public static void SyncSolution()
1416
{
17+
// Ensure that the mono islands are up-to-date
18+
AssetDatabase.Refresh();
19+
1520
// TODO: Rider and possibly other code editors, use reflection to call this method.
1621
// To avoid conflicts and null reference exception, this is left as a dummy method.
1722
Unity.CodeEditor.CodeEditor.Editor.Current.SyncAll();
23+
24+
#pragma warning disable 618
25+
if (ScriptEditorUtility.GetScriptEditorFromPath(CodeEditor.CurrentEditorInstallation) != ScriptEditorUtility.ScriptEditor.Other)
26+
{
27+
Synchronizer.Sync();
28+
}
1829
}
1930
}
2031

Editor/Mono/EditorGUI.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9429,25 +9429,20 @@ public static bool BeginFadeGroup(float value)
94299429
{
94309430
GUILayoutFadeGroup g = (GUILayoutFadeGroup)GUILayoutUtility.BeginLayoutGroup(GUIStyle.none, null, typeof(GUILayoutFadeGroup));
94319431
g.isVertical = true;
9432-
g.resetCoords = false;
9432+
g.resetCoords = true;
94339433
g.fadeValue = value;
94349434
g.wasGUIEnabled = GUI.enabled;
94359435
g.guiColor = GUI.color;
94369436
g.consideredForMargin = value > 0;
94379437

9438-
if (value != 0.0f && value != 1.0f)
9438+
if (value != 0.0f && value != 1.0f && Event.current.type == EventType.MouseDown)
94399439
{
9440-
g.resetCoords = true;
9441-
GUI.BeginGroup(g.rect);
9442-
9443-
if (Event.current.type == EventType.MouseDown)
9444-
{
9445-
Event.current.Use();
9446-
}
9440+
Event.current.Use();
94479441
}
94489442

94499443
// We don't want the fade group gui clip to be used for calculating the label width of controls in this fade group, so we lock the context width.
94509444
EditorGUIUtility.LockContextWidth();
9445+
GUI.BeginGroup(g.rect);
94519446

94529447
return value != 0;
94539448
}
@@ -9464,10 +9459,7 @@ public static void EndFadeGroup()
94649459
return;
94659460
}
94669461

9467-
if (g.fadeValue != 0.0f && g.fadeValue != 1.0f)
9468-
{
9469-
GUI.EndGroup();
9470-
}
9462+
GUI.EndGroup();
94719463

94729464
EditorGUIUtility.UnlockContextWidth();
94739465
GUI.enabled = g.wasGUIEnabled;

Editor/Mono/EditorGUIUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal static Material GUITextureBlit2SRGBMaterial
4848
if (!s_GUITextureBlit2SRGBMaterial)
4949
{
5050
Shader shader = LoadRequired("SceneView/GUITextureBlit2SRGB.shader") as Shader;
51-
s_GUITextureBlit2SRGBMaterial = new Material(shader) {hideFlags = HideFlags.HideAndDontSave};
51+
s_GUITextureBlit2SRGBMaterial = new Material(shader);
5252
}
5353
s_GUITextureBlit2SRGBMaterial.SetFloat("_ManualTex2SRGB", QualitySettings.activeColorSpace == ColorSpace.Linear ? 1.0f : 0.0f);
5454
return s_GUITextureBlit2SRGBMaterial;
@@ -63,7 +63,7 @@ internal static Material GUITextureBlitSceneGUIMaterial
6363
if (!s_GUITextureBlitSceneGUI)
6464
{
6565
Shader shader = LoadRequired("SceneView/GUITextureBlitSceneGUI.shader") as Shader;
66-
s_GUITextureBlitSceneGUI = new Material(shader) { hideFlags = HideFlags.HideAndDontSave };
66+
s_GUITextureBlitSceneGUI = new Material(shader);
6767
}
6868
return s_GUITextureBlitSceneGUI;
6969
}

Editor/Mono/EditorSettings.bindings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Linq;
77
using System.Runtime.InteropServices;
8+
using UnityEditor.VisualStudioIntegration;
89
using UnityEngine.Bindings;
910
using Object = UnityEngine.Object;
1011

@@ -192,7 +193,7 @@ public static string[] projectGenerationUserExtensions
192193

193194
public static string[] projectGenerationBuiltinExtensions
194195
{
195-
get { return new[] { "cs", "uxml", "uss", "shader", "compute", "cginc", "hlsl", "glslinc", "template" }; }
196+
get { return SolutionSynchronizer.BuiltinSupportedExtensions.Keys.ToArray(); }
196197
}
197198

198199
internal static extern string Internal_ProjectGenerationUserExtensions

Editor/Mono/GUI/AboutWindow.cs

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

55
using UnityEngine;
66
using System;
7+
using System.Collections;
8+
using System.Collections.Generic;
9+
using UnityEditor;
10+
using UnityEditor.VisualStudioIntegration;
711
using UnityEditorInternal;
812

913
namespace UnityEditor
@@ -146,6 +150,9 @@ public void OnGUI()
146150
GUILayout.BeginVertical();
147151
GUILayout.FlexibleSpace();
148152

153+
var VSTUlabel = UnityVSSupport.GetAboutWindowLabel();
154+
if (VSTUlabel.Length > 0)
155+
GUILayout.Label(VSTUlabel, "MiniLabel");
149156
GUILayout.Label(InternalEditorUtility.GetUnityCopyright(), "MiniLabel");
150157
GUILayout.EndVertical();
151158
GUILayout.Space(10);

Editor/Mono/GUI/ReorderableList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ private void DoDraggingAndSelection(Rect listRect)
709709
// Set m_Dragging state on first MouseDrag event after we got hotcontrol (to prevent animating elements when deleting elements by context menu)
710710
m_Dragging = true;
711711

712-
if (onMouseUpCallback != null)
712+
if (onMouseDragCallback != null)
713713
onMouseDragCallback(this);
714714

715715
// if we are dragging, update the position

0 commit comments

Comments
 (0)