/// <summary> 
        /// Paste the supplied nodes in the supplied ActionState.
        /// <param name="actionState">The ActionState to paste the node.</param>
        /// <param name="nodes">The nodes to be pasted.</param>
        /// <returns>The pasted nodes.</returns>
        /// </summary>
        public static ActionNode[] PasteNodes (InternalActionState actionState, ActionNode[] nodes) {
            var newNodes = new List<ActionNode>();

            // Validate parameters
            if (nodes != null && actionState != null) {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(actionState,"Paste Node");
                #else
                Undo.RecordObject(actionState,"Paste Node");
                #endif

                // Copy nodes
                for (int i = 0; i < nodes.Length; i++) {
                    if (nodes[i] != null && !(nodes[i] is BranchNode)) {
                        ActionNode newNode = nodes[i].Copy(actionState);
                        if (newNode != null)
                            newNodes.Add(newNode);
                    }
                }

                if (newNodes.Count > 0) {
                    // Saves node and sets dirty flag
                    StateUtility.SetDirty(actionState);

                    // Reload actionState to update variables
                    actionState.LoadNodes();
                }
            }
            return newNodes.ToArray();
        }
    	/// <summary> 
        /// Adds a new node to the action state, automatically handles undo, dirty flag and save node.
        /// <param name="actionState">The action state to add a new node.</param>
        /// <param name="nodeType">The type of the new node.</param>
        /// <returns>The new node.</returns>
        /// </summary>
        public static ActionNode AddNode (InternalActionState actionState, System.Type nodeType) {
            // Validate parameters
            if (actionState != null && nodeType != null && nodeType.IsSubclassOf(typeof(ActionNode)) && !nodeType.IsAbstract) {
                // Register Undo
                #if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
                Undo.RegisterUndo(actionState,"Add New Node");
                #else
                Undo.RecordObject(actionState,"Add New Node");
                #endif

                // Create new node
                var newNode = actionState.AddNode(nodeType);

                if (newNode != null) {                    
                    // Saves node and sets dirty flag
                    StateUtility.SetDirty(actionState);
                    return newNode;
                }
            }

            return null;
        }
        /// <summary>
        /// A Unity callback called when the object is loaded.
        /// </summary>
        private void OnEnable () {
            m_ActionState = target as InternalActionState;
            BehaviourWindow.activeNodeChanged += this.ActiveNodeChanged;

            // Try to create an editor for the current active node
            this.ActiveNodeChanged();

            // Register the visual debugging callback
            ActionNode.onNodeTick += OnNodeTick;

            // Register Update
            if (Application.isPlaying) {
                EditorApplication.update += this.Update;
            }
            else {
                m_ActionState.LoadNodes();
                RegisterEditorOnGUI();
            }
        }