public void OnNodeDelete(BTEditorGraphNode node) { if (node != null) { BTUndoSystem.RegisterUndo(new UndoNodeDeleted(node)); node.OnDelete(); } }
public void OnDeleteChild(int index) { BTEditorGraphNode child = GetChild(index); if (child != null) { child.OnDelete(); } }
public override void Undo() { if (CanUndo) { BTEditorGraphNode createdNode = m_graph.GetNodeByHash(m_createdNodeHash); m_parentNodeHash = m_graph.GetNodeHash(createdNode.Parent); m_serializedNode = BTUtils.SerializeNode(createdNode.Node); createdNode.OnDelete(); m_createdNodeHash = null; } }
public void OnNodeSwitchType(BTEditorGraphNode target, Type newType) { if (target == null || newType == null) { return; } BTEditorGraphNode parentNode = target.Parent; Vector2 oldPosition = target.NodePositon; int oldIndex = target.Parent.GetChildIndex(target); BehaviourNode node = BTUtils.CreateNode(newType); if (node != null) { if (node is Decorator) { Decorator original = target.Node as Decorator; Decorator decorator = node as Decorator; decorator.SetChild(original.GetChild()); } else if (node is Composite) { Composite original = target.Node as Composite; Composite composite = node as Composite; for (int i = 0; i < original.ChildCount; i++) { composite.AddChild(original.GetChild(i)); } } BTUndoSystem.BeginUndoGroup("Changed node type"); BTUndoSystem.RegisterUndo(new UndoNodeDeleted(target)); target.OnDelete(); BTEditorGraphNode newNode = parentNode.OnInsertChild(oldIndex, node); if (newNode != null) { newNode.NodePositon = oldPosition; BTUndoSystem.RegisterUndo(new UndoNodeCreated(newNode)); } BTUndoSystem.EndUndoGroup(); } }