diff --git a/Source/Editor/CustomEditors/CustomEditorPresenter.cs b/Source/Editor/CustomEditors/CustomEditorPresenter.cs index be7b4de5c..44188b8fb 100644 --- a/Source/Editor/CustomEditors/CustomEditorPresenter.cs +++ b/Source/Editor/CustomEditors/CustomEditorPresenter.cs @@ -219,6 +219,11 @@ namespace FlaxEditor.CustomEditors /// public event Action AfterLayout; + /// + /// The Editor context that owns this presenter. Can be or or other window/panel - custom editor scan use it for more specific features. + /// + public object Owner; + private bool _buildOnUpdate; /// @@ -226,9 +231,11 @@ namespace FlaxEditor.CustomEditors /// /// The undo. It's optional. /// The custom text to display when no object is selected. Default is No selection. - public CustomEditorPresenter(Undo undo, string noSelectionText = null) + /// The owner of the presenter. + 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); diff --git a/Source/Editor/GUI/ItemsListContextMenu.cs b/Source/Editor/GUI/ItemsListContextMenu.cs index 4abe39f0b..774252507 100644 --- a/Source/Editor/GUI/ItemsListContextMenu.cs +++ b/Source/Editor/GUI/ItemsListContextMenu.cs @@ -46,6 +46,11 @@ namespace FlaxEditor.GUI /// public event Action Clicked; + /// + /// The tint color of the text. + /// + public Color TintColor = Color.White; + /// /// Initializes a new instance of the class. /// @@ -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); } /// diff --git a/Source/Editor/SceneGraph/ActorNode.cs b/Source/Editor/SceneGraph/ActorNode.cs index 6019386d4..a9720a7d5 100644 --- a/Source/Editor/SceneGraph/ActorNode.cs +++ b/Source/Editor/SceneGraph/ActorNode.cs @@ -179,12 +179,12 @@ namespace FlaxEditor.SceneGraph /// /// Gets a value indicating whether this actor can be used to create prefab from it (as a root). /// - public virtual bool CanCreatePrefab => (Actor.HideFlags & HideFlags.DontSave) != HideFlags.DontSave; + public virtual bool CanCreatePrefab => (_actor.HideFlags & HideFlags.DontSave) != HideFlags.DontSave; /// /// Gets a value indicating whether this actor has a valid linkage to the prefab asset. /// - public virtual bool HasPrefabLink => Actor.HasPrefabLink; + public virtual bool HasPrefabLink => _actor.HasPrefabLink; /// public override string Name => _actor.Name; diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs index cebbfc544..6d4c34a6c 100644 --- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs +++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs @@ -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 diff --git a/Source/Editor/Undo/UndoBlock.cs b/Source/Editor/Undo/UndoBlock.cs index 3e6ed3e2c..7c1e4f78f 100644 --- a/Source/Editor/Undo/UndoBlock.cs +++ b/Source/Editor/Undo/UndoBlock.cs @@ -33,6 +33,8 @@ namespace FlaxEditor /// Custom action to append to the undo block action after recorded modifications apply. 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 /// public void Dispose() { - _undo.RecordEnd(_snapshotUndoInternal, _customActionBefore, _customActionAfter); + _undo?.RecordEnd(_snapshotUndoInternal, _customActionBefore, _customActionAfter); } } } diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs index ccc7abdb9..25c063372 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs @@ -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++) { diff --git a/Source/Editor/Windows/Assets/PrefabWindow.cs b/Source/Editor/Windows/Assets/PrefabWindow.cs index 3820e762c..9c484d9d4 100644 --- a/Source/Editor/Windows/Assets/PrefabWindow.cs +++ b/Source/Editor/Windows/Assets/PrefabWindow.cs @@ -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; diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs index f96385536..dc2dfc308 100644 --- a/Source/Editor/Windows/PropertiesWindow.cs +++ b/Source/Editor/Windows/PropertiesWindow.cs @@ -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; diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index e4aa70c7e..41b645bcb 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -1515,6 +1515,8 @@ bool Actor::ToBytes(const Array& 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& actors, MemoryWriteStream& output) for (int32 i = 0; i < actors.Count(); i++) { Actor* actor = actors[i]; + if (!actor) + continue; WriteObjectToBytes(actor, buffer, output);