void Update() { // Return if game is not active if (gameRef == null || !gameRef.enabled) { return; } State state = gameRef.GetState(); if (!renderPowerbar) { powerbarParent.SetActive(false); distanceDisplay.SetActive(true); distanceText.text = MathUtil.ToYards(gameRef.GetCurrentDistance().GetCurrentDistance()).ToString("F2") + "y"; } else { powerbarParent.SetActive(true); distanceDisplay.SetActive(false); } // ShotMode Mode m = gameRef.GetShotMode().GetShotMode(); switch (m) { case Mode.NORMAL: barColor = Color.yellow; powerBarIcon.texture = normalSprite; powerShotsRemaining.color = Color.gray; powerShotsRemaining.text = gameRef.GetShotMode().GetPowerShots().ToString(); break; case Mode.POWER: barColor = Color.red; powerBarIcon.texture = powerSprite; powerShotsRemaining.color = Color.white; powerShotsRemaining.text = gameRef.GetShotMode().GetPowerShots().ToString(); break; case Mode.APPROACH: barColor = Color.green; powerBarIcon.texture = approachSprite; powerShotsRemaining.text = "A"; break; default: throw new Exception(String.Format("Unsupported shot mode {0}", m)); } fillBar.color = barColor; negBar.color = barColor; barBackground.color = Color.Lerp(barColor, Color.black, .5f); // Powerbar update. Do this every frame. Rest can be done whenever current = (float)gameRef.GetPowerbar().GetCurrent(); power = (float)gameRef.GetPowerbar().GetPower(); accuracy = (float)gameRef.GetPowerbar().GetAccuracy(); fillBar.fillAmount = current; negBar.fillAmount = (current >= -Powerbar.NEGATIVE_PART) ? -current : Powerbar.NEGATIVE_PART; powerMarker.value = (power == 0) ? current : power; if (current >= 0) { accMarker.gameObject.SetActive(true); accMarkerNeg.gameObject.SetActive(false); } else { accMarker.gameObject.SetActive(false); accMarkerNeg.gameObject.SetActive(true); } accMarker.value = (accuracy == 0) ? current : accMarker.value; accMarkerNeg.value = (accuracy == 0) ? -current : accMarkerNeg.value; int maxVal = (int)MathUtil.ToYardsRounded(gameRef.GetBag().GetClub().GetDistance()); underText[0].text = (int)((float)maxVal) + "y"; underText[1].text = (int)((float)maxVal * .75f) + "y"; underText[2].text = (int)((float)maxVal * .5f) + "y"; underText[3].text = (int)((float)maxVal * .25f) + "y"; // Bag update clubText.text = gameRef.GetBag().GetClub().GetName(); remYdText.text = "Pin: " + (int)gameRef.GetBall().DistanceToHole() + "y"; clubMaxText.text = maxVal + "y"; // Hole info update HoleInfo holeInfo = gameRef.GetHoleInfo(); HoleData holeData = gameRef.GetHoleBag().GetCurrentHoleData(); holeText.text = gameRef.GetHoleBag().GetCurrentHoleNumber().ToString(); parText.text = "Par " + holeInfo.GetPar().ToString(); yardText.text = MathUtil.ToYardsRounded(holeInfo.GetLength()).ToString() + "y"; strokeText.text = holeData != null?holeData.GetStrokes().ToString() : ""; // Wind info update Wind tWind = gameRef.GetWind(); Vector3 camAngles = gameRef.GetCameraObject().transform.rotation.eulerAngles; // Orient arrow correctly camAngles[1] = -camAngles[1] - MathUtil.RadsToDeg((float)tWind.GetAngle()) + 90; //Random jittering according to speed. second value is a multiplier camAngles[1] += UnityEngine.Random.Range(-tWind.GetSpeed(), tWind.GetSpeed()) * 5; camAngles[0] = 0; arrowParent.transform.eulerAngles = camAngles; windText.text = String.Format("{0}m", tWind.GetVisualSpeed().ToString("F0")); // Lie image update if (state is PrepareState) { switch (gameRef.GetBall().GetMaterialType()) { case MaterialType.GREEN: lieImage.texture = lieImageGreen; break; case MaterialType.FAIRWAY: lieImage.texture = lieImageFairway; break; case MaterialType.ROUGH: lieImage.texture = lieImageRough; break; case MaterialType.BUNKER: lieImage.texture = lieImageBunker; break; case MaterialType.WATER: lieImage.texture = lieImageWater; break; case MaterialType.NONE: lieImage.texture = lieImageNone; break; default: throw new Exception(String.Format("Unsupported MaterialType: {0}", gameRef.GetBall().GetMaterialType())); } } // Lie percentage update if (state is RunningState) { float lie = gameRef.GetBall().GetLie(); lieText.text = String.Format("{0}%", (lie * 100).ToString("F0")); } else { Tuple <float, float> lieBounds = gameRef.GetBall().GetTerrainType().GetBounds(); lieText.text = (lieBounds.Item1 == lieBounds.Item2) ? String.Format("{0}%", (lieBounds.Item1 * 100).ToString("F0")) : String.Format("{0}%-{1}%", (lieBounds.Item1 * 100).ToString("F0"), (lieBounds.Item2 * 100).ToString("F0")); } // Lie angle update if (state is PrepareState || state is IdleState) { Tuple <float, float> terrainAngle = gameRef.GetBall().GetTerrainAngle(); aAngle.text = terrainAngle.Item1.ToString("F0") + "°"; aAngle.color = Mathf.Abs(terrainAngle.Item1) < 0.5f ? WHITE : terrainAngle.Item1 < 0f ? BLUE : RED; bAngle.text = terrainAngle.Item2.ToString("F0") + "°"; bAngle.color = Mathf.Abs(terrainAngle.Item2) < 0.5f ? WHITE : terrainAngle.Item2 < 0f ? BLUE : RED; } // BonusText update List <Item> heldItems = gameRef.GetPlayerAttributes().GetHeldItems(); if (heldItems.Count <= 20) { bonusText.text = ""; foreach (Item i in heldItems) { bonusText.text += i.GetName() + "\n"; } } else { bonusText.text = "...\n"; foreach (Item i in heldItems.Skip(Math.Max(0, heldItems.Count() - 19))) { bonusText.text += i.GetName() + "\n"; } } // Player attributes update PlayerAttributes plr = gameRef.GetPlayerAttributes(); playerinfoText[0].text = (plr.GetPower() * 100).ToString("F0"); playerinfoText[1].text = (plr.GetControl() * 100).ToString("F0"); playerinfoText[2].text = (plr.GetImpact() * 100).ToString("F0"); playerinfoText[3].text = (plr.GetSpin() * 100).ToString("F0"); // ToggleText update camToggleText.text = Char.ToUpper(gameRef.GetTarget().ToString()[0]) + gameRef.GetTarget().ToString().ToLower().Substring(1); Target target = gameRef.GetTarget(); if (target == Target.BALL || target == Target.FREE) { camToggleText.text = "View Cursor"; } else { camToggleText.text = "Reset Camera"; } normalToggleText.text = gc.greenNormalMap ? "Reset Green" : "View Green Normals"; // Post hole text holeWinText.text = MathUtil.GolfTerms(holeData.GetStrokes(), holeInfo.GetPar()); // Shot Bonus update if (shotBonusActive) { if (Time.time >= shotBonusTarget) { shotBonusActive = false; shotBonusDisplay.transform.position = shotBonusDefaultPosition; shotBonusDisplay.SetActive(false); } else { shotBonusDisplay.transform.position += (Vector3.up) * Time.deltaTime * 5; } } }
void Start() { gcObject = GameObject.Find(GameController.NAME); Game game = gcObject.GetComponent <Game>(); List <HoleData> holesPlayed = game.GetHoleBag().GetHolesPlayed(); for (int i = 0; i < 18; i++) { Hole[i].text = (i + 1).ToString(); if (i < holesPlayed.Count) { HoleData h = holesPlayed[i]; Back[i].text = MathUtil.ToYardsRounded(h.GetLengthBack()).ToString(); Front[i].text = MathUtil.ToYardsRounded(h.GetLengthFront()).ToString(); if (h.GetTee() == Tee.BACK) { Back[i].fontStyle = FontStyle.Bold; } else { Front[i].fontStyle = FontStyle.Bold; } Hcp[i].text = h.GetPar().ToString(); Hcp[i].fontStyle = FontStyle.Bold; Par[i].text = h.GetHandicap().ToString("F1"); Strokes[i].text = h.GetStrokes().ToString(); Putts[i].text = h.GetPutts().ToString(); Fir[i].text = h.GetFir() ? "X" : ""; Gir[i].text = h.GetGir() ? "X" : ""; } else { Back[i].text = ""; Front[i].text = ""; Hcp[i].text = ""; Par[i].text = ""; Strokes[i].text = ""; Putts[i].text = ""; Fir[i].text = ""; Gir[i].text = ""; } moneyText.text = game.GetScore().GetEarnings().ToString(); } foreach (Text t in tot) { t.fontStyle = FontStyle.Bold; } List <HoleData> front = holesPlayed.Take(9).ToList(); tot[0].text = "OUT"; tot[1].text = (front.Sum(h => MathUtil.ToYardsRounded(h.GetLengthBack()))).ToString(); tot[2].text = (front.Sum(h => MathUtil.ToYardsRounded(h.GetLengthFront()))).ToString(); tot[3].text = front.Count > 0 ? (front.Average(h => h.GetHandicap())).ToString("F1") : ""; tot[4].text = (front.Sum(h => h.GetPar())).ToString(); tot[5].text = (front.Sum(h => h.GetStrokes())).ToString(); tot[6].text = (front.Sum(h => h.GetPutts())).ToString(); tot[7].text = (front.Sum(h => h.GetFir() ? 1 : 0)).ToString(); tot[8].text = (front.Sum(h => h.GetGir() ? 1 : 0)).ToString(); List <HoleData> back = holesPlayed.Skip(9).Take(9).ToList(); tot[9].text = "IN"; tot[10].text = (back.Sum(h => MathUtil.ToYardsRounded(h.GetLengthBack()))).ToString(); tot[11].text = (back.Sum(h => MathUtil.ToYardsRounded(h.GetLengthFront()))).ToString(); tot[12].text = back.Count > 0 ? (back.Average(h => h.GetHandicap())).ToString("F1") : ""; tot[13].text = (back.Sum(h => h.GetPar())).ToString(); tot[14].text = (back.Sum(h => h.GetStrokes())).ToString(); tot[15].text = (back.Sum(h => h.GetPutts())).ToString(); tot[16].text = (back.Sum(h => h.GetFir() ? 1 : 0)).ToString(); tot[17].text = (back.Sum(h => h.GetGir() ? 1 : 0)).ToString(); foreach (Text t in grndTot) { t.fontStyle = FontStyle.Bold; } grndTot[0].text = "TOT"; grndTot[1].text = (holesPlayed.Sum(h => MathUtil.ToYardsRounded(h.GetLengthBack()))).ToString(); grndTot[2].text = (holesPlayed.Sum(h => MathUtil.ToYardsRounded(h.GetLengthFront()))).ToString(); grndTot[3].text = holesPlayed.Count > 0 ? (holesPlayed.Average(h => h.GetHandicap())).ToString("F1") : ""; grndTot[4].text = (holesPlayed.Sum(h => h.GetPar())).ToString(); grndTot[5].text = (holesPlayed.Sum(h => h.GetStrokes())).ToString(); grndTot[6].text = (holesPlayed.Sum(h => h.GetPutts())).ToString(); grndTot[7].text = (holesPlayed.Sum(h => h.GetFir() ? 1 : 0)).ToString(); grndTot[8].text = (holesPlayed.Sum(h => h.GetGir() ? 1 : 0)).ToString(); }