public GameObject Create(XboxKey key, RectTransform transform) { ButtonCount = 1; RectTransform original = GetComponent <RectTransform>(); if (original == null) { Debug.Log("Create(): Failed to get RectTransform"); } Image image = GetComponent <Image>(); if (image == null) { Debug.Log("Create(): Failed to get Image Script"); } if (image.sprite == null) { Debug.Log("Create(): Image.sprite is null. Halp"); } Start(); original = transform; switch (key) { case XboxKey.A: if (image.sprite == null) { Debug.Log("image.sprite is null"); } if (imagesDB == null) { Debug.Log("imagesDB is null"); } image.sprite = imagesDB.ABtn; break; case XboxKey.B: image.sprite = imagesDB.BBtn; break; case XboxKey.X: image.sprite = imagesDB.XBtn; break; case XboxKey.Y: image.sprite = imagesDB.YBtn; break; case XboxKey.LeftShoulder: image.sprite = imagesDB.LeftShoulder; break; case XboxKey.RightShoulder: image.sprite = imagesDB.RightShoulder; break; } this.key = key; return(this.gameObject); }
public InputKey(string name, string keyboardKey, XboxKey xboxKey) { setName(name); this.keyboardKey = keyboardKey; this.xboxKey = xboxKey; lookupName = true; isKey = true; inputKey = this; }
public InputKey(string name, KeyCode keyCode, XboxKey xboxKey) { setName(name); this.keyCode = keyCode; this.xboxKey = xboxKey; lookupName = false; isKey = true; inputKey = this; }
public static int getAmmo(XboxKey key) { for (int i = 0; i < buttonList.Count; i++) { if (buttonList[i] is UIbutton) { UIbutton tmp = (UIbutton)buttonList[i]; if (tmp.key == key) { return(tmp.ammo); } } } return(-1); }
public static bool getAble(XboxKey key) { for (int i = 0; i < buttonList.Count; i++) { if (buttonList[i] is UIbutton) { UIbutton tmp = (UIbutton)buttonList[i]; if (tmp.key == key) { return(tmp.isAble); } } } Debug.Log("Couldn't find, returning false"); return(false); }
public static void callReload(XboxKey key) { Debug.Log("Reloading!"); for (int i = 0; i < buttonList.Count; i++) { if (buttonList[i] is UIbutton) { UIbutton tmp = (UIbutton)buttonList[i]; if (tmp.key == key) { buttonDetails dets = tmp.Gamebutton.GetComponent <buttonDetails>(); dets.reload(); break; } } } }
public static int resetAmmo(XboxKey key) { for (int i = 0; i < buttonList.Count; i++) { if (buttonList[i] is UIbutton) { UIbutton tmp = (UIbutton)buttonList[i]; if (tmp.key == key) { tmp.ammo = tmp.fullAmmo; buttonList[i] = tmp; callUpdateAmmoAmount(i, tmp.fullAmmo); return(tmp.ammo); } } } return(-1); }
//single Key method for adding a button public static void AddButton(XboxKey key, string weaponName, float refreshTime, int ammo) { //this method assumes the caller knows what they're doing //will add duplicates GameObject temp = Instantiate(btnTemplate); temp.transform.SetParent(HUDCanvas.transform, false); buttonDetails dets = temp.GetComponent <buttonDetails>(); RectTransform Rtransform = btnTemplate.GetComponent <RectTransform>(); dets.updateInfo(weaponName, refreshTime, ammo, true); GameObject button = dets.Create(key, Rtransform); //change position by size and add padding RectTransform newTransform = button.GetComponent <RectTransform>(); Vector2 anchored = newTransform.anchoredPosition; float posY; if (buttonList.Count == 0) { posY = startPosition.y; } else { posY = startPosition.y - (paddingY * buttonList.Count) - (Rtransform.rect.height * buttonList.Count); } Debug.Log("posY: " + posY); anchored.y = posY; anchored.x = startPosition.x; newTransform.anchoredPosition = anchored; //Set btnData and add it to the list UIbutton btnData; btnData.key = key; btnData.keyCount = 1; btnData.Gamebutton = button; btnData.ammo = ammo; btnData.isAble = true; btnData.fullAmmo = ammo; buttonList.Add(btnData); }
public void setXboxKey(XboxKey xboxKey) { this.xboxKey = xboxKey; }
public static ButtonState getButtonState(XboxKey key, bool current) { switch (key) { case XboxKey.A: if (current) { return(currentInput.currentState.Buttons.A); } else { return(currentInput.previousState.Buttons.A); } case XboxKey.B: if (current) { return(currentInput.currentState.Buttons.B); } else { return(currentInput.previousState.Buttons.B); } case XboxKey.Back: if (current) { return(currentInput.currentState.Buttons.Back); } else { return(currentInput.previousState.Buttons.Back); } case XboxKey.Guide: if (current) { return(currentInput.currentState.Buttons.Guide); } else { return(currentInput.previousState.Buttons.Guide); } case XboxKey.LeftShoulder: if (current) { return(currentInput.currentState.Buttons.LeftShoulder); } else { return(currentInput.previousState.Buttons.LeftShoulder); } case XboxKey.LeftStick: if (current) { return(currentInput.currentState.Buttons.LeftStick); } else { return(currentInput.previousState.Buttons.LeftStick); } case XboxKey.RightShoulder: if (current) { return(currentInput.currentState.Buttons.RightShoulder); } else { return(currentInput.previousState.Buttons.RightShoulder); } case XboxKey.RightStick: if (current) { return(currentInput.currentState.Buttons.RightStick); } else { return(currentInput.previousState.Buttons.RightStick); } case XboxKey.Start: if (current) { return(currentInput.currentState.Buttons.Start); } else { return(currentInput.previousState.Buttons.Start); } case XboxKey.X: if (current) { return(currentInput.currentState.Buttons.X); } else { return(currentInput.previousState.Buttons.X); } case XboxKey.Y: if (current) { return(currentInput.currentState.Buttons.Y); } else { return(currentInput.previousState.Buttons.Y); } case XboxKey.DPadLeft: if (current) { return(currentInput.currentState.DPad.Left); } else { return(currentInput.previousState.DPad.Left); } case XboxKey.DPadRight: if (current) { return(currentInput.currentState.DPad.Right); } else { return(currentInput.previousState.DPad.Right); } case XboxKey.DPadDown: if (current) { return(currentInput.currentState.DPad.Down); } else { return(currentInput.previousState.DPad.Down); } case XboxKey.DPadUp: if (current) { return(currentInput.currentState.DPad.Up); } else { return(currentInput.previousState.DPad.Up); } default: Debug.LogWarning("getButtonState(): could not find button"); return(new ButtonState()); } }