private void Awake() { if (CBallFlightManager.instance == null) { CBallFlightManager.instance = this; } }
public void SetHumidity(WeatherManager.Humidity humid) { string str = humid.ToString(); str = str.Remove(0, 1); this.humindity = (double)int.Parse(str); CBallFlightManager.GetInstance().SetWeather(this.altitude, this.temperature, this.humindity, WeatherManager.barometer, this.windSpeed, (double)this.windDirection); this.SetWindUI(); }
public void SetWindSpeed(WeatherManager.WindSpeed speed) { switch (speed) { case WeatherManager.WindSpeed.Speed_0: { this.windSpeed = 0; break; } case WeatherManager.WindSpeed.Speed_0_5: { this.windSpeed = (double)UnityEngine.Random.Range(0, 5); break; } case WeatherManager.WindSpeed.Speed_5_10: { this.windSpeed = (double)UnityEngine.Random.Range(5, 10); break; } case WeatherManager.WindSpeed.Speed_10_15: { this.windSpeed = (double)UnityEngine.Random.Range(10, 15); break; } case WeatherManager.WindSpeed.Speed_15_20: { this.windSpeed = (double)UnityEngine.Random.Range(15, 20); break; } case WeatherManager.WindSpeed.Speed_20_25: { this.windSpeed = (double)UnityEngine.Random.Range(20, 25); break; } } CBallFlightManager.GetInstance().SetWeather(this.altitude, this.temperature, this.humindity, WeatherManager.barometer, this.windSpeed, (double)this.windDirection); this.SetWindUI(); }
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 SetWindDirection(WeatherManager.WindDirection direction) { switch (direction) { case WeatherManager.WindDirection.NONE: { this.windDirection = 270f; break; } case WeatherManager.WindDirection.RANDOM: { this.windDirection = (float)(45 * UnityEngine.Random.Range(0, 8)); break; } case WeatherManager.WindDirection.NORTH: { this.windDirection = 90f; break; } case WeatherManager.WindDirection.NORTH_EAST: { this.windDirection = 45f; break; } case WeatherManager.WindDirection.EAST: { this.windDirection = 0f; break; } case WeatherManager.WindDirection.SOUTH_EAST: { this.windDirection = 315f; break; } case WeatherManager.WindDirection.SOUTH: { this.windDirection = 270f; break; } case WeatherManager.WindDirection.SOUTH_WEST: { this.windDirection = 225f; break; } case WeatherManager.WindDirection.WEST: { this.windDirection = 180f; break; } case WeatherManager.WindDirection.NORTH_WEST: { this.windDirection = 135f; break; } } this.windArrowdegrees = this.GetArrowDegrees(this.windDirection); CBallFlightManager.GetInstance().SetWeather(this.altitude, this.temperature, this.humindity, WeatherManager.barometer, this.windSpeed, (double)this.windDirection); this.SetWindUI(); }
public void SetTemp(float temp) { this.temperature = (double)temp; CBallFlightManager.GetInstance().SetWeather(this.altitude, this.temperature, this.humindity, WeatherManager.barometer, this.windSpeed, (double)this.windDirection); }
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); } }