Merge branch 'AnimationSampleNode-AnimationAssetReferencePort' of https://github.com/Chikinsupu/FlaxEngine into Chikinsupu-AnimationSampleNode-AnimationAssetReferencePort

This commit is contained in:
Wojtek Figat
2023-10-09 22:24:57 +02:00
2 changed files with 36 additions and 3 deletions

View File

@@ -34,6 +34,9 @@ namespace FlaxEditor.Surface.Archetypes
/// <seealso cref="FlaxEditor.Surface.SurfaceNode" /> /// <seealso cref="FlaxEditor.Surface.SurfaceNode" />
public class Sample : SurfaceNode public class Sample : SurfaceNode
{ {
private AssetSelect _assetSelect;
private Box _assetBox;
/// <inheritdoc /> /// <inheritdoc />
public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch) public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
: base(id, context, nodeArch, groupArch) : base(id, context, nodeArch, groupArch)
@@ -54,16 +57,33 @@ namespace FlaxEditor.Surface.Archetypes
base.OnSurfaceLoaded(action); base.OnSurfaceLoaded(action);
if (Surface != null) if (Surface != null)
{
_assetSelect = GetChild<AssetSelect>();
_assetBox = GetBox(8);
_assetSelect.Visible = !_assetBox.HasAnyConnection;
UpdateTitle(); UpdateTitle();
}
} }
private void UpdateTitle() private void UpdateTitle()
{ {
var asset = Editor.Instance.ContentDatabase.Find((Guid)Values[0]); var asset = Editor.Instance.ContentDatabase.Find((Guid)Values[0]);
Title = asset?.ShortName ?? "Animation"; Title = _assetBox.HasAnyConnection || asset == null ? "Animation" : asset.ShortName;
var style = Style.Current; var style = Style.Current;
Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160); Resize(Mathf.Max(230, style.FontLarge.MeasureText(Title).X + 30), 160);
} }
/// <inheritdoc />
public override void ConnectionTick(Box box)
{
base.ConnectionTick(box);
if(box.ID != _assetBox.ID)
return;
_assetSelect.Visible = !box.HasAnyConnection;
UpdateTitle();
}
} }
/// <summary> /// <summary>
@@ -305,7 +325,8 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Input(0, "Speed", true, typeof(float), 5, 1), NodeElementArchetype.Factory.Input(0, "Speed", true, typeof(float), 5, 1),
NodeElementArchetype.Factory.Input(1, "Loop", true, typeof(bool), 6, 2), NodeElementArchetype.Factory.Input(1, "Loop", true, typeof(bool), 6, 2),
NodeElementArchetype.Factory.Input(2, "Start Position", true, typeof(float), 7, 3), NodeElementArchetype.Factory.Input(2, "Start Position", true, typeof(float), 7, 3),
NodeElementArchetype.Factory.Asset(0, Surface.Constants.LayoutOffsetY * 3, 0, typeof(FlaxEngine.Animation)), NodeElementArchetype.Factory.Input(3, "Animation Asset", true, typeof(FlaxEngine.Animation), 8),
NodeElementArchetype.Factory.Asset(0, Surface.Constants.LayoutOffsetY * 4, 0, typeof(FlaxEngine.Animation)),
} }
}, },
new NodeArchetype new NodeArchetype

View File

@@ -750,7 +750,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
// Animation // Animation
case 2: case 2:
{ {
const auto anim = node->Assets[0].As<Animation>(); auto anim = node->Assets[0].As<Animation>();
auto& bucket = context.Data->State[node->BucketIndex].Animation; auto& bucket = context.Data->State[node->BucketIndex].Animation;
switch (box->ID) switch (box->ID)
@@ -762,6 +762,18 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
const float speed = (float)tryGetValue(node->GetBox(5), node->Values[1]); const float speed = (float)tryGetValue(node->GetBox(5), node->Values[1]);
const bool loop = (bool)tryGetValue(node->GetBox(6), node->Values[2]); const bool loop = (bool)tryGetValue(node->GetBox(6), node->Values[2]);
const float startTimePos = (float)tryGetValue(node->GetBox(7), node->Values[3]); const float startTimePos = (float)tryGetValue(node->GetBox(7), node->Values[3]);
// Override animation when animation reference box is connected
auto animationAssetBox = node->GetBox(8);
if(animationAssetBox->HasConnection())
{
const Value assetBoxValue = tryGetValue(animationAssetBox, Value::Null);
if(assetBoxValue != Value::Null)
anim = (Animation*)assetBoxValue.AsAsset;
else
anim = nullptr;
}
const float length = anim ? anim->GetLength() : 0.0f; const float length = anim ? anim->GetLength() : 0.0f;
// Calculate new time position // Calculate new time position