Skip to content

Commit c37adb1

Browse files
author
Unity Technologies
committed
Unity 2017.4.10f1 C# reference source code
1 parent 4134799 commit c37adb1

File tree

9 files changed

+194
-51
lines changed

9 files changed

+194
-51
lines changed

Editor/Mono/Inspector/CanvasEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void AllRootCanvases()
126126
{
127127
if (PlayerSettings.virtualRealitySupported && (m_RenderMode.enumValueIndex == (int)RenderMode.ScreenSpaceOverlay))
128128
{
129-
EditorGUILayout.HelpBox("Using a render mode of ScreenSpaceOverlay while VR is enabled is not recommended for an optimal VR experience", MessageType.Warning);
129+
EditorGUILayout.HelpBox("Using a render mode of ScreenSpaceOverlay while VR is enabled will cause the Canvas to continue to incur a rendering cost, even though the Canvas will not be visible in VR.", MessageType.Warning);
130130
}
131131

132132
EditorGUILayout.PropertyField(m_RenderMode);

Editor/Mono/ProjectBrowser.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,11 @@ bool useTreeViewSelectionInsteadOfMainSelection
169169
[System.NonSerialized]
170170
public GUIContent m_SearchAssetStore = new GUIContent("Asset Store"); // updated when needed
171171

172+
[System.NonSerialized]
173+
private string m_lastSearchFilter;
174+
[System.NonSerialized]
175+
private double m_NextSearch = double.MaxValue;
176+
172177
ProjectBrowser()
173178
{
174179
}
@@ -1335,6 +1340,18 @@ void OnInspectorUpdate()
13351340
{
13361341
if (m_ListArea != null)
13371342
m_ListArea.OnInspectorUpdate();
1343+
1344+
1345+
// if it's time for a search we do it
1346+
if (EditorApplication.timeSinceStartup > m_NextSearch)
1347+
{
1348+
//Perform the Search
1349+
m_NextSearch = double.MaxValue;
1350+
m_SearchFilter.SearchFieldStringToFilter(m_SearchFieldText);
1351+
SyncFilterGUI();
1352+
TopBarSearchSettingsChanged();
1353+
Repaint();
1354+
}
13381355
}
13391356

13401357
void OnDestroy()
@@ -2112,15 +2129,14 @@ void SearchField()
21122129
}
21132130
}
21142131

2115-
string searchFilter = EditorGUI.ToolbarSearchField(searchFieldControlID, rect, m_SearchFieldText, false);
2116-
if (searchFilter != m_SearchFieldText || m_FocusSearchField)
2132+
m_lastSearchFilter = EditorGUI.ToolbarSearchField(searchFieldControlID, rect, m_SearchFieldText, false);
2133+
2134+
if (m_lastSearchFilter != m_SearchFieldText || m_FocusSearchField)
21172135
{
21182136
// Update filter with string
2119-
m_SearchFieldText = searchFilter;
2120-
m_SearchFilter.SearchFieldStringToFilter(m_SearchFieldText);
2121-
SyncFilterGUI();
2122-
TopBarSearchSettingsChanged();
2123-
Repaint();
2137+
m_SearchFieldText = m_lastSearchFilter;
2138+
2139+
m_NextSearch = EditorApplication.timeSinceStartup + SearchableEditorWindow.k_SearchTimerDelaySecs;
21242140
}
21252141
}
21262142

Editor/Mono/ProjectWindow/SearchableEditorWindow.cs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
44

55
using UnityEngine;
6-
using UnityEditor;
7-
using UnityEditorInternal;
86
using System.Collections.Generic;
7+
using Object = UnityEngine.Object;
98

109
namespace UnityEditor
1110
{
@@ -60,6 +59,10 @@ internal static SearchFilter CreateFilter(string searchString, SearchMode search
6059
bool m_HasSearchFilterFocus = false;
6160
int m_SearchFieldControlId;
6261

62+
internal const float k_SearchTimerDelaySecs = 0.250f;
63+
private double m_NextSearch = double.MaxValue;
64+
65+
6366
[MenuItem("Assets/Find References In Scene", false, 25)]
6467
private static void OnSearchForReferences()
6568
{
@@ -92,6 +95,17 @@ virtual public void OnDisable()
9295
searchableWindows.Remove(this);
9396
}
9497

98+
void OnInspectorUpdate()
99+
{
100+
// if it's time for a search we do it
101+
if (EditorApplication.timeSinceStartup > m_NextSearch)
102+
{
103+
m_NextSearch = double.MaxValue;
104+
Repaint();
105+
EditorApplication.Internal_CallSearchHasChanged();
106+
}
107+
}
108+
95109
internal bool hasSearchFilter
96110
{
97111
get { return m_SearchFilter != ""; }
@@ -127,7 +141,7 @@ internal static void SearchForReferencesToInstanceID(int instanceID)
127141
{
128142
if (sw.m_HierarchyType == HierarchyType.GameObjects)
129143
{
130-
sw.SetSearchFilter(searchFilter, SearchMode.All, false);
144+
sw.SetSearchFilter(searchFilter, SearchMode.All, false, false);
131145
sw.m_HasSearchFilterFocus = true;
132146
sw.Repaint();
133147
}
@@ -141,7 +155,7 @@ internal void FocusSearchField()
141155

142156
internal void ClearSearchFilter()
143157
{
144-
SetSearchFilter("", m_SearchMode, true);
158+
SetSearchFilter("", m_SearchMode, true, false);
145159
// Reset current editor. This is needed, so if the user types into a search field, and then
146160
// a new object is selected, which is not in the filter, with the editor still having keyboard focus,
147161
// the search field gets properly cleared.
@@ -174,7 +188,7 @@ internal void SelectNextSearchResult()
174188
}
175189
}
176190

177-
internal virtual void SetSearchFilter(string searchFilter, SearchMode mode, bool setAll)
191+
internal virtual void SetSearchFilter(string searchFilter, SearchMode mode, bool setAll, bool delayed)
178192
{
179193
m_SearchMode = mode;
180194
m_SearchFilter = searchFilter;
@@ -183,12 +197,21 @@ internal virtual void SetSearchFilter(string searchFilter, SearchMode mode, bool
183197
{
184198
foreach (SearchableEditorWindow sw in searchableWindows)
185199
{
186-
if (sw != this && sw.m_HierarchyType == m_HierarchyType && sw.m_HierarchyType != HierarchyType.Assets)
187-
sw.SetSearchFilter(m_SearchFilter, m_SearchMode, false);
200+
if (sw != this && sw.m_HierarchyType == m_HierarchyType &&
201+
sw.m_HierarchyType != HierarchyType.Assets)
202+
sw.SetSearchFilter(m_SearchFilter, m_SearchMode, false, delayed);
188203
}
189204
}
190-
Repaint();
191-
EditorApplication.Internal_CallSearchHasChanged();
205+
206+
if (delayed)
207+
{
208+
m_NextSearch = EditorApplication.timeSinceStartup + k_SearchTimerDelaySecs;
209+
}
210+
else
211+
{
212+
Repaint();
213+
EditorApplication.Internal_CallSearchHasChanged();
214+
}
192215
}
193216

194217
internal virtual void ClickedSearchField()
@@ -218,22 +241,22 @@ internal void SearchFieldGUI(float maxWidth)
218241
int searchMode = (int)m_SearchMode;
219242

220243
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape && GUI.GetNameOfFocusedControl() == "SearchFilter")
221-
SetSearchFilter("", (SearchMode)searchMode, true);
244+
SetSearchFilter("", (SearchMode)searchMode, true, true);
222245

223246
string[] enumStrings = System.Enum.GetNames(m_HierarchyType == HierarchyType.GameObjects ? typeof(SearchModeHierarchyWindow) : typeof(SearchMode));
224247
m_SearchFieldControlId = GUIUtility.GetControlID(s_SearchableEditorWindowSearchField, FocusType.Keyboard, rect);
225248

226249
EditorGUI.BeginChangeCheck();
227250
string searchFilter = EditorGUI.ToolbarSearchField(m_SearchFieldControlId, rect, enumStrings, ref searchMode, m_SearchFilter);
228251
if (EditorGUI.EndChangeCheck())
229-
SetSearchFilter(searchFilter, (SearchMode)searchMode, true);
252+
SetSearchFilter(searchFilter, (SearchMode)searchMode, true, true);
230253

231254
m_HasSearchFilterFocus = GUIUtility.keyboardControl == m_SearchFieldControlId;
232255

233256
if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape && m_SearchFilter != "" && GUIUtility.hotControl == 0)
234257
{
235258
m_SearchFilter = "";
236-
SetSearchFilter(searchFilter, (SearchMode)searchMode, true);
259+
SetSearchFilter(searchFilter, (SearchMode)searchMode, true, true);
237260
Event.current.Use();
238261
m_HasSearchFilterFocus = false;
239262
}

Editor/Mono/SceneHierarchyWindow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,9 +637,9 @@ void DoToolbar()
637637
GUILayout.EndHorizontal();
638638
}
639639

640-
internal override void SetSearchFilter(string searchFilter, SearchableEditorWindow.SearchMode searchMode, bool setAll)
640+
internal override void SetSearchFilter(string searchFilter, SearchableEditorWindow.SearchMode searchMode, bool setAll, bool delayed = false)
641641
{
642-
base.SetSearchFilter(searchFilter, searchMode, setAll);
642+
base.SetSearchFilter(searchFilter, searchMode, setAll, delayed);
643643

644644
// If the user clears the search we frame the last selection he made during the search
645645
if (m_DidSelectSearchResult && string.IsNullOrEmpty(searchFilter))

Editor/Mono/SceneView/SceneView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ public static void RepaintAll()
383383
}
384384
}
385385

386-
internal override void SetSearchFilter(string searchFilter, SearchMode mode, bool setAll)
386+
internal override void SetSearchFilter(string searchFilter, SearchMode mode, bool setAll, bool delayed = false)
387387
{
388388
if (m_SearchFilter == "" || searchFilter == "")
389389
m_StartSearchFilterTime = EditorApplication.timeSinceStartup;
390390

391-
base.SetSearchFilter(searchFilter, mode, setAll);
391+
base.SetSearchFilter(searchFilter, mode, setAll, delayed);
392392
}
393393

394394
internal void OnLostFocus()

Editor/Mono/Scripting/ScriptCompilation/EditorBuildRules.cs

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

55
using System;
66
using System.Collections.Generic;
7+
using System.Globalization;
78
using System.Linq;
89
using UnityEditor.Scripting.Compilers;
910
using File = System.IO.File;
@@ -32,6 +33,7 @@ internal class TargetAssembly
3233
public string Filename { get; private set; }
3334
public SupportedLanguage Language { get; set; }
3435
public AssemblyFlags Flags { get; private set; }
36+
public string PathPrefix { get; private set; }
3537
public Func<string, int> PathFilter { get; private set; }
3638
public Func<BuildTarget, EditorScriptCompilationOptions, bool> IsCompatibleFunc { get; private set; }
3739
public List<TargetAssembly> References { get; private set; }
@@ -42,17 +44,18 @@ public TargetAssembly()
4244
References = new List<TargetAssembly>();
4345
}
4446

45-
public TargetAssembly(string name, SupportedLanguage language, AssemblyFlags flags, TargetAssemblyType type)
46-
: this(name, language, flags, type, null, null)
47-
{
48-
}
49-
50-
public TargetAssembly(string name, SupportedLanguage language, AssemblyFlags flags, TargetAssemblyType type,
51-
Func<string, int> pathFilter, Func<BuildTarget, EditorScriptCompilationOptions, bool> compatFunc) : this()
47+
public TargetAssembly(string name,
48+
SupportedLanguage language,
49+
AssemblyFlags flags,
50+
TargetAssemblyType type,
51+
string pathPrefix,
52+
Func<string, int> pathFilter,
53+
Func<BuildTarget, EditorScriptCompilationOptions, bool> compatFunc) : this()
5254
{
5355
Language = language;
5456
Filename = name;
5557
Flags = flags;
58+
PathPrefix = pathPrefix;
5659
PathFilter = pathFilter;
5760
IsCompatibleFunc = compatFunc;
5861
Type = type;
@@ -145,6 +148,35 @@ public static PrecompiledAssembly CreateEditorCompiledAssembly(string path)
145148
};
146149
}
147150

151+
internal static bool FastStartsWith(string str, string prefix, string prefixLowercase)
152+
{
153+
int strLength = str.Length;
154+
int prefixLength = prefix.Length;
155+
156+
if (prefixLength > strLength)
157+
return false;
158+
159+
int lastPrefixCharIndex = prefixLength - 1;
160+
161+
// Check last char in prefix is equal. Since we are comparing
162+
// file paths against directory paths, the last char will be '/'.
163+
if (str[lastPrefixCharIndex] != prefix[lastPrefixCharIndex])
164+
return false;
165+
166+
for (int i = 0; i < prefixLength; ++i)
167+
{
168+
if (str[i] == prefix[i])
169+
continue;
170+
171+
char strC = char.ToLower(str[i], CultureInfo.InvariantCulture);
172+
173+
if (strC != prefixLowercase[i])
174+
return false;
175+
}
176+
177+
return true;
178+
}
179+
148180
public static TargetAssembly[] CreateTargetAssemblies(IEnumerable<CustomScriptAssembly> customScriptAssemblies)
149181
{
150182
if (customScriptAssemblies == null)
@@ -162,13 +194,18 @@ public static TargetAssembly[] CreateTargetAssemblies(IEnumerable<CustomScriptAs
162194
var targetAssemblies = new List<TargetAssembly>();
163195
var nameToTargetAssembly = new Dictionary<string, TargetAssembly>();
164196

197+
165198
// Create TargetAssemblies
166199
foreach (var customAssembly in customScriptAssemblies)
167200
{
168-
var pathPrefixLowerCase = customAssembly.PathPrefix.ToLower();
169-
170-
var targetAssembly = new TargetAssembly(customAssembly.Name + ".dll", null, customAssembly.AssemblyFlags,
171-
TargetAssemblyType.Custom, path => path.StartsWith(pathPrefixLowerCase) ? pathPrefixLowerCase.Length : -1,
201+
var lowerPathPrefix = customAssembly.PathPrefix.ToLower(CultureInfo.InvariantCulture);
202+
203+
var targetAssembly = new TargetAssembly(customAssembly.Name + ".dll",
204+
null,
205+
customAssembly.AssemblyFlags,
206+
TargetAssemblyType.Custom,
207+
customAssembly.PathPrefix,
208+
path => FastStartsWith(path, customAssembly.PathPrefix, lowerPathPrefix) ? customAssembly.PathPrefix.Length : -1,
172209
(BuildTarget target, EditorScriptCompilationOptions options) => customAssembly.IsCompatibleWith(target, options));
173210

174211
targetAssemblies.Add(targetAssembly);
@@ -607,17 +644,37 @@ internal static TargetAssembly[] CreatePredefinedTargetAssemblies()
607644
{
608645
var languageName = language.GetLanguageName();
609646

610-
var runtimeFirstPass = new TargetAssembly("Assembly-" + languageName + "-firstpass" + ".dll", language,
611-
AssemblyFlags.FirstPass, TargetAssemblyType.Predefined, FilterAssemblyInFirstpassFolder, null);
612-
613-
var runtime = new TargetAssembly("Assembly-" + languageName + ".dll", language, AssemblyFlags.None, TargetAssemblyType.Predefined);
614-
615-
var editorFirstPass = new TargetAssembly("Assembly-" + languageName + "-Editor-firstpass" + ".dll", language,
616-
AssemblyFlags.EditorOnly | AssemblyFlags.FirstPass, TargetAssemblyType.Predefined, FilterAssemblyInFirstpassEditorFolder,
647+
var runtimeFirstPass = new TargetAssembly("Assembly-" + languageName + "-firstpass" + ".dll",
648+
language,
649+
AssemblyFlags.FirstPass,
650+
TargetAssemblyType.Predefined,
651+
null,
652+
FilterAssemblyInFirstpassFolder,
653+
null);
654+
655+
var runtime = new TargetAssembly("Assembly-" + languageName + ".dll",
656+
language,
657+
AssemblyFlags.None,
658+
TargetAssemblyType.Predefined,
659+
null,
660+
null,
661+
null);
662+
663+
var editorFirstPass = new TargetAssembly("Assembly-" + languageName + "-Editor-firstpass" + ".dll",
664+
language,
665+
AssemblyFlags.EditorOnly | AssemblyFlags.FirstPass,
666+
TargetAssemblyType.Predefined,
667+
null,
668+
FilterAssemblyInFirstpassEditorFolder,
617669
IsCompatibleWithEditor);
618670

619-
var editor = new TargetAssembly("Assembly-" + languageName + "-Editor" + ".dll", language,
620-
AssemblyFlags.EditorOnly, TargetAssemblyType.Predefined, FilterAssemblyInEditorFolder, IsCompatibleWithEditor);
671+
var editor = new TargetAssembly("Assembly-" + languageName + "-Editor" + ".dll",
672+
language,
673+
AssemblyFlags.EditorOnly,
674+
TargetAssemblyType.Predefined,
675+
null,
676+
FilterAssemblyInEditorFolder,
677+
IsCompatibleWithEditor);
621678

622679
runtimeFirstPassAssemblies.Add(runtimeFirstPass);
623680
runtimeAssemblies.Add(runtime);
@@ -702,11 +759,16 @@ internal static TargetAssembly GetCustomTargetAssembly(string scriptPath, string
702759

703760
// CustomScriptAssembly paths are absolute, so we convert the scriptPath to an absolute path, if necessary.
704761
bool isPathAbsolute = AssetPath.IsPathRooted(scriptPath);
705-
var lowerFullPath = isPathAbsolute ? AssetPath.GetFullPath(scriptPath).ToLower() : AssetPath.Combine(projectDirectory, scriptPath).ToLower();
762+
var fullPath = isPathAbsolute ? AssetPath.GetFullPath(scriptPath) : AssetPath.Combine(projectDirectory, scriptPath);
706763

707764
foreach (var assembly in customTargetAssemblies)
708765
{
709-
int pathDepth = assembly.PathFilter(lowerFullPath);
766+
int maxPathDepth = assembly.PathPrefix.Length;
767+
768+
if (maxPathDepth <= highestPathDepth)
769+
continue;
770+
771+
int pathDepth = assembly.PathFilter(fullPath);
710772

711773
if (pathDepth <= highestPathDepth)
712774
continue;
@@ -748,15 +810,15 @@ static int FilterAssemblyInFirstpassEditorFolder(string pathName)
748810
static int FilterAssemblyInEditorFolder(string pathName)
749811
{
750812
const string editorSegment = "/editor/";
751-
int editorSegmentIndex = pathName.IndexOf(editorSegment);
813+
int editorSegmentIndex = pathName.IndexOf(editorSegment, StringComparison.InvariantCulture);
752814
if (editorSegmentIndex == -1) return -1;
753815

754816
return editorSegmentIndex + editorSegment.Length;
755817
}
756818

757-
static int FilterAssemblyPathBeginsWith(string pathName, string prefix)
819+
static int FilterAssemblyPathBeginsWith(string pathName, string lowerPrefix)
758820
{
759-
return pathName.StartsWith(prefix) ? prefix.Length : -1;
821+
return FastStartsWith(pathName, lowerPrefix, lowerPrefix) ? lowerPrefix.Length : -1;
760822
}
761823
}
762824
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Unity 2017.4.9f1 C# reference source code
1+
## Unity 2017.4.10f1 C# reference source code
22

33
The C# part of the Unity engine and editor source code.
44
May be used for reference purposes only.

0 commit comments

Comments
 (0)