Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     // Unmapped Everything
     for (int i = 0; i < commandListDEFAUT.Length; i++)
     {
         commandListDEFAUT[i] = new Unmapped();
     }
     // Set Default Mappings
     commandListDEFAUT[KeyCode.W.GetHashCode()] = new MoveForward();
     commandListDEFAUT[KeyCode.A.GetHashCode()] = new MoveLeft();
     commandListDEFAUT[KeyCode.S.GetHashCode()] = new MoveBackward();
     commandListDEFAUT[KeyCode.D.GetHashCode()] = new MoveRight();
     commandListDEFAUT[KeyCode.Z.GetHashCode()] = new UndoLast();
     //
     currentMappingForward  = KeyCode.W.GetHashCode();
     currentMappingBackward = KeyCode.S.GetHashCode();
     currentMappingLeft     = KeyCode.A.GetHashCode();
     currentMappingRight    = KeyCode.D.GetHashCode();
     //
     commandListUSER = commandListDEFAUT;
 }
Exemplo n.º 2
0
        //
        private void OnGUI()
        {
            Event e = Event.current;

            if (e.isKey)
            {
                if (Input.GetKeyDown(e.keyCode) && !remappingKeys)
                {
                    commandListUSER[e.keyCode.GetHashCode()].Execute(this.gameObject, commandListUSER[e.keyCode.GetHashCode()]);
                }

                // Cancel the Remapping
                if (remappingKeys && (e.keyCode == KeyCode.Escape))
                {
                    remappingWhat = "Nothing";
                    remappingKeys = false;
                }
                //
                if (remappingKeys && remappingWhat == "Forward" && (e.keyCode != KeyCode.Escape))
                {
                    // Clear old mapping
                    commandListUSER[currentMappingForward] = new Unmapped();
                    // Map new
                    commandListUSER[e.keyCode.GetHashCode()] = new MoveForward();
                    currentMappingForward   = e.keyCode.GetHashCode();
                    remappingWhat           = "Nothing";
                    remappingKeys           = false;
                    buttonRemapForward.text = "Click to Remap";
                }
                if (remappingKeys && remappingWhat == "Backward" && (e.keyCode != KeyCode.Escape))
                {
                    // Clear old mapping
                    commandListUSER[currentMappingBackward] = new Unmapped();
                    // Map new
                    commandListUSER[e.keyCode.GetHashCode()] = new MoveBackward();
                    remappingWhat            = "Nothing";
                    remappingKeys            = false;
                    buttonRemapBackward.text = "Click to Remap";
                }
                if (remappingKeys && remappingWhat == "Left" && (e.keyCode != KeyCode.Escape))
                {
                    // Clear old mapping
                    commandListUSER[currentMappingLeft] = new Unmapped();
                    // Map new
                    commandListUSER[e.keyCode.GetHashCode()] = new MoveLeft();
                    remappingWhat        = "Nothing";
                    remappingKeys        = false;
                    buttonRemapLeft.text = "Click to Remap";
                }
                if (remappingKeys && remappingWhat == "Right" && (e.keyCode != KeyCode.Escape))
                {
                    // Clear old mapping
                    commandListUSER[currentMappingRight] = new Unmapped();
                    // Map new
                    commandListUSER[e.keyCode.GetHashCode()] = new MoveRight();
                    remappingWhat         = "Nothing";
                    remappingKeys         = false;
                    buttonRemapRight.text = "Click to Remap";
                }
            }
        }