public static int ActionButtonIndex(NodeChoice.Choices nextNodeChoice) { switch (nextNodeChoice) { case NodeChoice.Choices.AttackRightArm: return(0); case NodeChoice.Choices.AttackLeftArm: return(1); case NodeChoice.Choices.RepairRightArm: return(2); case NodeChoice.Choices.RepairLeftArm: return(3); case NodeChoice.Choices.RepairBody: return(4); case NodeChoice.Choices.None: return(-1); default: return(-1); } }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.O)) { StartTurn(); } if (Input.GetKeyDown(KeyCode.P)) { EndTurn(); } if (Input.GetKeyDown(KeyCode.UpArrow)) { NodeChoice currentNode = NodeChoices[currentIndexChoice]; NodeChoice.Choices nextNodeChoice = currentNode.UpChoice; SelectAction(nextNodeChoice); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { NodeChoice currentNode = NodeChoices[currentIndexChoice]; NodeChoice.Choices nextNodeChoice = currentNode.DownChoice; SelectAction(nextNodeChoice); } else if (Input.GetKeyDown(KeyCode.RightArrow)) { NodeChoice currentNode = NodeChoices[currentIndexChoice]; NodeChoice.Choices nextNodeChoice = currentNode.RightChoice; SelectAction(nextNodeChoice); } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { NodeChoice currentNode = NodeChoices[currentIndexChoice]; NodeChoice.Choices nextNodeChoice = currentNode.LeftChoice; SelectAction(nextNodeChoice); } if (Input.GetKeyDown(KeyCode.Space)) { // if (playerTurn == false) DO NOTHING // TODO: bind keyboard action to trigger the action commande. //ActionButtons[nextActionButtonIndex].GetComponent<Button>().TriggerClickAction } }
void SelectAction(NodeChoice.Choices nextNodeChoice) { if (!playerTurn) { return; } int nextActionButtonIndex = NodeChoice.ActionButtonIndex(nextNodeChoice); if (nextActionButtonIndex < 0) { return; } previousIndexChoice = currentIndexChoice; currentIndexChoice = nextActionButtonIndex; if (previousIndexChoice != -1) { ActionButtons[previousIndexChoice].GetComponent <Image>().color = NotSelectedButtonColor; } ActionButtons[nextActionButtonIndex].GetComponent <Image>().color = SelectedButtonColor; }