public void DeleteFlight(string timeOfHit) { TFlightData item = null; int num = 0; while (num < this.recentFlights.Count) { if (this.recentFlights[num].timeOfHit != timeOfHit) { num++; } else { this.recentFlights[num].ballTransform.GetComponent <CBall>().HideSelf(); item = this.recentFlights[num]; if (this.OnFlightWasDeleted != null) { this.OnFlightWasDeleted(item); } this.recentFlights[num].MarkDataForDelete(); break; } } this.PruneStorage(); }
public int AddFlight(TFlightData flight) { this.PruneStorage(); flight.SetFlagDataIsGood(); this.recentFlights.Add(flight); this.isLastFlightOk = true; return(this.recentFlights.Count - 1); }
public List <TFlightPoint> GetFlightData() { if (this.trajectory == null || this.trajectory.Count == 0) { this.trajectory = TFlightData.GenerateMissingTrajectory(this); } return(this.trajectory); }
public void DeleteFlight(TFlightData flight) { if (flight == null) { return; } this.isLastFlightOk = false; this.DeleteFlight(flight.timeOfHit); }
private int PullMaxHeight() { if (this.trajectory.Count > 0) { return(this.PullMaxHeight(ref this.trajectory)); } List <TFlightPoint> tFlightPoints = TFlightData.GenerateMissingTrajectory(this); return(this.PullMaxHeight(ref tFlightPoints)); }
public void DoReplay(TFlightData data) { if (data.isValid) { this.isReplay = true; this.originalBall = data.ballTransform.GetComponent <CBall>(); this.originalBall.gameObject.SetActive(false); this.replayBall = this.currentBall; this.replayBall.name = "Prop_Ball::Replay"; //this.replayBall.SetNewTracerMaterial(ApplicationDataManager.instance.GetTracerMaterialByColor(this.originalBall.tracerColor)); //CSimulationManager.instance.ReplayShot(data); //this.numericDisplays.ResetDials(); //this.numericDisplayStatic.ResetDials(); } }
public void MSNGR_SaveFlightData(TFlightData flightData) { if (LoginManager.IsUserLoggedIn) { Shot shot = (new ShotFlightDataConverter()).Convert(flightData); SessionAndActivityManager.Instance.AddShotToSession(shot); if (!MembershipManager.GetAccess(STSWMMSFeatureFlagType.Settings_Watch_Me)) { AppLog.Log("Shot was not saved to watch-me file because feature flag WatchMe is disabled.", true); } else { AppLog.Log("Start saving shot to watch-me file.", true); WatchmeFile.SaveShot(flightData, shot); } } }
public static void SortTFlightDataListByESN(ref List <TFlightData> list) { TFlightData tFlightDatum = new TFlightData(); for (int i = 0; i < list.Count; i++) { for (int j = i; j < list.Count; j++) { if (list[j].esnShotId < list[i].esnShotId) { tFlightDatum = list[i]; list[i] = list[j]; list[j] = tFlightDatum; } } } }
private void FixedUpdate() { if (this.m_ballNotLaunched || this.simulationComplete) { return; } TFlightData mostRecentFlight = CFlightDataStorage.instance.GetMostRecentFlight(); if (this.m_ball == null || mostRecentFlight == null) { return; } this.m_timeSinceShotEnded += Time.deltaTime; this.m_restingPosition = this.m_ball.transform.position; if (this.m_ball.isFlightComplete) { TFlightData offline = CFlightDataStorage.instance.GetMostRecentFlight(); offline.offline = this.GetOffline(); if (this.isStoringTFlightData) { Messenger <TFlightData> .Broadcast(MESSAGE_EVENTS.SHOT_COMPLETE, offline); } this.m_ball.name = "Prop_Ball::Old"; this.m_ball.PurgeTrajectoryBuffer(); this.simulationComplete = true; GameEntry.GameCore.BallEnd(m_ball); return; } if (!this.m_ballHasBounced) { this.m_landedPosition = this.m_ball.transform.position; mostRecentFlight.carry = this.GetFlightDistance(); mostRecentFlight.carryPoint = new TFlightPoint() { location = this.m_landedPosition }; if (this.m_ball.hasBallLanded) { this.m_ballHasBounced = true; } } mostRecentFlight.roll = this.GetRollDistance(); this.AddPointToFlightData(); }
public virtual bool WatchShot() { if (!this.isReplay && CSimulationManager.instance.isSimulationComplete && !this._shotValuesWasSaved) { TFlightData mostRecentFlight = CFlightDataStorage.instance.GetMostRecentFlight(); Vector2 relativeBallPos = this.GetRelativeBallPos(mostRecentFlight.carryPoint.location, this.tee.transform.position); Vector2 vector2 = this.GetRelativeBallPos(this.currentBall.transform.position, this.tee.transform.position); mostRecentFlight.carryPosX = relativeBallPos.x; mostRecentFlight.carryPosY = relativeBallPos.y; mostRecentFlight.totalPosX = vector2.x; mostRecentFlight.totalPosY = vector2.y; if (LoginManager.IsUserLoggedIn) { Shot lastShotFromCurrentActivity = SessionAndActivityManager.Instance.GetLastShotFromCurrentActivity(); lastShotFromCurrentActivity.CarryPosX = relativeBallPos.x; lastShotFromCurrentActivity.CarryPosY = relativeBallPos.y; lastShotFromCurrentActivity.TotalPosX = vector2.x; lastShotFromCurrentActivity.TotalPosY = vector2.y; lastShotFromCurrentActivity.IsDirty = true; //DatabaseManager.InsertOrUpdate<Shot>(lastShotFromCurrentActivity); } this._shotValuesWasSaved = true; } if (CSimulationManager.instance.isSimulationComplete) { if (this.ProcessWatchShot_IsSimulationComplete()) { this._shotValuesWasSaved = false; return(true); } } else if (this.currentBall.hasBallLanded && !this.ballHasLanded && !this.ignoreBallLand) { this.ProcessWatchShot_BallHasLanded(); } else if (!this.currentBall.GetTrajectory().IsMidFlight()) { this.ProcessWatchShot_Common(); } else { this.ProcessWatchShot_BallIsMidFlight(); } return(false); }
public static List <TFlightPoint> GenerateMissingTrajectory(TFlightData data) { if (data == null) { Debug.LogError("Data is null: Empty trajectory generated"); return(new List <TFlightPoint>()); } CBallFlightManager instance = CBallFlightManager.GetInstance(); if (instance == null) { Debug.LogError("Flight Manager is null: Empty trajectory generated"); return(new List <TFlightPoint>()); } if (WeatherManager.instance != null) { instance.SetWeather(WeatherManager.instance.altitude, WeatherManager.instance.temperature, WeatherManager.instance.humindity, WeatherManager.barometer, WeatherManager.instance.windSpeed, (double)WeatherManager.instance.windDirection); } else { instance.SetWeather(0, 70, 50, WeatherManager.barometer, 0, 90); } //GrassManager.instance.SetGrassType((GrassManager.GrassType)data.courseConditionId); instance.CalculateCollision((double)data.totalSpeedMPH, (double)data.launchAngle, (double)data.horizontalAngle, (double)data.backSpin, (double)data.sideSpin); Vector3 vector3 = new Vector3(118.5399f, 0.06167692f, 0f); BallTrajectory ballTrajectory = instance.CalculateFlightTrajectory(vector3, (double)data.totalSpeedMPH, (double)data.launchAngle, (double)data.backSpin, (double)(-1f * data.sideSpin), (double)data.side, data.isLefty, null); List <TFlightPoint> tFlightPoints = new List <TFlightPoint>(); for (int i = 0; i < ballTrajectory.m_points.Count; i++) { TFlightPoint tFlightPoint = new TFlightPoint() { location = ballTrajectory.m_points[i].pos, time = ballTrajectory.m_points[i].time }; tFlightPoints.Add(tFlightPoint); if (ballTrajectory.firstBounceFrame == i) { data.carryPoint = tFlightPoint; } } return(tFlightPoints); }
public static void SaveShot(TFlightData flightdata, Shot shotdata) { try { string str = Path.Combine(Application.persistentDataPath, "ShotHistory.xml"); XmlDocument xmlDocument = new XmlDocument(); if (!File.Exists(str)) { xmlDocument.AppendChild(xmlDocument.CreateElement("XML")); } else { using (FileStream fileStream = File.OpenRead(str)) { xmlDocument.Load(fileStream); } } XmlNode xmlNodes = xmlDocument.SelectSingleNode("XML"); XmlElement xmlElement = xmlDocument.CreateElement("SHOT"); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "DATETIME", flightdata.dateOfHit.ToString("G")); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "ESN", flightdata.ESN); int id = LoginManager.UserData.Id; WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "CUSTOMERID", id.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "CLUBNAME", flightdata.clubName); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "CLUBTYPE", flightdata.clubTypeID); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "SHOTID", flightdata.esnShotId.ToString()); int numberInActivity = shotdata.NumberInActivity; WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "SHOTNUMBER", numberInActivity.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "UOM", "I"); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "ALTITUDE", WeatherManager.instance.altitude.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "BALLSPEED", flightdata.totalSpeedMPH.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "CLUBHEADSPEED", flightdata.clubSpeed.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "SMASHFACTOR", flightdata.smashFactor.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "VERTICALLAUNCHANGLE", flightdata.launchAngle.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "HORIZONTALLAUNCHANGLE", flightdata.horizontalAngle.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "BACKSPIN", flightdata.backSpin.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "SIDESPIN", flightdata.sideSpin.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "TOTALSPIN", flightdata.totalSpin.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "SPINAXIS", flightdata.spinAxis.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "CARRYDISTANCE", flightdata.carry.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "ROLLDISTANCE", flightdata.roll.ToString()); float single = flightdata.carry + flightdata.roll; WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "TOTALDISTANCE", single.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "OFFLINE", flightdata.offline.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "MAXHEIGHT", flightdata.maxHeight.ToString()); WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "FLIGHTTIME", (flightdata.trajectory == null ? string.Empty : flightdata.trajectory[flightdata.trajectory.Count - 1].time.ToString())); float descentAngle = CBallFlightManager.GetInstance().DescentAngle; WatchmeFile.AddShotDataNode(xmlDocument, xmlElement, "DESCENTANGLE", descentAngle.ToString("F")); xmlNodes.AppendChild(xmlElement); using (FileStream fileStream1 = File.OpenWrite(str)) { xmlDocument.Save(fileStream1); } FileInfo fileInfo = new FileInfo(str); AppLog.Log(string.Concat("Watch-me file saved at path: ", fileInfo.FullName), true); } catch (Exception exception1) { Exception exception = exception1; AppLog.Log(string.Format("Exception during open/write watch-me file {0}. Message: {1}", "ShotHistory.xml", exception.Message), true); } }
public void LaunchBall(float launchAngle, float horizontalAngle, float totalSpeed_MPS, float attackAngle, float clubSpeed, float smashFactor, float side, string clubName, float flightDuration, float maxHeight, float backSpin, float sideSpin, float spinAxis, float totalSpin, bool isNotReplay) { bool isHandnessLefty = false; int currentGrassType; if (launchAngle < 0f) { launchAngle = 0f; } if (this.PreBallLaunchDelegate != null) { this.PreBallLaunchDelegate(); } if (this.m_ballTransform != null) { float totalSpeedMPS = totalSpeed_MPS * 2.2369f; this.m_launchPosition = this.m_ball.transform.position; Vector3 mLaunchPosition = this.m_launchPosition; Vector3 vector3 = mLaunchPosition; this.m_restingPosition = mLaunchPosition; this.m_landedPosition = vector3; CBallFlightManager.GetInstance().CalculateCollision((double)totalSpeedMPS, (double)launchAngle, (double)horizontalAngle, (double)backSpin, (double)sideSpin); if (CGameManager.instance == null) { isHandnessLefty = (!LoginManager.IsUserLoggedIn ? false : LoginManager.UserData.IsLefty); } else { //isHandnessLefty = CGameManager.instance.UiHolder.GameSettings.IsHandnessLefty; } bool flag = isHandnessLefty; //List<SimulationGreen> simulationGreens = this.GenerateGreensDataFromScene(this.m_launchPosition); BallTrajectory ballTrajectory = CBallFlightManager.GetInstance().CalculateFlightTrajectory(this.m_launchPosition, (double)(totalSpeed_MPS * 2.2369f), (double)launchAngle, (double)backSpin, (double)(sideSpin * -1f), (double)horizontalAngle, flag, null); BallTrajectory.Point endPoint = ballTrajectory.m_points[ballTrajectory.firstBounceFrame]; foreach (BallTrajectory.Point point in ballTrajectory.m_points) { if (point.pos.y > maxHeight) { maxHeight = point.pos.y; } } golfballHitData data = new golfballHitData(); data.endPoint = endPoint.pos; data.time = endPoint.time; data.maxHeight = maxHeight; data.speed = totalSpeedMPS; data.launchAngle = launchAngle; data.horizontalAngle = horizontalAngle; data.backSpin = backSpin; data.sideSpin = sideSpin; data.ball = m_ball; GameEntry.GameCore.HitGolfBall(data); UnityEngine.Debug.Log(string.Format("最大高度:{0},飞行时间{1},速度{2},发射角度{3},偏转角度{4}", maxHeight, endPoint.time, totalSpeedMPS, launchAngle, horizontalAngle)); this.SetBallTracerColor(); TFlightData tFlightDatum = new TFlightData(); tFlightDatum.ESN = (string.IsNullOrEmpty(ApplicationDataManager.instance.ESN) ? "NOESN" : string.Copy(ApplicationDataManager.instance.ESN)); tFlightDatum.esnShotId = ApplicationDataManager.instance.GenerateLocalEsnID(); tFlightDatum.timeOfHit = Time.time.ToString(); tFlightDatum.dateOfHit = DateTime.Now; tFlightDatum.ballTransform = this.m_ballTransform; tFlightDatum.attackAngle = attackAngle; tFlightDatum.clubSpeed = (float)CBallFlightManager.GetInstance().SpeedMPH; tFlightDatum.descentAngle = CBallFlightManager.GetInstance().DescentAngle; tFlightDatum.smashFactor = totalSpeedMPS / tFlightDatum.clubSpeed; tFlightDatum.backSpin = backSpin; tFlightDatum.totalSpeedMPH = totalSpeedMPS; tFlightDatum.totalSpeedMPS = totalSpeed_MPS; tFlightDatum.launchAngle = launchAngle; tFlightDatum.horizontalAngle = horizontalAngle; //数据处理 tFlightDatum.travelTime = flightDuration; tFlightDatum.maxHeight = maxHeight; tFlightDatum.side = side; tFlightDatum.sideSpin = sideSpin; tFlightDatum.isLefty = flag; tFlightDatum.spinAxis = spinAxis; tFlightDatum.totalSpin = totalSpin; TFlightData tFlightDatum1 = tFlightDatum; if (GrassManager.instance == null) { currentGrassType = 0; } else { currentGrassType = (int)GrassManager.instance.CurrentGrassType; } tFlightDatum1.courseConditionId = currentGrassType; TFlightPoint tFlightPoint = new TFlightPoint() { location = new Vector3(0f, 0f, 0f), time = 0f }; //tFlightDatum.clubName = CGameManager.instance.GetCurrentClubName(); //tFlightDatum.clubTypeID = Club.GetClubIDFromName(tFlightDatum.clubName); tFlightDatum.clubName = "ClubName"; tFlightDatum.clubTypeID = "clubTypeID"; tFlightDatum.flightColor = this.m_ball.tracerColor; if (!isNotReplay) { CFlightDataStorage.instance.ReplayShotData = tFlightDatum; } else { CFlightDataStorage.instance.AddFlight(tFlightDatum); } this.isStoringTFlightData = isNotReplay; this.m_ballNotLaunched = false; if (this.OnBallLaunched != null) { this.OnBallLaunched(); } this.m_ball.SetTrajectory(ballTrajectory); //CGameManager.instance.UiHolder.TracerManager.AddBallWithTracer(this.m_ball); } }
private void ProcessRunningState() { if (this._restartGameInited) { return; } if (this._gameInterface.IsShutDown) { this.gameState = CGameManager.GAMESTATE.SHUTDOWN; return; } if (this._gameInterface.IsNewGame || this._gameInterface.IsPlayAgain) { this.gameSubState = CGameManager.GAME_SUBSTATE.GAME_OVER; } switch (this.gameSubState) { case CGameManager.GAME_SUBSTATE.PREP_TEE: { if (this._gameInterface.PrepareTee()) { this.gameSubState = CGameManager.GAME_SUBSTATE.MOVE_TEE; } break; } case CGameManager.GAME_SUBSTATE.MOVE_TEE: { if (this._gameInterface.MoveTee()) { this.gameSubState = CGameManager.GAME_SUBSTATE.TAKE_SHOT; SecurityWrapperService.Instance.ArmBox(); } break; } case CGameManager.GAME_SUBSTATE.TAKE_SHOT: { if (this.replayShotRequested) { TFlightData mostRecentFlight = CFlightDataStorage.instance.GetMostRecentFlight(); if (mostRecentFlight != null) { this._gameInterface.DoReplay(mostRecentFlight); } this.replayShotRequested = false; } if (this._gameInterface.TakeShot()) { this.gameSubState = CGameManager.GAME_SUBSTATE.WATCH_SHOT; } break; } case CGameManager.GAME_SUBSTATE.WATCH_SHOT: { if (this._gameInterface.WatchShot()) { this.gameSubState = CGameManager.GAME_SUBSTATE.POST_SHOT; } break; } case CGameManager.GAME_SUBSTATE.POST_SHOT: { if (this._gameInterface.PostShot()) { if (!this._gameInterface.IsGameOver) { this.gameSubState = CGameManager.GAME_SUBSTATE.SET_NEXT_TURN; } else { this.gameSubState = CGameManager.GAME_SUBSTATE.GAME_OVER; } } break; } case CGameManager.GAME_SUBSTATE.SET_NEXT_TURN: { if (this._gameInterface.SetNextTurn()) { this.gameSubState = CGameManager.GAME_SUBSTATE.PREP_TEE; } break; } case CGameManager.GAME_SUBSTATE.GAME_OVER: { if (this._gameInterface.GameOver()) { this.gameSubState = CGameManager.GAME_SUBSTATE.SET_NEXT_TURN; if (this._gameInterface.IsPlayAgain) { this._gameInterface.ResetGame(); this.gameSubState = CGameManager.GAME_SUBSTATE.SET_NEXT_TURN; } if (this._gameInterface.IsNewGame) { this._restartGameInited = true; this._gameInterface.ResetGame(); this._gameInterface.ShutDownCleanUp(); base.Invoke("ReloadGameScene", 2f); } } break; } } }
public static TFlightTrajectory CalculateAverageTrajectory(IList <TFlightData> shotList, int maxPoints = 100) { List <Vector3> vector3s; TFlightPoint tFlightPoint; List <List <TFlightPoint> > lists = new List <List <TFlightPoint> >(); foreach (TFlightData tFlightDatum in shotList) { lists.Add(TFlightData.GenerateMissingTrajectory(tFlightDatum)); } List <List <TFlightPoint> > lists1 = new List <List <TFlightPoint> >(); List <List <TFlightPoint> > lists2 = new List <List <TFlightPoint> >(); for (int i = 0; i < lists.Count; i++) { int num = lists[i].IndexOf(shotList[i].carryPoint); lists1.Add(lists[i].GetRange(0, num + 2)); lists2.Add(lists[i].GetRange(num + 2, lists[i].Count - (num + 2))); } int num1 = lists1.Min <List <TFlightPoint> >((List <TFlightPoint> list) => list.Count); if (num1 > maxPoints) { num1 = maxPoints; } int num2 = lists2.Min <List <TFlightPoint> >((List <TFlightPoint> list) => list.Count); if (num2 > maxPoints) { num2 = maxPoints; } List <Vector3> vector3s1 = new List <Vector3>(new Vector3[num1]); List <Vector3> vector3s2 = new List <Vector3>(new Vector3[num2]); for (int j = 0; j < num1; j++) { for (int k = 0; k < lists1.Count; k++) { float count = (float)lists1[k].Count / (float)num1; int num3 = (int)((float)j * count); List <Vector3> item = vector3s1; vector3s = item; int num4 = j; int num5 = num4; item[num4] = vector3s[num5] + lists1[k][num3].location; } } for (int l = 0; l < num2; l++) { for (int m = 0; m < lists2.Count; m++) { float single = (float)lists2[m].Count / (float)num2; int num6 = (int)((float)l * single); List <Vector3> item1 = vector3s2; vector3s = item1; int num7 = l; int num8 = num7; item1[num7] = vector3s[num8] + lists2[m][num6].location; } } List <TFlightPoint> tFlightPoints = new List <TFlightPoint>(); for (int n = 0; n < vector3s1.Count; n++) { tFlightPoint = new TFlightPoint() { location = vector3s1[n] / (float)shotList.Count }; tFlightPoints.Add(tFlightPoint); } List <TFlightPoint> tFlightPoints1 = new List <TFlightPoint>(); for (int o = 0; o < vector3s2.Count; o++) { tFlightPoint = new TFlightPoint() { location = vector3s2[o] / (float)shotList.Count }; tFlightPoints1.Add(tFlightPoint); } return(new TFlightTrajectory(tFlightPoints, tFlightPoints1)); }