/**
            Actived the writeMode

        */
        private void activedWriteMode() {
            if (this.objectSelected != null && this.objectSelected.GetComponentInChildren<TextMesh>() != null)
            {
                textMesh = this.objectSelected.GetComponentInChildren<TextMesh>();
                textMesh.text += " "; // the space to show the choice letter
                renameAction = new RenameAction(textMesh);
                writeMode = true;
            }
        }
        public void onKeyboardEvent(ref Event e)
        {
            if (writeMode) {
                updateWriteMode(ref e);
                print("writemode");
                return;
            }
            // Rename Action 
            else if (UnityEngine.Input.GetKey(KeyCode.F2))
            {
                textMesh = select.GetComponentInChildren<TextMesh>();
                renameAction = new RenameAction(textMesh);
                writeMode = true;
            }
            // Action avec la touche "Controle"
            else if (UnityEngine.Input.GetKey(KeyCode.LeftControl)) {
                // Selection des objets avec les fleches directionnelles
                InputLeftControlAction();
            }
            // Action sans la touche "Controle"
            else { 
                // A: AddAction
                if (UnityEngine.Input.GetKeyDown(KeyCode.A))
                {
                    addObject();
                    print("action: add");
                }
                // D: RemoveAction
                else if (UnityEngine.Input.GetKeyDown(KeyCode.D) && !deleteMode)
                {
                    // Remove Action
                    /*RemoveAction removeAction = new RemoveAction(this.select);
                    base.managerListener.doAction(removeAction);
                    print("action: remove");

                    // Supprimer de l'arbre pour ne plus pouvoir le selectionner
                    this.nodeCourant = this.nodeCourant.Remove();
                    */

                    // Remove Action
                    RemoveAction removeAction = new RemoveAction(ref this.nodeCourant);
                    base.managerListener.doAction(removeAction);
                    print("action: remove");

                    this.nodeCourant = removeAction.NodeCourant;

                    // Selectionner le precedent
                    if (this.nodeCourant == null) {
                        Select(instance);
                    } else {
                        Select(nodeCourant.Gameobject);
                    }
                    deleteMode = true;
                }
                else if (UnityEngine.Input.GetKeyUp(KeyCode.D) && deleteMode)
                {
                    deleteMode = false;
                }
                // U: UndoAction
                else if (UnityEngine.Input.GetKeyDown(KeyCode.U))
                {
                    base.managerListener.undoAction();
                    print("action: undo");
                }
                // R: RedoAction
                else if (UnityEngine.Input.GetKeyDown(KeyCode.R))
                {
                    base.managerListener.redoAction();
                    print("action: redo");
                }
                // Deplacer un objet selectionne avec les fleches directionnelles
                else {
                    InputMoveAction();
                    
                }
            }
        }
		public void onGamePadEvent(ref Event e)
		{
			if (writeMode) {
				updateWriteMode(ref e);
				print("writemode");
				return;
			}
			// Rename Action 
			else if (UnityEngine.Input.GetKey(KeyCode.Joystick1Button1)) // A button
			{
				textMesh = select.GetComponentInChildren<TextMesh>();
				renameAction = new RenameAction(textMesh);
				writeMode = true;
			}
			else if (UnityEngine.Input.GetKey(KeyCode.Joystick1Button6)) { // LT button
				InputLeftControlAction();
			}
			else { 
					if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button3)) // Y button
				{
					AddAction addAction = new AddAction(PrimitiveType.Cube, new Vector3(0, 0, -8));
					base.managerListener.doAction(addAction);
					print("action: add");

					this.nodeCourant.Add(new Node(addAction.GameObject));
				}
					else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button2) && !deleteMode) // B button
				{
					RemoveAction removeAction = new RemoveAction(ref this.nodeCourant);
					base.managerListener.doAction(removeAction);
					print("action: remove");

					this.nodeCourant = removeAction.NodeCourant;

					if (this.nodeCourant == null) {
						Select(instance);
					} else {
						Select(nodeCourant.Gameobject);
					}
					deleteMode = true;
				}
					else if (UnityEngine.Input.GetKeyUp(KeyCode.Joystick1Button2) && deleteMode) // B button
				{
					deleteMode = false;
				}
					else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button5)) // RB button
				{
					base.managerListener.undoAction();
					print("action: undo");
				}
					else if (UnityEngine.Input.GetKeyDown(KeyCode.Joystick1Button4)) // LB button
				{
					base.managerListener.redoAction();
					print("action: redo");
				}
				else {
					InputMoveAction();

				}
			}
		}