public void ChangeKeyBinding(Button b, InputManager.Key newKey) { if (buttons.ContainsKey(b)) { buttons[b] = newKey; } else { buttons.Add(b, newKey); } }
void RefreshKeyLabels() { InputManager input = InputManager.instance; for (int i = 0; i < mItems.Length; i++) { InputManager.Key key = input.GetBindKey(playerIndex, actions[i].index, actions[i].keys[0]); mItems[i].primaryLabel.text = key.isValid ? key.GetKeyString() : "None"; key = input.GetBindKey(playerIndex, actions[i].index, actions[i].keys[1]); mItems[i].secondaryLabel.text = key.isValid ? key.GetKeyString() : "None"; } LayoutBase.RefreshNow(transform); }
void Update() { if (mBindActive) { if (mActionBindInd != -1 && mActionBindKeyInd != -1) { InputManager input = InputManager.instance; bool done = false; if (UnityEngine.Input.GetKeyDown(KeyCode.Escape)) { done = true; } else { //hm for (int i = 0; i < mKeyCodes.Length; i++) { KeyCode key = (KeyCode)mKeyCodes.GetValue(i); if (UnityEngine.Input.GetKeyDown(key)) { ActionData dat = actions[mActionBindInd]; InputManager.Key keyDat = input.GetBindKey(mPlayerInd, dat.index, dat.keys[mActionBindKeyInd]); //check if this key is already bound, //if so, then just swap keycode InputManager.Key conflictKeyDat = null; for (int a = 0; a < actions.Length; a++) { if (a != mActionBindInd) { for (int k = 0; k < actions[a].keys.Length; k++) { InputManager.Key kDat = input.GetBindKey(mPlayerInd, actions[a].index, actions[a].keys[k]); if (kDat.code == key) { conflictKeyDat = kDat; break; } } } else { for (int k = 0; k < actions[a].keys.Length; k++) { if (k != mActionBindKeyInd) { InputManager.Key kDat = input.GetBindKey(mPlayerInd, actions[a].index, actions[a].keys[k]); if (kDat.code == key) { conflictKeyDat = kDat; break; } } } } if (conflictKeyDat != null) { break; } } if (conflictKeyDat != null) { conflictKeyDat.SetAsKey(keyDat.code); conflictKeyDat.SetDirty(true); } keyDat.SetAsKey(key); keyDat.SetDirty(true); done = true; mIsDirty = true; break; } } } if (done) { mLastActionBindInd = mActionBindInd; mLastActionBindKeyInd = mActionBindKeyInd; mActionBindInd = -1; mActionBindKeyInd = -1; mLastTime = Time.realtimeSinceStartup; Localize.instance.Refresh(); //for labels using input stuff } } else if (Time.realtimeSinceStartup - mLastTime >= 0.2f) { mBindActive = false; BindFinish(mLastActionBindInd, mLastActionBindKeyInd); if (bindFinishCallback != null) { bindFinishCallback(this, mLastActionBindInd, mLastActionBindKeyInd); } } } }
public InputEvent(InputManager.Key key) { this.key = key; }