Skip to content

Commit ba5f30b

Browse files
author
Unity Technologies
committed
Unity 2019.2.0b2 C# reference source code
1 parent eea3fd5 commit ba5f30b

11 files changed

Lines changed: 109 additions & 58 deletions

File tree

Editor/Mono/GUIView.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ namespace UnityEditor
1717
[StructLayout(LayoutKind.Sequential)]
1818
internal partial class GUIView : View
1919
{
20+
[InitializeOnLoad]
21+
static class EditorShaderLoader
22+
{
23+
static EditorShaderLoader()
24+
{
25+
// TODO: Remove this once case 1148851 has been fixed.
26+
UnityEngine.UIElements.UIR.UIRenderDevice.editorShader = EditorShader;
27+
}
28+
}
29+
2030
internal static event Action<GUIView> positionChanged = null;
2131

2232
Panel m_Panel = null;

Editor/Mono/Inspector/PreviewRenderUtility.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public void BeginPreview(Rect r, GUIStyle previewBackground)
221221
{
222222
Texture defaultEnvTexture = ReflectionProbe.defaultTexture;
223223

224-
if (Unsupported.SetOverrideRenderSettings(previewScene.scene))
224+
if (Unsupported.SetOverrideLightingSettings(previewScene.scene))
225225
{
226226
RenderSettings.ambientMode = AmbientMode.Flat;
227227
RenderSettings.ambientLight = ambientColor;
@@ -260,7 +260,7 @@ public void BeginStaticPreview(Rect r)
260260
{
261261
var oldProbe = RenderSettings.ambientProbe;
262262
Texture defaultEnvTexture = ReflectionProbe.defaultTexture;
263-
if (Unsupported.SetOverrideRenderSettings(previewScene.scene))
263+
if (Unsupported.SetOverrideLightingSettings(previewScene.scene))
264264
{
265265
// Most preview windows just want the light probe from the main scene so by default we copy it here. It can then be overridden if user wants.
266266
RenderSettings.ambientProbe = oldProbe;
@@ -338,7 +338,7 @@ public void BeginPreviewHDR(Rect r, GUIStyle previewBackground)
338338

339339
public Texture EndPreview()
340340
{
341-
Unsupported.RestoreOverrideRenderSettings();
341+
Unsupported.RestoreOverrideLightingSettings();
342342

343343
m_SavedState.Restore();
344344
FinishFrame();
@@ -347,7 +347,7 @@ public Texture EndPreview()
347347

348348
private void FinishFrame()
349349
{
350-
Unsupported.RestoreOverrideRenderSettings();
350+
Unsupported.RestoreOverrideLightingSettings();
351351
foreach (var light in lights)
352352
light.enabled = false;
353353
}
@@ -366,7 +366,7 @@ internal static void DrawPreview(Rect r, Texture texture)
366366
public Texture2D EndStaticPreview()
367367
{
368368
if (!EditorApplication.isUpdating)
369-
Unsupported.RestoreOverrideRenderSettings();
369+
Unsupported.RestoreOverrideLightingSettings();
370370

371371
var tmp = RenderTexture.GetTemporary((int)m_TargetRect.width, (int)m_TargetRect.height, 0, GraphicsFormat.R8G8B8A8_UNorm);
372372

Editor/Mono/SceneManagement/StageManager/PrefabStage/PrefabStageUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ static void AppendEnvironmentName(Transform transform, object userData)
311311
static Scene CreateDefaultPreviewScene()
312312
{
313313
Scene previewScene = EditorSceneManager.NewPreviewScene();
314-
Unsupported.SetOverrideRenderSettings(previewScene);
314+
Unsupported.SetOverrideLightingSettings(previewScene);
315315

316316
// Setup default render settings for this preview scene
317317
UnityEngine.RenderSettings.defaultReflectionMode = UnityEngine.Rendering.DefaultReflectionMode.Custom;
318318
UnityEngine.RenderSettings.customReflection = GetDefaultReflection(); // ensure chrome materials do not render balck
319319
UnityEngine.RenderSettings.skybox = null; // do not use skybox for the default previewscene, we want the flat Prefab Mode background color to let it stand out from normal scenes
320320
UnityEngine.RenderSettings.ambientMode = AmbientMode.Trilight; // do not use skybox ambient but simple trilight ambient for simplicity
321-
Unsupported.RestoreOverrideRenderSettings();
321+
Unsupported.RestoreOverrideLightingSettings();
322322

323323
return previewScene;
324324
}

Editor/Mono/SceneManagement/StageManager/StageUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace UnityEditor.SceneManagement
1313
{
1414
public static partial class StageUtility
1515
{
16-
[Shortcut("Stage/Go Back", KeyCode.H)]
16+
[Shortcut("Stage/Go Back")]
1717
static void GoBackShortcut()
1818
{
1919
StageUtility.GoBackToPreviousStage();

Editor/Mono/SceneView/SceneView.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,7 +2296,7 @@ protected virtual void OnGUI()
22962296
// Use custom scene RenderSettings (if currently showing a custom scene)
22972297
bool restoreOverrideRenderSettings = false;
22982298
if (m_CustomScene.IsValid())
2299-
restoreOverrideRenderSettings = Unsupported.SetOverrideRenderSettings(m_CustomScene);
2299+
restoreOverrideRenderSettings = Unsupported.SetOverrideLightingSettings(m_CustomScene);
23002300

23012301
SetupCustomSceneLighting();
23022302

@@ -2332,7 +2332,7 @@ protected virtual void OnGUI()
23322332
CleanupCustomSceneLighting();
23332333

23342334
if (restoreOverrideRenderSettings)
2335-
Unsupported.RestoreOverrideRenderSettings();
2335+
Unsupported.RestoreOverrideLightingSettings();
23362336

23372337
//Ensure that the target texture is clamped [0-1]
23382338
//This is needed because otherwise gizmo rendering gets all

Editor/Mono/SceneVisibilityManager.cs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,28 @@ namespace UnityEditor
1515
{
1616
public class SceneVisibilityManager : ScriptableSingleton<SceneVisibilityManager>
1717
{
18+
internal class ShortcutContext : IShortcutToolContext
19+
{
20+
public bool active
21+
{
22+
get
23+
{
24+
var focusedWindow = EditorWindow.focusedWindow;
25+
if (focusedWindow != null)
26+
{
27+
return (focusedWindow.GetType() == typeof(SceneView) ||
28+
focusedWindow.GetType() == typeof(SceneHierarchyWindow));
29+
}
30+
31+
return false;
32+
}
33+
}
34+
}
35+
36+
private static ShortcutContext s_ShortcutContext;
37+
1838
public static event Action visibilityChanged;
39+
1940
internal static event Action currentStageIsolated;
2041

2142
private readonly static List<GameObject> m_RootBuffer = new List<GameObject>();
@@ -41,6 +62,8 @@ private static void Initialize()
4162
SceneVisibilityState.internalStructureChanged += InternalStructureChanged;
4263
PrefabStage stage = StageNavigationManager.instance.GetCurrentPrefabStage();
4364
SceneVisibilityState.SetPrefabStageScene(stage == null ? default(Scene) : stage.scene);
65+
s_ShortcutContext = new ShortcutContext();
66+
ShortcutIntegration.instance.contextManager.RegisterToolContext(s_ShortcutContext);
4467
}
4568

4669
private static void InternalStructureChanged()
@@ -322,8 +345,8 @@ public bool AreAllDescendantsVisible(GameObject gameObject)
322345
}
323346

324347
//SHORTCUTS
325-
[Shortcut("Scene Visibility/Toggle Selection Visibility")]
326-
static void ToggleSelectionVisibility()
348+
[Shortcut("Scene Visibility/Toggle Visibility for Selection")]
349+
private static void ToggleSelectionVisibility()
327350
{
328351
if (Selection.gameObjects.Length > 0)
329352
{
@@ -337,14 +360,14 @@ static void ToggleSelectionVisibility()
337360

338361
shouldHide = false;
339362
}
340-
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Selection Visibility");
363+
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Visibility for Selection");
341364
SceneVisibilityState.SetGameObjectsHidden(Selection.gameObjects, shouldHide, false);
342365
instance.VisibilityChanged();
343366
}
344367
}
345368

346-
[Shortcut("Scene Visibility/Toggle Selection And Descendants Visibility")]
347-
static void ToggleSelectionAndDescendantsVisibility()
369+
[Shortcut("Scene Visibility/Toggle Visibility for Selection and Children", typeof(ShortcutContext), KeyCode.H)]
370+
private static void ToggleSelectionAndDescendantsVisibility()
348371
{
349372
if (Selection.gameObjects.Length > 0)
350373
{
@@ -358,7 +381,7 @@ static void ToggleSelectionAndDescendantsVisibility()
358381

359382
shouldHide = false;
360383
}
361-
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Visibility And Children");
384+
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Visibility for Selection and Children");
362385
SceneVisibilityState.SetGameObjectsHidden(Selection.gameObjects, shouldHide, true);
363386
instance.VisibilityChanged();
364387
}
@@ -425,20 +448,20 @@ private static void RevertIsolationCurrentStage()
425448
}
426449

427450
[Shortcut("Scene Visibility/Exit Isolation")]
428-
static void ExitIsolationShortcut()
451+
private static void ExitIsolationShortcut()
429452
{
430453
instance.ExitIsolation();
431454
}
432455

433-
[Shortcut("Scene Visibility/Toggle Selection And Descendants")]
456+
[Shortcut("Scene Visibility/Toggle Isolation for Selection and Children", typeof(ShortcutContext), KeyCode.H, ShortcutModifiers.Shift)]
434457
static void ToggleIsolateSelectionAndDescendantsShortcut()
435458
{
436459
instance.ToggleIsolateSelectionAndDescendants();
437460
}
438461

439462
internal void ToggleIsolateSelectionAndDescendants()
440463
{
441-
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Isolation on Selection And Children");
464+
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Isolation for Selection and Children");
442465

443466
if (!IsCurrentStageIsolated())
444467
{
@@ -459,15 +482,15 @@ internal void ToggleIsolateSelectionAndDescendants()
459482
}
460483
}
461484

462-
[Shortcut("Scene Visibility/Toggle Isolation on Selection")]
485+
[Shortcut("Scene Visibility/Toggle Isolation for Selection")]
463486
static void ToggleIsolateSelectionShortcut()
464487
{
465488
instance.ToggleIsolateSelection();
466489
}
467490

468491
internal void ToggleIsolateSelection()
469492
{
470-
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Isolation on Selection");
493+
Undo.RecordObject(SceneVisibilityState.GetInstance(), "Toggle Isolation for Selection");
471494

472495
if (!IsCurrentStageIsolated())
473496
{

Editor/Mono/Unsupported.bindings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public static bool IsDeveloperBuild()
7878
[FreeFunction("GetScreenManager().SetAllowCursorLock")]
7979
internal static extern void SetAllowCursorLock(bool allow, DisallowCursorLockReasons reasons);
8080

81-
public static bool SetOverrideRenderSettings(Scene scene)
81+
public static bool SetOverrideLightingSettings(Scene scene)
8282
{
83-
return SetOverrideRenderSettingsInternal(scene.handle);
83+
return SetOverrideLightingSettingsInternal(scene.handle);
8484
}
8585

86-
internal static extern bool SetOverrideRenderSettingsInternal(int sceneHandle);
86+
internal static extern bool SetOverrideLightingSettingsInternal(int sceneHandle);
8787

8888

89-
public static extern void RestoreOverrideRenderSettings();
89+
public static extern void RestoreOverrideLightingSettings();
9090

9191
[FreeFunction("GetRenderSettings().SetUseFogNoDirty")]
9292
public static extern void SetRenderSettingsUseFogNoDirty(bool fog);

Modules/ShortcutManagerEditor/ShortcutController.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ static void InitializeController()
9191
var bindingValidator = new BindingValidator();
9292
var invalidContextReporter = new DiscoveryInvalidShortcutReporter();
9393
var discovery = new Discovery(shortcutProviders, bindingValidator, invalidContextReporter);
94-
instance = new ShortcutController(discovery, bindingValidator, new ShortcutProfileStore(), new LastUsedProfileIdProvider());
94+
IContextManager contextManager = null;
95+
96+
if (instance != null)
97+
{
98+
contextManager = instance.contextManager;
99+
}
100+
101+
if (contextManager == null)
102+
{
103+
contextManager = new ContextManager();
104+
}
105+
106+
instance = new ShortcutController(discovery, contextManager, bindingValidator, new ShortcutProfileStore(), new LastUsedProfileIdProvider());
95107
instance.trigger.invokingAction += OnInvokingAction;
96108
}
97109

@@ -115,14 +127,14 @@ class ShortcutController : IAvailableShortcutsChangedNotifier
115127
public IBindingValidator bindingValidator { get; }
116128
public Trigger trigger { get; }
117129

118-
ContextManager m_ContextManager = new ContextManager();
130+
IContextManager m_ContextManager;
119131

120132
public IContextManager contextManager => m_ContextManager;
121133
ILastUsedProfileIdProvider m_LastUsedProfileIdProvider;
122134

123135
public event Action availableShortcutsChanged;
124136

125-
public ShortcutController(IDiscovery discovery, IBindingValidator bindingValidator, IShortcutProfileStore profileStore, ILastUsedProfileIdProvider lastUsedProfileIdProvider)
137+
public ShortcutController(IDiscovery discovery, IContextManager contextManager, IBindingValidator bindingValidator, IShortcutProfileStore profileStore, ILastUsedProfileIdProvider lastUsedProfileIdProvider)
126138
{
127139
m_Discovery = discovery;
128140
this.bindingValidator = bindingValidator;
@@ -136,6 +148,7 @@ public ShortcutController(IDiscovery discovery, IBindingValidator bindingValidat
136148
var conflictResolverView = new ConflictResolverView();
137149
var conflictResolver = new ConflictResolver(profileManager, contextManager, conflictResolverView);
138150

151+
m_ContextManager = contextManager;
139152

140153
m_Directory = new Directory(profileManager.GetAllShortcuts());
141154
trigger = new Trigger(m_Directory, conflictResolver);

Modules/UIElements/Renderer/UIRUtility.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,5 @@ public static void Destroy(Object obj)
3737
else
3838
Object.DestroyImmediate(obj);
3939
}
40-
41-
public static bool GetOpenGLCoreVersion(out int major, out int minor)
42-
{
43-
var version = SystemInfo.graphicsDeviceVersion;
44-
var rx = new Regex(@"OpenGL( *)[0-9].[0-9]");
45-
var matches = rx.Matches(version);
46-
if (matches.Count == 0)
47-
{
48-
major = minor = -1;
49-
return false;
50-
}
51-
var match = matches[0].Value;
52-
major = match[match.Length - 3] - '0';
53-
minor = match[match.Length - 1] - '0';
54-
return true;
55-
}
5640
}
5741
}

Modules/UIElements/Renderer/UIRenderer/UIRenderDevice.cs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public void Dispose()
136136
static CustomSampler s_FenceSampler = CustomSampler.Create("UIR.WaitOnFence");
137137
static CustomSampler s_BeforeDrawSampler = CustomSampler.Create("UIR.BeforeDraw");
138138

139+
static bool? s_ComputeIsAvailable;
140+
const string k_ComputeIsAvailableTag = "UIE_ComputeIsAvailable";
141+
const string k_ComputeIsAvailableTrue = "1";
142+
139143

140144
static UIRenderDevice()
141145
{
@@ -193,13 +197,42 @@ private UIRenderDevice(Shader defaultMaterialShader, uint initialVertexCapacity,
193197
SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;
194198
}
195199

200+
// TODO: Remove this once case 1148851 has been fixed.
201+
static internal Shader editorShader = null;
202+
203+
/// <summary>
204+
/// Indicates whether the active subshader of the stock shader has compute capability. Derived shaders are
205+
/// expected to work as the stock shader in that regard.
206+
/// </summary>
207+
bool ComputeIsAvailable
208+
{
209+
get
210+
{
211+
if (!s_ComputeIsAvailable.HasValue)
212+
{
213+
// Remove this workaround once case 1148851 has been fixed. In the editor, subshaders aren't stripped
214+
// according to the graphic device capabilities unless the shader is precompiled. Querying tags will
215+
// always return the tags from the first subshader. The editor shader is precompiled and doesn't
216+
// suffer this issue, so we can use it as a reference.
217+
var stockDefaultShader = editorShader;
218+
var stockDefaultMaterial = new Material(stockDefaultShader);
219+
string tagValue = stockDefaultMaterial.GetTag(k_ComputeIsAvailableTag, false);
220+
UIRUtility.Destroy(stockDefaultMaterial);
221+
s_ComputeIsAvailable = tagValue == k_ComputeIsAvailableTrue;
222+
}
223+
224+
return s_ComputeIsAvailable.Value;
225+
}
226+
}
227+
196228
void CompleteCreation()
197229
{
198230
if (m_DrawRanges.IsCreated)
199231
return;
200232

201233
var initialTransformCapacity = m_LazyCreationInitialTransformCapacity;
202-
bool unlimitedTransformCount = SystemInfo.supportsComputeShaders && !OpenGLCoreBelow45();
234+
235+
bool unlimitedTransformCount = ComputeIsAvailable;
203236
if (!unlimitedTransformCount)
204237
// This should be in sync with the fallback value of UIE_SKIN_ELEMS_COUNT_MAX_CONSTANTS in UnityUIE.cginc (minus one for the identity matrix)
205238
initialTransformCapacity = 19;
@@ -568,18 +601,6 @@ public Material GetStandardMaterial()
568601
return m_DefaultMaterial;
569602
}
570603

571-
static bool OpenGLCoreBelow45()
572-
{
573-
int maj, min;
574-
if (UIRUtility.GetOpenGLCoreVersion(out maj, out min))
575-
{
576-
if (maj == 4)
577-
return min < 5;
578-
return maj < 4;
579-
}
580-
else return false;
581-
}
582-
583604
static void SetupStandardMaterial(Material material, DrawingModes mode)
584605
{
585606
const CompareFunction compFront = CompareFunction.Always;

0 commit comments

Comments
 (0)