public void endBind() { binding = false; if (textToBind != null && groupToBind != null) { textToBind.text = groupToBind[0].currentKey.ToString(); } textToBind = null; groupToBind = null; mouseDown = false; if (buttonToBind != null) { buttonToBind.EndBind(); } buttonToBind = null; }
private void SetUpControlsMenu() { keybindButtons = new List <KeybindButton>(); int controlsCount = System.Enum.GetValues(typeof(GameControls)).Length; float yScale = keybindButtonPrefab.GetComponent <RectTransform>().sizeDelta.y; contentWindow.sizeDelta = new Vector2(contentWindow.sizeDelta.x, (controlsCount - 1) * yScale); // count - 1 so ESCAPE can't be rebound for (int i = 0; i < controlsCount - 1; i++) { GameControls c = (GameControls)i; KeybindButton keybindButton = Instantiate(keybindButtonPrefab, contentWindow); keybindButton.SetUp(-yScale * i, c, KeybindingController.GetKeybindName(c)); keybindButtons.Add(keybindButton); } uiBlocker.SetActive(false); keybindExplanation.SetActive(false); }
public void startBind(GameObject obj, List <ActionType> group) { KeybindButton kbb = obj.GetComponent <KeybindButton>(); if (binding) { if (kbb.keyLabel == textToBind && group == groupToBind) { endBind(); return; } endBind(); } buttonToBind = kbb; textToBind = kbb.keyLabel; groupToBind = group; binding = true; kbb.keyLabel.text = "Cancel"; mouseDown = true; }
public void CreateKeybindButtons(List <List <ActionType> >[] groups, StateManager.View[] gameModes) { if (KeyButtonPrefab == null) { Debug.Log("Keybind Button Prefab was null."); return; } RectTransform buttonSize = KeyButtonPrefab.GetComponent <RectTransform> (); int xPos = (int)((Screen.width / 2) * -0.9) - (int)(buttonSize.rect.width * canvas.scaleFactor) + (int)canvas.transform.position.x; int yPos = (int)(Screen.height * 0.85); foreach (StateManager.View v in gameModes) { if (groups[(int)v].Count > 0) { xPos += (int)(buttonSize.rect.width * canvas.scaleFactor * 1.2); } yPos = (int)(Screen.height * 0.85); foreach (List <ActionType> group in groups[(int)v]) { GameObject keyButton = Instantiate(KeyButtonPrefab); KeybindButton buttonScript = keyButton.GetComponent <KeybindButton> (); keyButton.transform.SetParent(keybindMenu.transform, false); buttonScript.Init(group); keyButton.transform.position = new Vector3(xPos, yPos, 0); float realXPos = keyButton.transform.localPosition.x; float realYPos = keyButton.transform.localPosition.y; yPos -= (int)(buttonSize.rect.height * canvas.scaleFactor * 1.5); if (yPos < buttonSize.rect.height * canvas.scaleFactor * 1.5) { xPos += (int)(buttonSize.rect.width * canvas.scaleFactor * 1.2); yPos = (int)(Screen.height * 0.85); } } } }