Minor improvements and fixes for Editor
This commit is contained in:
@@ -219,6 +219,11 @@ namespace FlaxEditor.CustomEditors
|
||||
/// </summary>
|
||||
public event Action<LayoutElementsContainer> AfterLayout;
|
||||
|
||||
/// <summary>
|
||||
/// The Editor context that owns this presenter. Can be <see cref="FlaxEditor.Windows.PropertiesWindow"/> or <see cref="FlaxEditor.Windows.Assets.PrefabWindow"/> or other window/panel - custom editor scan use it for more specific features.
|
||||
/// </summary>
|
||||
public object Owner;
|
||||
|
||||
private bool _buildOnUpdate;
|
||||
|
||||
/// <summary>
|
||||
@@ -226,9 +231,11 @@ namespace FlaxEditor.CustomEditors
|
||||
/// </summary>
|
||||
/// <param name="undo">The undo. It's optional.</param>
|
||||
/// <param name="noSelectionText">The custom text to display when no object is selected. Default is No selection.</param>
|
||||
public CustomEditorPresenter(Undo undo, string noSelectionText = null)
|
||||
/// <param name="owner">The owner of the presenter.</param>
|
||||
public CustomEditorPresenter(Undo undo, string noSelectionText = null, object owner = null)
|
||||
{
|
||||
Undo = undo;
|
||||
Owner = owner;
|
||||
Panel = new PresenterPanel(this);
|
||||
Editor = new RootEditor(noSelectionText);
|
||||
Editor.Initialize(this, this, null);
|
||||
|
||||
@@ -46,6 +46,11 @@ namespace FlaxEditor.GUI
|
||||
/// </summary>
|
||||
public event Action<Item> Clicked;
|
||||
|
||||
/// <summary>
|
||||
/// The tint color of the text.
|
||||
/// </summary>
|
||||
public Color TintColor = Color.White;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Item"/> class.
|
||||
/// </summary>
|
||||
@@ -129,7 +134,7 @@ namespace FlaxEditor.GUI
|
||||
}
|
||||
|
||||
// Draw name
|
||||
Render2D.DrawText(style.FontSmall, Name, textRect, Enabled ? style.Foreground : style.ForegroundDisabled, TextAlignment.Near, TextAlignment.Center);
|
||||
Render2D.DrawText(style.FontSmall, Name, textRect, TintColor * (Enabled ? style.Foreground : style.ForegroundDisabled), TextAlignment.Near, TextAlignment.Center);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -179,12 +179,12 @@ namespace FlaxEditor.SceneGraph
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this actor can be used to create prefab from it (as a root).
|
||||
/// </summary>
|
||||
public virtual bool CanCreatePrefab => (Actor.HideFlags & HideFlags.DontSave) != HideFlags.DontSave;
|
||||
public virtual bool CanCreatePrefab => (_actor.HideFlags & HideFlags.DontSave) != HideFlags.DontSave;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether this actor has a valid linkage to the prefab asset.
|
||||
/// </summary>
|
||||
public virtual bool HasPrefabLink => Actor.HasPrefabLink;
|
||||
public virtual bool HasPrefabLink => _actor.HasPrefabLink;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => _actor.Name;
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
{
|
||||
for (int i = 0; i < parent.ChildrenCount; i++)
|
||||
{
|
||||
if (parent.Children[i] is ActorTreeNode child)
|
||||
if (parent.Children[i] is ActorTreeNode child && child.Actor)
|
||||
child._orderInParent = child.Actor.OrderInParent;
|
||||
}
|
||||
parent.SortChildren();
|
||||
@@ -193,7 +193,7 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
{
|
||||
// Update hidden state
|
||||
var actor = Actor;
|
||||
if (actor != null && !_hasSearchFilter)
|
||||
if (actor && !_hasSearchFilter)
|
||||
{
|
||||
Visible = (actor.HideFlags & HideFlags.HideInHierarchy) == 0;
|
||||
}
|
||||
@@ -209,22 +209,25 @@ namespace FlaxEditor.SceneGraph.GUI
|
||||
{
|
||||
Color color = Style.Current.Foreground;
|
||||
var actor = Actor;
|
||||
if (actor != null && actor.HasPrefabLink)
|
||||
if (actor)
|
||||
{
|
||||
// Prefab
|
||||
color = Style.Current.ProgressNormal;
|
||||
}
|
||||
if (actor.HasPrefabLink)
|
||||
{
|
||||
// Prefab
|
||||
color = Style.Current.ProgressNormal;
|
||||
}
|
||||
|
||||
if (actor != null && !actor.IsActiveInHierarchy)
|
||||
{
|
||||
// Inactive
|
||||
return Style.Current.ForegroundGrey;
|
||||
}
|
||||
if (!actor.IsActiveInHierarchy)
|
||||
{
|
||||
// Inactive
|
||||
return Style.Current.ForegroundGrey;
|
||||
}
|
||||
|
||||
if (actor?.Scene != null && Editor.Instance.StateMachine.IsPlayMode && actor.IsStatic)
|
||||
{
|
||||
// Static
|
||||
return color * 0.85f;
|
||||
if (actor.Scene != null && Editor.Instance.StateMachine.IsPlayMode && actor.IsStatic)
|
||||
{
|
||||
// Static
|
||||
return color * 0.85f;
|
||||
}
|
||||
}
|
||||
|
||||
// Default
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace FlaxEditor
|
||||
/// <param name="customActionAfter">Custom action to append to the undo block action after recorded modifications apply.</param>
|
||||
public UndoBlock(Undo undo, object snapshotInstance, string actionString, IUndoAction customActionBefore = null, IUndoAction customActionAfter = null)
|
||||
{
|
||||
if (undo == null)
|
||||
return;
|
||||
_snapshotUndoInternal = snapshotInstance;
|
||||
_undo = undo;
|
||||
_undo.RecordBegin(_snapshotUndoInternal, actionString);
|
||||
@@ -43,7 +45,7 @@ namespace FlaxEditor
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
_undo.RecordEnd(_snapshotUndoInternal, _customActionBefore, _customActionAfter);
|
||||
_undo?.RecordEnd(_snapshotUndoInternal, _customActionBefore, _customActionAfter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,8 +271,11 @@ namespace FlaxEditor.Windows.Assets
|
||||
|
||||
private void Update(ActorNode actorNode)
|
||||
{
|
||||
actorNode.TreeNode.OnNameChanged();
|
||||
actorNode.TreeNode.OnOrderInParentChanged();
|
||||
if (actorNode.Actor)
|
||||
{
|
||||
actorNode.TreeNode.OnNameChanged();
|
||||
actorNode.TreeNode.OnOrderInParentChanged();
|
||||
}
|
||||
|
||||
for (int i = 0; i < actorNode.ChildNodes.Count; i++)
|
||||
{
|
||||
|
||||
@@ -148,7 +148,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
_viewport.TransformGizmo.ModeChanged += UpdateToolstrip;
|
||||
|
||||
// Prefab properties editor
|
||||
_propertiesEditor = new CustomEditorPresenter(_undo);
|
||||
_propertiesEditor = new CustomEditorPresenter(_undo, null, this);
|
||||
_propertiesEditor.Panel.Parent = _split2.Panel2;
|
||||
_propertiesEditor.Modified += MarkAsEdited;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace FlaxEditor.Windows
|
||||
Title = "Properties";
|
||||
AutoFocus = true;
|
||||
|
||||
Presenter = new CustomEditorPresenter(editor.Undo);
|
||||
Presenter = new CustomEditorPresenter(editor.Undo, null, this);
|
||||
Presenter.Panel.Parent = this;
|
||||
Presenter.GetUndoObjects += GetUndoObjects;
|
||||
Presenter.CacheExpandedGroups = true;
|
||||
|
||||
@@ -1515,6 +1515,8 @@ bool Actor::ToBytes(const Array<Actor*>& actors, MemoryWriteStream& output)
|
||||
// By default we collect actors and scripts (they are ManagedObjects recognized by the id)
|
||||
|
||||
auto actor = actors[i];
|
||||
if (!actor)
|
||||
continue;
|
||||
ids.Add(actor->GetID());
|
||||
for (int32 j = 0; j < actor->Scripts.Count(); j++)
|
||||
{
|
||||
@@ -1534,6 +1536,8 @@ bool Actor::ToBytes(const Array<Actor*>& actors, MemoryWriteStream& output)
|
||||
for (int32 i = 0; i < actors.Count(); i++)
|
||||
{
|
||||
Actor* actor = actors[i];
|
||||
if (!actor)
|
||||
continue;
|
||||
|
||||
WriteObjectToBytes(actor, buffer, output);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user