Skip to content

Commit f21b4df

Browse files
author
Unity Technologies
committed
Unity 2018.2.2f1 C# reference source code
1 parent 3225c11 commit f21b4df

8 files changed

Lines changed: 375 additions & 15 deletions

File tree

Editor/Mono/GUI/DockArea.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using UnityEditorInternal;
1010
using UnityEngine.Experimental.UIElements;
1111
using UnityEngine.Experimental.UIElements.StyleEnums;
12+
using UnityEngine.XR;
1213

1314
namespace UnityEditor
1415
{
@@ -391,13 +392,35 @@ protected override void OldOnGUI()
391392

392393
if (m_Panes.Count > 0)
393394
{
395+
RenderToHMDIfNecessary(r);
394396
InvokeOnGUI(r);
395397
}
396398

397399
EditorGUI.ShowRepaints();
398400
Highlighter.ControlHighlightGUI(this);
399401
}
400402

403+
void RenderToHMDIfNecessary(Rect onGUIPosition)
404+
{
405+
if (!XRSettings.isDeviceActive ||
406+
(actualView is GameView) ||
407+
!EditorApplication.isPlaying ||
408+
EditorApplication.isPaused ||
409+
Event.current.type != EventType.Repaint)
410+
{
411+
return;
412+
}
413+
414+
foreach (var pane in m_Panes)
415+
{
416+
if (pane is GameView)
417+
{
418+
var gameView = pane as GameView;
419+
gameView.RenderToHMDOnly();
420+
}
421+
}
422+
}
423+
401424
protected override void SetActualViewPosition(Rect newPos)
402425
{
403426
//Sit down and let me tell you the intent of this.

Editor/Mono/GUI/EditorGUIInternal.cs

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

55
using System;
66
using System.Collections;
7-
using ICSharpCode.NRefactory.Ast;
87
using UnityEngine;
98
using System.Collections.Generic;
109
using Object = UnityEngine.Object;

Editor/Mono/Inspector/EditorDragging.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,18 @@ void HandleEditorDragging(Editor[] editors, int editorIndex, Rect targetRect, fl
199199
// Add script components
200200
var index = 0;
201201
var addedComponents = new Component[targetComponents.Length * scripts.Count()];
202-
foreach (var targetComponent in targetComponents)
202+
for (int i = 0; i < targetComponents.Length; i++)
203203
{
204+
var targetComponent = targetComponents[i];
204205
var gameObject = targetComponent.gameObject;
206+
bool targetIsTransform = targetComponent is Transform;
205207
foreach (var script in scripts)
206208
addedComponents[index++] = ObjectFactory.AddComponent(gameObject, script.GetClass());
209+
210+
// If the target is a Transform, the AddComponent might have replaced it with a RectTransform.
211+
// Handle this possibility by updating the target component.
212+
if (targetIsTransform)
213+
targetComponents[i] = gameObject.transform;
207214
}
208215

209216
// Move added components relative to target components

Editor/Mono/Scripting/Compilers/CSharpLanguage.cs

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
using ICSharpCode.NRefactory.Visitors;
88
using System.IO;
99
using System.Collections.Generic;
10+
using System.Linq;
1011
using System.Text.RegularExpressions;
12+
using JetBrains.Annotations;
1113
using UnityEditor.Modules;
14+
using UnityEditor.Scripting.ScriptCompilation;
15+
using UnityEngine;
1216

1317
namespace UnityEditor.Scripting.Compilers
1418
{
@@ -52,22 +56,58 @@ public override bool CompilerRequiresAdditionalReferences()
5256
return true;
5357
}
5458

55-
public override string GetNamespace(string fileName, string definedSymbols)
59+
public string GetNamespaceNewRuntime(string filePath, string definedSymbols)
5660
{
57-
using (var parser = ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.CSharp, ReadAndConverteNewLines(fileName)))
61+
var definedSymbolSplit = definedSymbols.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
62+
string[] defines = null;
63+
var responseFilePath = Path.Combine("Assets", MonoCSharpCompiler.ReponseFilename);
64+
try
65+
{
66+
var responseFileData = ScriptCompilerBase.ParseResponseFileFromFile(responseFilePath);
67+
defines = new string[responseFileData.Defines.Length + definedSymbolSplit.Length];
68+
Array.Copy(definedSymbolSplit, defines, definedSymbolSplit.Length);
69+
Array.Copy(responseFileData.Defines, 0, defines, definedSymbolSplit.Length, responseFileData.Defines.Length);
70+
}
71+
catch (Exception e)
72+
{
73+
Debug.LogException(e);
74+
}
75+
76+
var uniqueSymbols = new HashSet<string>(defines ?? definedSymbolSplit);
77+
return CSharpNamespaceParser.GetNamespace(ReadAndConverteNewLines(filePath).ReadToEnd(), Path.GetFileNameWithoutExtension(filePath), uniqueSymbols.ToArray());
78+
}
79+
80+
public string GetNamespaceOldRuntime(string filePath, string definedSymbols)
81+
{
82+
var definedSymbolSplit = definedSymbols.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
83+
string[] defines = null;
84+
var responseFilePath = Path.Combine("Assets", MonoCSharpCompiler.ReponseFilename);
85+
try
86+
{
87+
var responseFileData = ScriptCompilerBase.ParseResponseFileFromFile(responseFilePath);
88+
defines = new string[responseFileData.Defines.Length + definedSymbolSplit.Length];
89+
Array.Copy(definedSymbolSplit, defines, definedSymbolSplit.Length);
90+
Array.Copy(responseFileData.Defines, 0, defines, definedSymbolSplit.Length, responseFileData.Defines.Length);
91+
}
92+
catch (Exception e)
93+
{
94+
Debug.LogException(e);
95+
}
96+
97+
var uniqueSymbols = new HashSet<string>(defines ?? definedSymbolSplit);
98+
using (var parser = ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.CSharp, ReadAndConverteNewLines(filePath)))
5899
{
59-
var uniqueSymbols = new HashSet<string>(definedSymbols.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
60100
foreach (var symbol in uniqueSymbols)
61101
{
62102
parser.Lexer.ConditionalCompilationSymbols.Add(symbol, string.Empty);
63103
}
64-
parser.Lexer.EvaluateConditionalCompilation = true;
65104

105+
parser.Lexer.EvaluateConditionalCompilation = true;
66106
parser.Parse();
67107
try
68108
{
69109
var visitor = new NamespaceVisitor();
70-
VisitorData data = new VisitorData() {TargetClassName = Path.GetFileNameWithoutExtension(fileName)};
110+
var data = new VisitorData { TargetClassName = Path.GetFileNameWithoutExtension(filePath) };
71111
parser.CompilationUnit.AcceptVisitor(visitor, data);
72112
return string.IsNullOrEmpty(data.DiscoveredNamespace) ? string.Empty : data.DiscoveredNamespace;
73113
}
@@ -79,12 +119,24 @@ public override string GetNamespace(string fileName, string definedSymbols)
79119
return string.Empty;
80120
}
81121

122+
public override string GetNamespace(string filePath, string definedSymbols)
123+
{
124+
if (EditorApplication.scriptingRuntimeVersion == ScriptingRuntimeVersion.Latest)
125+
{
126+
return GetNamespaceNewRuntime(filePath, definedSymbols);
127+
}
128+
else
129+
{
130+
return GetNamespaceOldRuntime(filePath, definedSymbols);
131+
}
132+
}
133+
82134
// TODO: Revisit this code and switch to version 5.5.1 (or Roslyn if possible) when Editor switches to newer runtime version (on going work expected
83135
// to finish around 2017.2 or 2017.3 release.
84136
//
85137
// This is a workaround for a bug in version 3.2.1 of NRefactory in which it fails to parse sources with a combination of LF / #if / #else
86138
// Version 5.5.1 is confirmed to not have this bug but we can't use it since it requires a newer runtime/c# version;
87-
private static StringReader ReadAndConverteNewLines(string filePath)
139+
static StringReader ReadAndConverteNewLines(string filePath)
88140
{
89141
var text = File.ReadAllText(filePath);
90142

@@ -105,27 +157,25 @@ public VisitorData()
105157
public Stack<string> CurrentNamespaces;
106158
public string DiscoveredNamespace;
107159
}
108-
109160
class NamespaceVisitor : AbstractAstVisitor
110161
{
111162
public override object VisitNamespaceDeclaration(ICSharpCode.NRefactory.Ast.NamespaceDeclaration namespaceDeclaration, object data)
112163
{
113-
VisitorData visitorData = (VisitorData)data;
164+
var visitorData = (VisitorData)data;
114165
visitorData.CurrentNamespaces.Push(namespaceDeclaration.Name);
115166
// Visit children (E.g. TypeDcelarion objects)
116167
namespaceDeclaration.AcceptChildren(this, visitorData);
117168
visitorData.CurrentNamespaces.Pop();
118-
119169
return null;
120170
}
121171

122172
public override object VisitTypeDeclaration(ICSharpCode.NRefactory.Ast.TypeDeclaration typeDeclaration, object data)
123173
{
124-
VisitorData visitorData = (VisitorData)data;
174+
var visitorData = (VisitorData)data;
125175
if (typeDeclaration.Name == visitorData.TargetClassName)
126176
{
127-
string fullNamespace = string.Empty;
128-
foreach (string ns in visitorData.CurrentNamespaces)
177+
var fullNamespace = string.Empty;
178+
foreach (var ns in visitorData.CurrentNamespaces)
129179
{
130180
if (fullNamespace == string.Empty)
131181
fullNamespace = ns;

0 commit comments

Comments
 (0)