Add automatic preserving of basic joint properties when converting between types in Editor
This commit is contained in:
@@ -430,6 +430,7 @@ namespace FlaxEditor.Modules
|
||||
var actorNode = Editor.Instance.Scene.GetActorNode(actor);
|
||||
if (actorNode == null)
|
||||
throw new InvalidOperationException("Failed to create scene node for the spawned actor.");
|
||||
actorNode.PostConvert(oldNode);
|
||||
|
||||
actorNode.PostSpawn();
|
||||
Editor.Scene.MarkSceneEdited(actor.Scene);
|
||||
|
||||
@@ -295,6 +295,14 @@ namespace FlaxEditor.SceneGraph
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action called after converting actor in editor.
|
||||
/// </summary>
|
||||
/// <param name="source">The source actor node from which this node was converted.</param>
|
||||
public virtual void PostConvert(ActorNode source)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnParentChanged()
|
||||
{
|
||||
|
||||
35
Source/Editor/SceneGraph/Actors/JointNode.cs
Normal file
35
Source/Editor/SceneGraph/Actors/JointNode.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
|
||||
|
||||
using FlaxEngine;
|
||||
|
||||
namespace FlaxEditor.SceneGraph.Actors
|
||||
{
|
||||
/// <summary>
|
||||
/// Scene tree node for <see cref="Joint"/> actor type.
|
||||
/// </summary>
|
||||
[HideInEditor]
|
||||
public sealed class JointNode : ActorNode
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public JointNode(Actor actor)
|
||||
: base(actor)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void PostConvert(ActorNode source)
|
||||
{
|
||||
base.PostConvert(source);
|
||||
|
||||
if (source.Actor is Joint other)
|
||||
{
|
||||
// Preserve basic properties when changing joint type
|
||||
var joint = (Joint)Actor;
|
||||
joint.Target = other.Target;
|
||||
joint.TargetAnchor = other.TargetAnchor;
|
||||
joint.TargetAnchorRotation = other.TargetAnchorRotation;
|
||||
joint.EnableCollision = other.EnableCollision;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@ namespace FlaxEditor.SceneGraph
|
||||
CustomNodesTypes.Add(typeof(SplineRopeBody), typeof(ActorNode));
|
||||
CustomNodesTypes.Add(typeof(NavMesh), typeof(ActorNode));
|
||||
CustomNodesTypes.Add(typeof(SpriteRender), typeof(SpriteRenderNode));
|
||||
CustomNodesTypes.Add(typeof(Joint), typeof(JointNode));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user