Ejemplo n.º 1
0
        /// <summary>
        /// Breaks any prefab links for the selected objects. Supports undo/redo.
        /// </summary>
        public void BreakLinks()
        {
            // Skip in invalid states
            if (!Editor.StateMachine.CurrentState.CanEditScene)
            {
                return;
            }

            // Get valid objects (the top ones, C++ backend will process the child objects)
            var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode actorNode && actorNode.HasPrefabLink).ToList().BuildNodesParents();

            if (selection.Count == 0)
            {
                return;
            }

            // Perform action
            if (Editor.StateMachine.CurrentState.CanUseUndoRedo)
            {
                if (selection.Count == 1)
                {
                    var action = BreakPrefabLinkAction.Break(((ActorNode)selection[0]).Actor);
                    Undo.AddAction(action);
                    action.Do();
                }
                else
                {
                    var actions = new IUndoAction[selection.Count];
                    for (int i = 0; i < selection.Count; i++)
                    {
                        var action = BreakPrefabLinkAction.Break(((ActorNode)selection[i]).Actor);
                        actions[i] = action;
                        action.Do();
                    }
                    Undo.AddAction(new MultiUndoAction(actions));
                }
            }
            else
            {
                for (int i = 0; i < selection.Count; i++)
                {
                    ((ActorNode)selection[i]).Actor.BreakPrefabLink();
                }
            }
        }
Ejemplo n.º 2
0
        private void OnPrefabCreated(ContentItem contentItem)
        {
            if (contentItem is PrefabItem prefabItem)
            {
                PrefabCreated?.Invoke(prefabItem);
            }

            // Skip in invalid states
            if (!Editor.StateMachine.CurrentState.CanEditScene)
            {
                return;
            }

            // Record undo for prefab creating (backend links the target instance with the prefab)
            if (Editor.Undo.Enabled)
            {
                var selection = Editor.SceneEditing.Selection.Where(x => x is ActorNode).ToList().BuildNodesParents();
                if (selection.Count == 0)
                {
                    return;
                }

                if (selection.Count == 1)
                {
                    var action = BreakPrefabLinkAction.Linked(((ActorNode)selection[0]).Actor);
                    Undo.AddAction(action);
                }
                else
                {
                    var actions = new IUndoAction[selection.Count];
                    for (int i = 0; i < selection.Count; i++)
                    {
                        var action = BreakPrefabLinkAction.Linked(((ActorNode)selection[i]).Actor);
                        actions[i] = action;
                    }
                    Undo.AddAction(new MultiUndoAction(actions));
                }
            }

            Editor.Instance.Windows.PropertiesWin.Presenter.BuildLayout();
        }