Merge branch 'Tryibion-show-prefab-add-delete'
This commit is contained in:
@@ -63,6 +63,11 @@ namespace FlaxEditor.CustomEditors
|
|||||||
/// Indication of if the properties window is locked on specific objects.
|
/// Indication of if the properties window is locked on specific objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LockSelection { get; set; }
|
public bool LockSelection { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the scene editing context.
|
||||||
|
/// </summary>
|
||||||
|
public ISceneEditingContext SceneContext { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using FlaxEditor.Actions;
|
using FlaxEditor.Actions;
|
||||||
using FlaxEditor.CustomEditors.Editors;
|
using FlaxEditor.CustomEditors.Editors;
|
||||||
using FlaxEditor.CustomEditors.Elements;
|
using FlaxEditor.CustomEditors.Elements;
|
||||||
@@ -10,10 +7,14 @@ using FlaxEditor.GUI;
|
|||||||
using FlaxEditor.GUI.ContextMenu;
|
using FlaxEditor.GUI.ContextMenu;
|
||||||
using FlaxEditor.GUI.Tree;
|
using FlaxEditor.GUI.Tree;
|
||||||
using FlaxEditor.Scripting;
|
using FlaxEditor.Scripting;
|
||||||
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using FlaxEngine.Json;
|
using FlaxEngine.Json;
|
||||||
using FlaxEngine.Utilities;
|
using FlaxEngine.Utilities;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace FlaxEditor.CustomEditors.Dedicated
|
namespace FlaxEditor.CustomEditors.Dedicated
|
||||||
{
|
{
|
||||||
@@ -238,6 +239,12 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
node.TextColor = Color.OrangeRed;
|
node.TextColor = Color.OrangeRed;
|
||||||
node.Text = Utilities.Utils.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
|
node.Text = Utilities.Utils.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
|
||||||
}
|
}
|
||||||
|
// Removed Actor
|
||||||
|
else if (editor is RemovedActorDummy removedActor)
|
||||||
|
{
|
||||||
|
node.TextColor = Color.OrangeRed;
|
||||||
|
node.Text = $"{removedActor.PrefabObject.Name} ({Utilities.Utils.GetPropertyNameUI(removedActor.PrefabObject.GetType().Name)})";
|
||||||
|
}
|
||||||
// Actor or Script
|
// Actor or Script
|
||||||
else if (editor.Values[0] is SceneObject sceneObject)
|
else if (editor.Values[0] is SceneObject sceneObject)
|
||||||
{
|
{
|
||||||
@@ -293,11 +300,35 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
// Not used
|
// Not used
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class RemovedActorDummy : CustomEditor
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The removed prefab object (from the prefab default instance).
|
||||||
|
/// </summary>
|
||||||
|
public Actor PrefabObject;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The prefab instance's parent.
|
||||||
|
/// </summary>
|
||||||
|
public Actor ParentActor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The order of the removed actor in the parent.
|
||||||
|
/// </summary>
|
||||||
|
public int OrderInParent;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Initialize(LayoutElementsContainer layout)
|
||||||
|
{
|
||||||
|
// Not used
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private TreeNode ProcessDiff(CustomEditor editor, bool skipIfNotModified = true)
|
private TreeNode ProcessDiff(CustomEditor editor, bool skipIfNotModified = true)
|
||||||
{
|
{
|
||||||
// Special case for new Script added to actor
|
// Special case for new Script or child actor added to actor
|
||||||
if (editor.Values[0] is Script script && !script.HasPrefabLink)
|
if ((editor.Values[0] is Script script && !script.HasPrefabLink) || (editor.Values[0] is Actor a && !a.HasPrefabLink))
|
||||||
return CreateDiffNode(editor);
|
return CreateDiffNode(editor);
|
||||||
|
|
||||||
// Skip if no change detected
|
// Skip if no change detected
|
||||||
@@ -357,6 +388,41 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compare child actors for removed actors.
|
||||||
|
if (editor is ActorEditor && editor.Values.HasReferenceValue && editor.Values.ReferenceValue is Actor prefabObjectActor)
|
||||||
|
{
|
||||||
|
var thisActor = editor.Values[0] as Actor;
|
||||||
|
for (int i = 0; i < prefabObjectActor.ChildrenCount; i++)
|
||||||
|
{
|
||||||
|
var prefabActorChild = prefabObjectActor.Children[i];
|
||||||
|
if (thisActor == null)
|
||||||
|
continue;
|
||||||
|
bool isRemoved = true;
|
||||||
|
for (int j = 0; j < thisActor.ChildrenCount; j++)
|
||||||
|
{
|
||||||
|
var actorChild = thisActor.Children[j];
|
||||||
|
if (actorChild.PrefabObjectID == prefabActorChild.PrefabObjectID)
|
||||||
|
{
|
||||||
|
isRemoved = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isRemoved)
|
||||||
|
{
|
||||||
|
var dummy = new RemovedActorDummy
|
||||||
|
{
|
||||||
|
PrefabObject = prefabActorChild,
|
||||||
|
ParentActor = thisActor,
|
||||||
|
OrderInParent = prefabActorChild.OrderInParent,
|
||||||
|
};
|
||||||
|
var child = CreateDiffNode(dummy);
|
||||||
|
if (result == null)
|
||||||
|
result = CreateDiffNode(editor);
|
||||||
|
result.AddChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,6 +532,22 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case for reverting removed Actors
|
||||||
|
if (editor is RemovedActorDummy removedActor)
|
||||||
|
{
|
||||||
|
Editor.Log("Reverting removed actor changes to prefab (adding it)");
|
||||||
|
|
||||||
|
var parentActor = removedActor.ParentActor;
|
||||||
|
var restored = parentActor.AddChild(removedActor.PrefabObject.GetType());
|
||||||
|
var prefabId = parentActor.PrefabID;
|
||||||
|
var prefabObjectId = removedActor.PrefabObject.PrefabObjectID;
|
||||||
|
string data = JsonSerializer.Serialize(removedActor.PrefabObject);
|
||||||
|
JsonSerializer.Deserialize(restored, data);
|
||||||
|
Presenter.Owner.SceneContext.Spawn(restored, parentActor, removedActor.OrderInParent);
|
||||||
|
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), ref prefabId, ref prefabObjectId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Special case for new Script added to actor
|
// Special case for new Script added to actor
|
||||||
if (editor.Values[0] is Script script && !script.HasPrefabLink)
|
if (editor.Values[0] is Script script && !script.HasPrefabLink)
|
||||||
{
|
{
|
||||||
@@ -477,6 +559,19 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Special case for new Actor added to actor
|
||||||
|
if (editor.Values[0] is Actor a && !a.HasPrefabLink)
|
||||||
|
{
|
||||||
|
Editor.Log("Reverting added actor changes to prefab (removing it)");
|
||||||
|
|
||||||
|
// TODO: Keep previous selection.
|
||||||
|
var context = Presenter.Owner.SceneContext;
|
||||||
|
context.Select(SceneGraph.SceneGraphFactory.FindNode(a.ID));
|
||||||
|
context.DeleteSelection();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Presenter.Undo != null && Presenter.Undo.Enabled)
|
if (Presenter.Undo != null && Presenter.Undo.Enabled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using FlaxEditor.SceneGraph;
|
using FlaxEditor.SceneGraph;
|
||||||
using FlaxEditor.Viewport;
|
using FlaxEditor.Viewport;
|
||||||
|
using FlaxEngine;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace FlaxEditor
|
namespace FlaxEditor
|
||||||
{
|
{
|
||||||
@@ -39,9 +40,23 @@ namespace FlaxEditor
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
void RenameSelection();
|
void RenameSelection();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes selected objects.
|
||||||
|
/// </summary>
|
||||||
|
void DeleteSelection();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Focuses selected objects.
|
/// Focuses selected objects.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void FocusSelection();
|
void FocusSelection();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Spawns the specified actor to the game (with undo).
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="actor">The actor.</param>
|
||||||
|
/// <param name="parent">The parent actor. Set null as default.</param>
|
||||||
|
/// <param name="orderInParent">The order under the parent to put the spawned actor.</param>
|
||||||
|
/// <param name="autoSelect">True if automatically select the spawned actor, otherwise false.</param>
|
||||||
|
void Spawn(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ namespace FlaxEditor.SceneGraph
|
|||||||
public List<SceneGraphNode> Selection => SceneContext.Selection;
|
public List<SceneGraphNode> Selection => SceneContext.Selection;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the list of selected scene graph nodes in the editor context.
|
/// Gets the scene editing context.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract ISceneEditingContext SceneContext { get; }
|
public abstract ISceneEditingContext SceneContext { get; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -641,5 +641,8 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public bool LockSelection { get; set; }
|
public bool LockSelection { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ISceneEditingContext SceneContext => null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -430,6 +430,12 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void DeleteSelection()
|
||||||
|
{
|
||||||
|
Delete();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void FocusSelection()
|
public void FocusSelection()
|
||||||
{
|
{
|
||||||
@@ -488,7 +494,8 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
/// <param name="actor">The actor.</param>
|
/// <param name="actor">The actor.</param>
|
||||||
/// <param name="parent">The parent.</param>
|
/// <param name="parent">The parent.</param>
|
||||||
/// <param name="orderInParent">The order of the actor under the parent.</param>
|
/// <param name="orderInParent">The order of the actor under the parent.</param>
|
||||||
public void Spawn(Actor actor, Actor parent, int orderInParent = -1)
|
/// <param name="autoSelect">True if automatically select the spawned actor, otherwise false.</param>
|
||||||
|
public void Spawn(Actor actor, Actor parent, int orderInParent = -1, bool autoSelect = true)
|
||||||
{
|
{
|
||||||
if (actor == null)
|
if (actor == null)
|
||||||
throw new ArgumentNullException(nameof(actor));
|
throw new ArgumentNullException(nameof(actor));
|
||||||
@@ -514,8 +521,11 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
// Create undo action
|
// Create undo action
|
||||||
var action = new CustomDeleteActorsAction(new List<SceneGraphNode>(1) { actorNode }, true);
|
var action = new CustomDeleteActorsAction(new List<SceneGraphNode>(1) { actorNode }, true);
|
||||||
Undo.AddAction(action);
|
Undo.AddAction(action);
|
||||||
Focus();
|
if (autoSelect)
|
||||||
Select(actorNode);
|
{
|
||||||
|
Focus();
|
||||||
|
Select(actorNode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTreeRightClick(TreeNode node, Float2 location)
|
private void OnTreeRightClick(TreeNode node, Float2 location)
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ISceneEditingContext SceneContext => this;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether use live reloading for the prefab changes (applies prefab changes on modification by auto).
|
/// Gets or sets a value indicating whether use live reloading for the prefab changes (applies prefab changes on modification by auto).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ namespace FlaxEditor.Windows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public ISceneEditingContext SceneContext => Editor.Windows.EditWin;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PropertiesWindow"/> class.
|
/// Initializes a new instance of the <see cref="PropertiesWindow"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -26,12 +26,24 @@ namespace FlaxEditor.Windows
|
|||||||
FlaxEditor.Utilities.Utils.SetupCommonInputActions(this);
|
FlaxEditor.Utilities.Utils.SetupCommonInputActions(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void DeleteSelection()
|
||||||
|
{
|
||||||
|
Editor.SceneEditing.Delete();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void FocusSelection()
|
public void FocusSelection()
|
||||||
{
|
{
|
||||||
Editor.Windows.EditWin.Viewport.FocusSelection();
|
Editor.Windows.EditWin.Viewport.FocusSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Spawn(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true)
|
||||||
|
{
|
||||||
|
Editor.SceneEditing.Spawn(actor, parent, orderInParent, autoSelect);
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public EditorViewport Viewport => Editor.Windows.EditWin.Viewport;
|
public EditorViewport Viewport => Editor.Windows.EditWin.Viewport;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user