public void OnNodeSwitchType(BTEditorGraphNode target, Type newType) { if (target == null || newType == null) { return; } BTEditorGraphNode parentNode = target.Parent; Vector2 oldPosition = target.NodePosition; int oldIndex = target.Parent.GetChildIndex(target); BehaviourNode node = BTUtils.CreateNode(newType); if (node != null) { node.Constraints.AddRange(target.Node.Constraints); 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.NodePosition = oldPosition; BTUndoSystem.RegisterUndo(new UndoNodeCreated(newNode)); } BTUndoSystem.EndUndoGroup(); } }