@@ -41,11 +41,12 @@ namespace FlaxEngine.GUI
|
||||
protected override void DrawChildren()
|
||||
{
|
||||
// Draw all screen space canvases
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = 0; i < _children.Count; i++)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
|
||||
if (child.Visible && child.Is2D)
|
||||
if (child.Visible && child.Is2D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
child.Draw();
|
||||
}
|
||||
@@ -69,10 +70,11 @@ namespace FlaxEngine.GUI
|
||||
UICanvas.CalculateRay(ref location, out Ray ray);
|
||||
|
||||
// Test 3D
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled && child.Is3D)
|
||||
if (child.Visible && child.Enabled && child.Is3D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
if (child.Intersects3D(ref ray, out var childLocation))
|
||||
{
|
||||
@@ -91,10 +93,11 @@ namespace FlaxEngine.GUI
|
||||
|
||||
// Check all children collisions with mouse and fire events for them
|
||||
bool isFirst3DHandled = false;
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled)
|
||||
if (child.Visible && child.Enabled && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
// Fire events
|
||||
if (child.Is2D)
|
||||
@@ -156,10 +159,11 @@ namespace FlaxEngine.GUI
|
||||
UICanvas.CalculateRay(ref location, out Ray ray);
|
||||
|
||||
// Test 3D
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled && child.Is3D)
|
||||
if (child.Visible && child.Enabled && child.Is3D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
if (child.Intersects3D(ref ray, out var childLocation))
|
||||
{
|
||||
@@ -183,10 +187,11 @@ namespace FlaxEngine.GUI
|
||||
UICanvas.CalculateRay(ref location, out Ray ray);
|
||||
|
||||
// Test 3D
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled && child.Is3D)
|
||||
if (child.Visible && child.Enabled && child.Is3D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
if (child.Intersects3D(ref ray, out var childLocation))
|
||||
{
|
||||
@@ -210,10 +215,11 @@ namespace FlaxEngine.GUI
|
||||
UICanvas.CalculateRay(ref location, out Ray ray);
|
||||
|
||||
// Test 3D
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled && child.Is3D)
|
||||
if (child.Visible && child.Enabled && child.Is3D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
if (child.Intersects3D(ref ray, out var childLocation))
|
||||
{
|
||||
@@ -237,10 +243,11 @@ namespace FlaxEngine.GUI
|
||||
UICanvas.CalculateRay(ref location, out Ray ray);
|
||||
|
||||
// Test 3D
|
||||
var layerMask = MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default;
|
||||
for (int i = _children.Count - 1; i >= 0 && _children.Count > 0; i--)
|
||||
{
|
||||
var child = (CanvasRootControl)_children[i];
|
||||
if (child.Visible && child.Enabled && child.Is3D)
|
||||
if (child.Visible && child.Enabled && child.Is3D && layerMask.HasLayer(child.Canvas.Layer))
|
||||
{
|
||||
if (child.Intersects3D(ref ray, out var childLocation))
|
||||
{
|
||||
|
||||
@@ -74,6 +74,8 @@ namespace FlaxEngine.GUI
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool SkipEvents => !_canvas.ReceivesEvents || !_canvas.IsVisible();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override CursorType Cursor
|
||||
{
|
||||
@@ -197,7 +199,7 @@ namespace FlaxEngine.GUI
|
||||
public override void Update(float deltaTime)
|
||||
{
|
||||
// UI navigation
|
||||
if (_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
{
|
||||
UpdateNavigation(deltaTime, _canvas.NavigateUp.Name, NavDirection.Up, ref _navigationHeldTimeUp, ref _navigationRateTimeUp);
|
||||
UpdateNavigation(deltaTime, _canvas.NavigateDown.Name, NavDirection.Down, ref _navigationHeldTimeDown, ref _navigationRateTimeDown);
|
||||
@@ -267,7 +269,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnCharInput(char c)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnCharInput(c);
|
||||
@@ -276,7 +278,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragDrop(ref Float2 location, DragData data)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return DragDropEffect.None;
|
||||
|
||||
return base.OnDragDrop(ref location, data);
|
||||
@@ -285,7 +287,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragEnter(ref Float2 location, DragData data)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return DragDropEffect.None;
|
||||
|
||||
return base.OnDragEnter(ref location, data);
|
||||
@@ -294,7 +296,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnDragLeave()
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnDragLeave();
|
||||
@@ -303,7 +305,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override DragDropEffect OnDragMove(ref Float2 location, DragData data)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return DragDropEffect.None;
|
||||
|
||||
return base.OnDragMove(ref location, data);
|
||||
@@ -312,7 +314,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnKeyDown(KeyboardKeys key)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnKeyDown(key);
|
||||
@@ -321,7 +323,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnKeyUp(KeyboardKeys key)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnKeyUp(key);
|
||||
@@ -330,7 +332,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnMouseDoubleClick(Float2 location, MouseButton button)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnMouseDoubleClick(location, button);
|
||||
@@ -339,7 +341,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnMouseDown(Float2 location, MouseButton button)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnMouseDown(location, button);
|
||||
@@ -348,7 +350,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnMouseEnter(Float2 location)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
_mousePosition = location;
|
||||
@@ -359,8 +361,7 @@ namespace FlaxEngine.GUI
|
||||
public override void OnMouseLeave()
|
||||
{
|
||||
_mousePosition = Float2.Zero;
|
||||
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnMouseLeave();
|
||||
@@ -369,7 +370,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnMouseMove(Float2 location)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
_mousePosition = location;
|
||||
@@ -379,7 +380,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnMouseUp(Float2 location, MouseButton button)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnMouseUp(location, button);
|
||||
@@ -388,7 +389,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnMouseWheel(Float2 location, float delta)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnMouseWheel(location, delta);
|
||||
@@ -397,7 +398,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnTouchEnter(Float2 location, int pointerId)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnTouchEnter(location, pointerId);
|
||||
@@ -406,7 +407,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnTouchDown(Float2 location, int pointerId)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnTouchDown(location, pointerId);
|
||||
@@ -415,7 +416,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnTouchMove(Float2 location, int pointerId)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnTouchMove(location, pointerId);
|
||||
@@ -424,7 +425,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override bool OnTouchUp(Float2 location, int pointerId)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return false;
|
||||
|
||||
return base.OnTouchUp(location, pointerId);
|
||||
@@ -433,7 +434,7 @@ namespace FlaxEngine.GUI
|
||||
/// <inheritdoc />
|
||||
public override void OnTouchLeave(int pointerId)
|
||||
{
|
||||
if (!_canvas.ReceivesEvents)
|
||||
if (SkipEvents)
|
||||
return;
|
||||
|
||||
base.OnTouchLeave(pointerId);
|
||||
|
||||
@@ -66,6 +66,8 @@ namespace FlaxEngine
|
||||
/// <inheritdoc />
|
||||
public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output)
|
||||
{
|
||||
if (!Canvas.IsVisible(renderContext.View.RenderLayersMask))
|
||||
return;
|
||||
var bounds = Canvas.Bounds;
|
||||
bounds.Transformation.Translation -= renderContext.View.Origin;
|
||||
if (renderContext.View.Frustum.Contains(bounds.GetBoundingBox()) == ContainmentType.Disjoint)
|
||||
@@ -873,6 +875,20 @@ namespace FlaxEngine
|
||||
}
|
||||
}
|
||||
|
||||
internal bool IsVisible()
|
||||
{
|
||||
return IsVisible(MainRenderTask.Instance?.ViewLayersMask ?? LayersMask.Default);
|
||||
}
|
||||
|
||||
internal bool IsVisible(LayersMask layersMask)
|
||||
{
|
||||
#if FLAX_EDITOR
|
||||
if (_editorTask != null || _editorRoot != null)
|
||||
return true;
|
||||
#endif
|
||||
return layersMask.HasLayer(Layer);
|
||||
}
|
||||
|
||||
#if FLAX_EDITOR
|
||||
private SceneRenderTask _editorTask;
|
||||
private ContainerControl _editorRoot;
|
||||
|
||||
Reference in New Issue
Block a user