public void RefreshSelectedEntity() { if (SELECTED_GAME_ENTITY != null) { if (SELECTED_GAME_ENTITY.entityType == "UNIT") { UnitClass unit = SELECTED_GAME_ENTITY.GetComponent <UnitClass>(); // Show new moves // Show moves (if own unit) if (unit.playerTeam == PLAYER_TEAM && unit.ACTION_READY) { unit.ShowMoves(); } // Set UI entityMenu.SetSelectedEntity(SELECTED_GAME_ENTITY); if (SELECTED_GAME_ENTITY.GetComponent <UnitClass>().unitHP <= 0) { entityMenu.SetVisible(false); } else { entityMenu.SetVisible(true); } } } else { entityMenu.SetVisible(false); } }
// Entity selection functions public void SetSelectedEntity(EntityClass selectedEntity) { // Hide any previously shown available moves HideIndicatorPlanes(); // Remove focus from previously focused unit if (selectedEntity == SELECTED_GAME_ENTITY || selectedEntity == null) { // Remove entity arrow GameObject[] oldArrows = GameObject.FindGameObjectsWithTag("EntityArrow"); foreach (GameObject arrow in oldArrows) { Destroy(arrow); } SELECTED_GAME_ENTITY = null; entityMenu.SetVisible(false); } else { // Set SELECTED_GAME_OBJECT SELECTED_GAME_ENTITY = selectedEntity; // Remove entity and then reset arrow GameObject[] oldArrows = GameObject.FindGameObjectsWithTag("EntityArrow"); foreach (GameObject arrow in oldArrows) { Destroy(arrow); } GameObject newEntityArrow = Instantiate(selectedEntityArrow); newEntityArrow.transform.SetParent(selectedEntity.transform, false); newEntityArrow.transform.position = new Vector3(selectedEntity.transform.position.x, selectedEntity.transform.position.y, selectedEntity.transform.position.z); if (selectedEntity.entityType == "UNIT") { UnitClass unit = selectedEntity.GetComponent <UnitClass>(); // Show moves (if own unit) if (unit.playerTeam == PLAYER_TEAM && unit.ACTION_READY) { unit.ShowMoves(); } // Set UI entityMenu.SetSelectedEntity(SELECTED_GAME_ENTITY); if (unit.unitHP <= 0) { entityMenu.SetVisible(false); } else { entityMenu.SetVisible(true); } } } }
// TODO: put in update? public void SetSelectedEntity(EntityClass selectedObject) { // Set new SELECTED_GAME_OBJECT SELECTED_GAME_OBJECT = selectedObject; if (selectedObject.entityType == "UNIT") { UnitClass selectedUnit = SELECTED_GAME_OBJECT.GetComponent <UnitClass>(); // Set AttackMenu SetAttackMenu(); // Update menu with SELECTED_GAME_OBJECT profImage.texture = selectedUnit.unitProfileTexture; unitName.text = selectedUnit.entityName; unitMaxHP.text = (selectedUnit.unitHPMax).ToString(); unitHP.text = (selectedUnit.unitHP).ToString(); unitMaxMP.text = (selectedUnit.unitMPMax).ToString(); unitMP.text = (selectedUnit.unitMP).ToString(); // Set Entity Menu status bar entityMenuStatusBar.GetComponent <EntityMenuStatusBar>().unit = selectedUnit; // Fill HP bar float REMAINING_HP_RATIO = ((float)selectedUnit.unitHP) / (selectedUnit.unitHPMax); unitHPBar.fillAmount = REMAINING_HP_RATIO; // Fill MP bar float REMAINING_MP_RATIO = ((float)selectedUnit.unitMP) / (selectedUnit.unitMPMax); unitMPBar.fillAmount = REMAINING_MP_RATIO; } }
// BUTTONS void AttackButton() { SELECTED_GAME_OBJECT.GetComponent <UnitClass>().ShowAttacks(); }