Modernize the code to use unified scene access #3513
This commit is contained in:
@@ -63,6 +63,11 @@ namespace FlaxEditor.CustomEditors
|
||||
/// Indication of if the properties window is locked on specific objects.
|
||||
/// </summary>
|
||||
public bool LockSelection { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the scene editing context.
|
||||
/// </summary>
|
||||
public ISceneEditingContext SceneContext { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FlaxEditor.Actions;
|
||||
using FlaxEditor.CustomEditors.Editors;
|
||||
using FlaxEditor.CustomEditors.Elements;
|
||||
@@ -10,10 +7,14 @@ using FlaxEditor.GUI;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Tree;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEditor.Windows.Assets;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
using FlaxEngine.Json;
|
||||
using FlaxEngine.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace FlaxEditor.CustomEditors.Dedicated
|
||||
{
|
||||
@@ -542,10 +543,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
var prefabObjectId = removedActor.PrefabObject.PrefabObjectID;
|
||||
string data = JsonSerializer.Serialize(removedActor.PrefabObject);
|
||||
JsonSerializer.Deserialize(restored, data);
|
||||
if (Presenter.Owner is PropertiesWindow propertiesWindow)
|
||||
Editor.Instance.SceneEditing.Spawn(restored, parentActor, removedActor.OrderInParent);
|
||||
else if (Presenter.Owner is PrefabWindow prefabWindow)
|
||||
prefabWindow.Spawn(restored, parentActor, removedActor.OrderInParent);
|
||||
Presenter.Owner.SceneContext.Spawn(restored, parentActor, removedActor.OrderInParent);
|
||||
Actor.Internal_LinkPrefab(FlaxEngine.Object.GetUnmanagedPtr(restored), ref prefabId, ref prefabObjectId);
|
||||
return;
|
||||
}
|
||||
@@ -568,17 +566,9 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
Editor.Log("Reverting added actor changes to prefab (removing it)");
|
||||
|
||||
// TODO: Keep previous selection.
|
||||
if (Presenter.Owner is PropertiesWindow propertiesWindow)
|
||||
{
|
||||
var editorInstance = Editor.Instance.SceneEditing;
|
||||
editorInstance.Select(a);
|
||||
editorInstance.Delete();
|
||||
}
|
||||
else if (Presenter.Owner is PrefabWindow prefabWindow)
|
||||
{
|
||||
prefabWindow.Select(prefabWindow.Graph.Root.Find(a));
|
||||
prefabWindow.Delete();
|
||||
}
|
||||
var context = Presenter.Owner.SceneContext;
|
||||
context.Select(SceneGraph.SceneGraphFactory.FindNode(a.ID));
|
||||
context.DeleteSelection();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// Copyright (c) Wojciech Figat. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using FlaxEditor.SceneGraph;
|
||||
using FlaxEditor.Viewport;
|
||||
using FlaxEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FlaxEditor
|
||||
{
|
||||
@@ -39,9 +40,23 @@ namespace FlaxEditor
|
||||
/// </summary>
|
||||
void RenameSelection();
|
||||
|
||||
/// <summary>
|
||||
/// Deletes selected objects.
|
||||
/// </summary>
|
||||
void DeleteSelection();
|
||||
|
||||
/// <summary>
|
||||
/// Focuses selected objects.
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of selected scene graph nodes in the editor context.
|
||||
/// Gets the scene editing context.
|
||||
/// </summary>
|
||||
public abstract ISceneEditingContext SceneContext { get; }
|
||||
}
|
||||
|
||||
@@ -641,5 +641,8 @@ namespace FlaxEditor.Windows.Assets
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool LockSelection { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public ISceneEditingContext SceneContext => null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -430,6 +430,12 @@ namespace FlaxEditor.Windows.Assets
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DeleteSelection()
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void FocusSelection()
|
||||
{
|
||||
@@ -488,7 +494,8 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// <param name="actor">The actor.</param>
|
||||
/// <param name="parent">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)
|
||||
throw new ArgumentNullException(nameof(actor));
|
||||
@@ -514,8 +521,11 @@ namespace FlaxEditor.Windows.Assets
|
||||
// Create undo action
|
||||
var action = new CustomDeleteActorsAction(new List<SceneGraphNode>(1) { actorNode }, true);
|
||||
Undo.AddAction(action);
|
||||
Focus();
|
||||
Select(actorNode);
|
||||
if (autoSelect)
|
||||
{
|
||||
Focus();
|
||||
Select(actorNode);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTreeRightClick(TreeNode node, Float2 location)
|
||||
|
||||
@@ -91,6 +91,9 @@ namespace FlaxEditor.Windows.Assets
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ISceneEditingContext SceneContext => this;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether use live reloading for the prefab changes (applies prefab changes on modification by auto).
|
||||
/// </summary>
|
||||
|
||||
@@ -58,6 +58,9 @@ namespace FlaxEditor.Windows
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ISceneEditingContext SceneContext => Editor.Windows.EditWin;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PropertiesWindow"/> class.
|
||||
/// </summary>
|
||||
|
||||
@@ -26,12 +26,24 @@ namespace FlaxEditor.Windows
|
||||
FlaxEditor.Utilities.Utils.SetupCommonInputActions(this);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void DeleteSelection()
|
||||
{
|
||||
Editor.SceneEditing.Delete();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void 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 />
|
||||
public EditorViewport Viewport => Editor.Windows.EditWin.Viewport;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user