Add support for deleting selected spline points (with undo)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.Json;
|
||||
using Object = FlaxEngine.Object;
|
||||
|
||||
namespace FlaxEditor.SceneGraph.Actors
|
||||
{
|
||||
@@ -26,6 +27,10 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
|
||||
public override bool CanBeSelectedDirectly => true;
|
||||
|
||||
public override bool CanDelete => true;
|
||||
|
||||
public override bool CanUseState => true;
|
||||
|
||||
public override Transform Transform
|
||||
{
|
||||
get
|
||||
@@ -40,6 +45,39 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
}
|
||||
}
|
||||
|
||||
private struct Data
|
||||
{
|
||||
public Guid Spline;
|
||||
public int Index;
|
||||
public BezierCurve<Transform>.Keyframe Keyframe;
|
||||
}
|
||||
|
||||
public override StateData State
|
||||
{
|
||||
get
|
||||
{
|
||||
var actor = (Spline)_node.Actor;
|
||||
return new StateData
|
||||
{
|
||||
TypeName = typeof(SplinePointNode).FullName,
|
||||
CreateMethodName = nameof(Create),
|
||||
State = JsonSerializer.Serialize(new Data
|
||||
{
|
||||
Spline = actor.ID,
|
||||
Index = Index,
|
||||
Keyframe = actor.GetSplineKeyframe(Index),
|
||||
}),
|
||||
};
|
||||
}
|
||||
set => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override void Delete()
|
||||
{
|
||||
var actor = (Spline)_node.Actor;
|
||||
actor.RemoveSplinePoint(Index);
|
||||
}
|
||||
|
||||
public override bool RayCastSelf(ref RayCastData ray, out float distance, out Vector3 normal)
|
||||
{
|
||||
var actor = (Spline)_node.Actor;
|
||||
@@ -73,6 +111,19 @@ namespace FlaxEditor.SceneGraph.Actors
|
||||
DebugDraw.DrawWireSphere(new BoundingSphere(tangentOut, 4.0f), Color.White, 0, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static SceneGraphNode Create(StateData state)
|
||||
{
|
||||
var data = JsonSerializer.Deserialize<Data>(state.State);
|
||||
var spline = Object.Find<Spline>(ref data.Spline);
|
||||
spline.InsertSplineLocalPoint(data.Index, data.Keyframe.Time, data.Keyframe.Value, false);
|
||||
spline.SetSplineKeyframe(data.Index, data.Keyframe);
|
||||
var splineNode = (SplineNode)SceneGraphFactory.FindNode(data.Spline);
|
||||
if (splineNode == null)
|
||||
return null;
|
||||
splineNode.OnUpdate();
|
||||
return splineNode.ActorChildNodes[data.Index];
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class SplinePointTangentNode : ActorChildNode
|
||||
|
||||
Reference in New Issue
Block a user