Merge remote-tracking branch 'origin/master' into 1.6

# Conflicts:
#	Source/Tools/Flax.Build/Build/Builder.Projects.cs
#	Source/Tools/Flax.Build/Build/Plugins/NetworkingPlugin.cs
This commit is contained in:
Wojtek Figat
2023-03-14 11:52:41 +01:00
25 changed files with 545 additions and 196 deletions

View File

@@ -22,7 +22,6 @@ namespace FlaxEditor.Content
/// Json assets proxy.
/// </summary>
/// <seealso cref="FlaxEditor.Content.JsonAssetBaseProxy" />
[ContentContextMenu("New/Json Asset")]
public abstract class JsonAssetProxy : JsonAssetBaseProxy
{
/// <summary>
@@ -127,6 +126,7 @@ namespace FlaxEditor.Content
/// Generic Json assets proxy (supports all json assets that don't have dedicated proxy).
/// </summary>
/// <seealso cref="FlaxEditor.Content.JsonAssetBaseProxy" />
[ContentContextMenu("New/Json Asset")]
public class GenericJsonAssetProxy : JsonAssetProxy
{
/// <inheritdoc />

View File

@@ -327,8 +327,8 @@ bool CookAssetsStep::ProcessDefaultAsset(AssetCookData& options)
{
// Use compact json
rapidjson_flax::StringBuffer buffer;
rapidjson_flax::Writer<rapidjson_flax::StringBuffer> writer(buffer);
asJsonAsset->Document.Accept(writer);
CompactJsonWriter writerObj(buffer);
asJsonAsset->Save(writerObj);
// Store json data in the first chunk
auto chunk = New<FlaxChunk>();

View File

@@ -178,13 +178,13 @@ namespace FlaxEditor.SceneGraph.Actors
// Draw tangent points
if (tangentIn != pos)
{
DebugDraw.DrawLine(pos, tangentIn, Color.White.AlphaMultiplied(0.6f), 0, false);
DebugDraw.DrawWireSphere(new BoundingSphere(tangentIn, 4.0f), Color.White, 0, false);
DebugDraw.DrawLine(pos, tangentIn, Color.Blue.AlphaMultiplied(0.6f), 0, false);
DebugDraw.DrawWireSphere(new BoundingSphere(tangentIn, 4.0f), Color.Blue, 0, false);
}
if (tangentIn != pos)
if (tangentOut != pos)
{
DebugDraw.DrawLine(pos, tangentOut, Color.White.AlphaMultiplied(0.6f), 0, false);
DebugDraw.DrawWireSphere(new BoundingSphere(tangentOut, 4.0f), Color.White, 0, false);
DebugDraw.DrawLine(pos, tangentOut, Color.Red.AlphaMultiplied(0.6f), 0, false);
DebugDraw.DrawWireSphere(new BoundingSphere(tangentOut, 4.0f), Color.Red, 0, false);
}
}

View File

@@ -250,6 +250,9 @@ namespace FlaxEditor.Surface.Archetypes
set => Values[1] = value;
}
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => Context;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{
@@ -288,6 +291,8 @@ namespace FlaxEditor.Surface.Archetypes
private bool _isMouseDown;
private Rectangle _textRect;
private Rectangle _dragAreaRect;
private bool _cursorChanged = false;
private bool _textRectHovered = false;
/// <summary>
/// Gets or sets the first state node identifier for the state machine pointed by the entry node.
@@ -336,7 +341,8 @@ namespace FlaxEditor.Surface.Archetypes
var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0);
titleSize.X += 8.0f;
_dragAreaRect = new Rectangle((Size - titleSize) * 0.5f, titleSize);
var padding = new Float2(8, 8);
_dragAreaRect = new Rectangle(padding, Size - padding * 2);
}
/// <inheritdoc />
@@ -345,10 +351,19 @@ namespace FlaxEditor.Surface.Archetypes
var style = Style.Current;
// Paint Background
BackgroundColor = _isSelected ? Color.OrangeRed : style.BackgroundNormal;
if (_isSelected)
Render2D.DrawRectangle(_textRect, Color.Orange);
BackgroundColor = style.BackgroundNormal;
var dragAreaColor = BackgroundColor / 2.0f;
if (IsMouseOver)
BackgroundColor *= 1.2f;
if (_textRectHovered)
BackgroundColor *= 1.2f;
Render2D.FillRectangle(_textRect, BackgroundColor);
Render2D.FillRectangle(_dragAreaRect, dragAreaColor);
// Push clipping mask
if (ClipChildren)
@@ -382,6 +397,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = true;
Cursor = CursorType.Hand;
_cursorChanged = true;
Focus();
return true;
}
@@ -399,6 +415,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = false;
Cursor = CursorType.Default;
_cursorChanged = false;
Surface.ConnectingEnd(this);
}
@@ -412,6 +429,25 @@ namespace FlaxEditor.Surface.Archetypes
public override void OnMouseMove(Float2 location)
{
Surface.ConnectingOver(this);
if (_dragAreaRect.Contains(location) && !_cursorChanged && !Input.GetMouseButton(MouseButton.Left))
{
Cursor = CursorType.SizeAll;
_cursorChanged = true;
}
else if (!_dragAreaRect.Contains(location) && _cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRect.Contains(location) && !_dragAreaRect.Contains(location) && !_textRectHovered)
{
_textRectHovered = true;
}
else if (_textRectHovered && (!_textRect.Contains(location) || _dragAreaRect.Contains(location)))
{
_textRectHovered = false;
}
base.OnMouseMove(location);
}
@@ -420,6 +456,15 @@ namespace FlaxEditor.Surface.Archetypes
{
base.OnMouseLeave();
if (_cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRectHovered)
_textRectHovered = false;
if (_isMouseDown)
{
_isMouseDown = false;
@@ -606,6 +651,8 @@ namespace FlaxEditor.Surface.Archetypes
private Rectangle _textRect;
private Rectangle _dragAreaRect;
private Rectangle _renameButtonRect;
private bool _cursorChanged = false;
private bool _textRectHovered = false;
/// <summary>
/// The transitions list from this state to the others.
@@ -711,7 +758,8 @@ namespace FlaxEditor.Surface.Archetypes
var width = Mathf.Max(100, titleSize.X + 50);
Resize(width, 0);
titleSize.X += 8.0f;
_dragAreaRect = new Rectangle((Size - titleSize) * 0.5f, titleSize);
var padding = new Float2(8, 8);
_dragAreaRect = new Rectangle(padding, Size - padding * 2);
}
/// <inheritdoc />
@@ -1138,10 +1186,19 @@ namespace FlaxEditor.Surface.Archetypes
var style = Style.Current;
// Paint Background
BackgroundColor = _isSelected ? Color.OrangeRed : style.BackgroundNormal;
if (_isSelected)
Render2D.DrawRectangle(_textRect, Color.Orange);
BackgroundColor = style.BackgroundNormal;
var dragAreaColor = BackgroundColor / 2.0f;
if (IsMouseOver)
BackgroundColor *= 1.2f;
if (_textRectHovered)
BackgroundColor *= 1.2f;
Render2D.FillRectangle(_textRect, BackgroundColor);
Render2D.FillRectangle(_dragAreaRect, dragAreaColor);
// Push clipping mask
if (ClipChildren)
@@ -1194,6 +1251,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = true;
Cursor = CursorType.Hand;
_cursorChanged = true;
Focus();
return true;
}
@@ -1211,6 +1269,7 @@ namespace FlaxEditor.Surface.Archetypes
{
_isMouseDown = false;
Cursor = CursorType.Default;
_cursorChanged = false;
Surface.ConnectingEnd(this);
}
@@ -1231,6 +1290,26 @@ namespace FlaxEditor.Surface.Archetypes
public override void OnMouseMove(Float2 location)
{
Surface.ConnectingOver(this);
if (_dragAreaRect.Contains(location) && !_cursorChanged && !_renameButtonRect.Contains(location) && !_closeButtonRect.Contains(location) && !Input.GetMouseButton(MouseButton.Left))
{
Cursor = CursorType.SizeAll;
_cursorChanged = true;
}
else if ((!_dragAreaRect.Contains(location) || _renameButtonRect.Contains(location) || _closeButtonRect.Contains(location)) && _cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRect.Contains(location) && !_dragAreaRect.Contains(location) && !_textRectHovered)
{
_textRectHovered = true;
}
else if (_textRectHovered && (!_textRect.Contains(location) || _dragAreaRect.Contains(location)))
{
_textRectHovered = false;
}
base.OnMouseMove(location);
}
@@ -1239,6 +1318,15 @@ namespace FlaxEditor.Surface.Archetypes
{
base.OnMouseLeave();
if (_cursorChanged)
{
Cursor = CursorType.Default;
_cursorChanged = false;
}
if (_textRectHovered)
_textRectHovered = false;
if (_isMouseDown)
{
_isMouseDown = false;
@@ -1311,6 +1399,9 @@ namespace FlaxEditor.Surface.Archetypes
set => Values[1] = value;
}
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => Context;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{
@@ -1682,6 +1773,9 @@ namespace FlaxEditor.Surface.Archetypes
set => RuleGraph = value;
}
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => SourceState.Context;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -484,7 +484,7 @@ namespace FlaxEditor.Surface.Archetypes
Title = "Blend with Mask",
Description = "Blend animation poses using skeleton mask",
Flags = NodeFlags.AnimGraph,
Size = new Float2(180, 100),
Size = new Float2(180, 140),
DefaultValues = new object[]
{
0.0f,
@@ -496,7 +496,7 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Input(0, "Pose A", true, typeof(void), 1),
NodeElementArchetype.Factory.Input(1, "Pose B", true, typeof(void), 2),
NodeElementArchetype.Factory.Input(2, "Alpha", true, typeof(float), 3, 0),
NodeElementArchetype.Factory.Asset(100, 20, 1, typeof(SkeletonMask)),
NodeElementArchetype.Factory.Asset(0, 70, 1, typeof(SkeletonMask)),
}
},
new NodeArchetype

View File

@@ -25,6 +25,11 @@ namespace FlaxEditor.Surface
/// </summary>
byte[] SurfaceData { get; set; }
/// <summary>
/// Gets the context which owns this surface context (null for root).
/// </summary>
VisjectSurfaceContext ParentContext { get; }
/// <summary>
/// Called when Visject Surface context gets created for this surface data source. Can be used to link for some events.
/// </summary>

View File

@@ -33,6 +33,14 @@ namespace FlaxEditor.Surface.Undo
CaptureConnections(iB, out _inputBefore);
CaptureConnections(oB, out _outputBefore);
#if BUILD_DEBUG
// Validate handles
if (_context.Get(_surface) != iB.ParentNode.Context)
throw new System.Exception("Invalid ContextHandle");
if (_input.Get(iB.ParentNode.Context) != iB || _output.Get(oB.ParentNode.Context) != oB)
throw new System.Exception("Invalid BoxHandle");
#endif
}
public void End()

View File

@@ -1,7 +1,9 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
using System.Text;
using FlaxEngine;
using FlaxEngine.Json;
namespace FlaxEditor.Surface.Undo
{
@@ -9,7 +11,7 @@ namespace FlaxEditor.Surface.Undo
/// The helper structure for Surface context handle.
/// </summary>
[HideInEditor]
public struct ContextHandle
public struct ContextHandle : IEquatable<ContextHandle>
{
private readonly string[] _path;
@@ -42,6 +44,31 @@ namespace FlaxEditor.Surface.Undo
}
}
/// <summary>
/// Initializes a new instance of the <see cref="ContextHandle"/> struct.
/// </summary>
/// <param name="child">The child context provider.</param>
public ContextHandle(ISurfaceContext child)
{
if (child == null)
throw new ArgumentNullException();
VisjectSurfaceContext parent = child.ParentContext;
VisjectSurfaceContext context = parent;
int count = 1;
while (parent != null)
{
count++;
parent = parent.Parent;
}
_path = new string[count];
_path[0] = child.SurfaceName;
for (int i = 1; i < count; i++)
{
_path[i] = context.Context.SurfaceName;
context = context.Parent;
}
}
/// <summary>
/// Gets the context.
/// </summary>
@@ -69,5 +96,46 @@ namespace FlaxEditor.Surface.Undo
return context;
}
/// <inheritdoc />
public bool Equals(ContextHandle other)
{
return JsonSerializer.ValueEquals(_path, other._path);
}
/// <inheritdoc />
public override bool Equals(object obj)
{
return obj is ContextHandle other && Equals(other);
}
/// <inheritdoc />
public override int GetHashCode()
{
int hash = 17;
if (_path != null)
{
unchecked
{
for (var i = 0; i < _path.Length; i++)
{
var item = _path[i];
hash = hash * 23 + (item != null ? item.GetHashCode() : 0);
}
}
}
return hash;
}
/// <inheritdoc />
public override string ToString()
{
var sb = new StringBuilder();
if (_path == null)
return string.Empty;
for (int i = _path.Length - 1; i >= 0; i--)
sb.Append(_path[i]).Append('/');
return sb.ToString();
}
}
}

View File

@@ -2,6 +2,8 @@
using System;
using System.Collections.Generic;
using FlaxEditor.Surface.Undo;
using FlaxEngine;
namespace FlaxEditor.Surface
{
@@ -9,7 +11,7 @@ namespace FlaxEditor.Surface
{
private VisjectSurfaceContext _root;
private VisjectSurfaceContext _context;
private readonly Dictionary<ISurfaceContext, VisjectSurfaceContext> _contextCache = new Dictionary<ISurfaceContext, VisjectSurfaceContext>();
private readonly Dictionary<ContextHandle, VisjectSurfaceContext> _contextCache = new Dictionary<ContextHandle, VisjectSurfaceContext>();
/// <summary>
/// The surface context stack.
@@ -54,11 +56,12 @@ namespace FlaxEditor.Surface
return;
// Get or create context
if (!_contextCache.TryGetValue(context, out VisjectSurfaceContext surfaceContext))
var contextHandle = new ContextHandle(context);
if (!_contextCache.TryGetValue(contextHandle, out VisjectSurfaceContext surfaceContext))
{
surfaceContext = CreateContext(_context, context);
_context?.Children.Add(surfaceContext);
_contextCache.Add(context, surfaceContext);
_contextCache.Add(contextHandle, surfaceContext);
context.OnContextCreated(surfaceContext);
@@ -118,7 +121,8 @@ namespace FlaxEditor.Surface
}
// Check if has context in cache
if (_contextCache.TryGetValue(context, out VisjectSurfaceContext surfaceContext))
var contextHandle = new ContextHandle(context);
if (_contextCache.TryGetValue(contextHandle, out VisjectSurfaceContext surfaceContext))
{
// Remove from navigation path
while (ContextStack.Contains(surfaceContext))
@@ -126,7 +130,7 @@ namespace FlaxEditor.Surface
// Dispose
surfaceContext.Clear();
_contextCache.Remove(context);
_contextCache.Remove(contextHandle);
}
}
@@ -147,7 +151,8 @@ namespace FlaxEditor.Surface
return;
// Check if already in a path
if (_contextCache.TryGetValue(context, out VisjectSurfaceContext surfaceContext) && ContextStack.Contains(surfaceContext))
var contextHandle = new ContextHandle(context);
if (_contextCache.TryGetValue(contextHandle, out VisjectSurfaceContext surfaceContext) && ContextStack.Contains(surfaceContext))
{
// Change stack
do

View File

@@ -899,6 +899,9 @@ namespace FlaxEditor.Surface
/// <inheritdoc />
public abstract byte[] SurfaceData { get; set; }
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -366,6 +366,9 @@ namespace FlaxEditor.Viewport.Previews
}
}
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
void ISurfaceContext.OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -408,6 +408,9 @@ namespace FlaxEditor.Windows
/// <inheritdoc />
public byte[] SurfaceData { get; set; }
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -179,6 +179,9 @@ namespace FlaxEditor.Windows.Assets
/// <inheritdoc />
public abstract byte[] SurfaceData { get; set; }
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -1147,6 +1147,9 @@ namespace FlaxEditor.Windows.Assets
}
}
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{

View File

@@ -326,10 +326,10 @@ namespace FlaxEditor.Windows
Select(item, true);
// Disable scrolling in content view
if (_split.Panel2.VScrollBar != null)
_split.Panel2.VScrollBar.ThumbEnabled = false;
if (_split.Panel2.HScrollBar != null)
_split.Panel2.HScrollBar.ThumbEnabled = false;
if (_contentViewPanel.VScrollBar != null)
_contentViewPanel.VScrollBar.ThumbEnabled = false;
if (_contentViewPanel.HScrollBar != null)
_contentViewPanel.HScrollBar.ThumbEnabled = false;
ScrollingOnContentView(false);
// Show rename popup
@@ -340,10 +340,10 @@ namespace FlaxEditor.Windows
popup.Closed += renamePopup =>
{
// Restore scrolling in content view
if (_split.Panel2.VScrollBar != null)
_split.Panel2.VScrollBar.ThumbEnabled = true;
if (_split.Panel2.HScrollBar != null)
_split.Panel2.HScrollBar.ThumbEnabled = true;
if (_contentViewPanel.VScrollBar != null)
_contentViewPanel.VScrollBar.ThumbEnabled = true;
if (_contentViewPanel.HScrollBar != null)
_contentViewPanel.HScrollBar.ThumbEnabled = true;
ScrollingOnContentView(true);
// Check if was creating new element
@@ -761,7 +761,7 @@ namespace FlaxEditor.Windows
// Select and scroll to cover in view
_view.Select(item);
_split.Panel2.ScrollViewTo(item, fastScroll);
_contentViewPanel.ScrollViewTo(item, fastScroll);
// Focus
_view.Focus();

View File

@@ -105,6 +105,9 @@ namespace FlaxEngine.Windows.Search
/// <inheritdoc />
public byte[] SurfaceData { get; set; }
/// <inheritdoc />
public VisjectSurfaceContext ParentContext => null;
/// <inheritdoc />
public void OnContextCreated(VisjectSurfaceContext context)
{