- Added input box to animation sample node to receive animation assets

- AssetSelect not gets shown or hidden depending on if the box has a connection
- Animation asset reference box now overrides asset picker
This commit is contained in:
Nils Hausfeld
2023-10-06 15:23:43 +02:00
parent a698095bdd
commit e07ae33040
2 changed files with 34 additions and 2 deletions

View File

@@ -34,6 +34,9 @@ namespace FlaxEditor.Surface.Archetypes
/// <seealso cref="FlaxEditor.Surface.SurfaceNode" />
public class Sample : SurfaceNode
{
private AssetSelect _assetSelect;
private Box _assetBox;
/// <inheritdoc />
public Sample(uint id, VisjectSurfaceContext context, NodeArchetype nodeArch, GroupArchetype groupArch)
: base(id, context, nodeArch, groupArch)
@@ -54,8 +57,13 @@ namespace FlaxEditor.Surface.Archetypes
base.OnSurfaceLoaded();
if (Surface != null)
{
_assetSelect = GetChild<AssetSelect>();
_assetBox = GetBox(8);
_assetSelect.Visible = !_assetBox.HasAnyConnection;
UpdateTitle();
}
}
private void UpdateTitle()
{
@@ -64,6 +72,17 @@ namespace FlaxEditor.Surface.Archetypes
var style = Style.Current;
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;
}
}
/// <summary>
@@ -305,7 +324,8 @@ namespace FlaxEditor.Surface.Archetypes
NodeElementArchetype.Factory.Input(0, "Speed", true, typeof(float), 5, 1),
NodeElementArchetype.Factory.Input(1, "Loop", true, typeof(bool), 6, 2),
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

View File

@@ -749,7 +749,7 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
// Animation
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;
switch (box->ID)
@@ -761,6 +761,18 @@ void AnimGraphExecutor::ProcessGroupAnimation(Box* boxBase, Node* nodeBase, Valu
const float speed = (float)tryGetValue(node->GetBox(5), node->Values[1]);
const bool loop = (bool)tryGetValue(node->GetBox(6), node->Values[2]);
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;
// Calculate new time position