Example #1
0
    public override void Update()
    {
        Vector3 vector3;
        Vector3 vector31;

        if (this.m_target != null)
        {
            CBall component = this.m_target.GetComponent <CBall>();
            if (component == null)
            {
                this.m_cameraTransform.position = this.m_initialPosition + this.CamOffset;
                this.m_cameraTransform.LookAt(this.m_target.transform.position);
            }
            else
            {
                BallTrajectory trajectory = component.GetTrajectory();
                if (trajectory != null && trajectory.m_points.Count != 0)
                {
                    BallTrajectory.Point item = component.GetTrajectory().m_points[0];
                    this.lastGoodStartLocation = item.pos;
                    BallTrajectory.Point point = component.GetTrajectory().m_points[component.GetTrajectory().firstBounceFrame];
                    this.lastGoodBallLanding = point.pos;
                    this.lastGoodBallResting = component.GetTrajectory().GetRestingPosition();
                }
                if ((this.lastGoodBallLanding - this.lastGoodStartLocation).magnitude >= (this.lastGoodBallResting - this.lastGoodStartLocation).magnitude)
                {
                    vector3  = this.lastGoodBallResting;
                    vector31 = this.lastGoodBallLanding;
                }
                else
                {
                    vector3  = this.lastGoodBallLanding;
                    vector31 = this.lastGoodBallResting;
                }
                Vector3 vector32 = vector31 - vector3;
                float   single   = vector32.magnitude / 2f;
                vector32.Normalize();
                Vector3 vector33 = vector3 + (vector32 * single);
                Vector3 vector34 = Vector3.Cross(Vector3.up, vector32);
                if (vector33.x > this.lastGoodStartLocation.x)
                {
                    vector34 *= -1f;
                }
                vector34  *= 2f;
                vector34.y = 0.5f;
                this.m_cameraTransform.position = vector33 + vector34;
                this.m_cameraTransform.LookAt(this.m_target.transform);
            }
        }
    }
Example #2
0
 public void AddPoint(Vector3 pos, float deltaTime)
 {
     BallTrajectory.Point point = new BallTrajectory.Point();
     if (this.m_points.Count != 0)
     {
         Assert(deltaTime > 0f);
         BallTrajectory.Point item = this.m_points[this.m_points.Count - 1];
         point.time = item.time + deltaTime;
     }
     else
     {
         Assert(deltaTime == 0f);
         point.time = 0f;
     }
     point.pos = pos;
     this.m_points.Add(point);
 }
Example #3
0
    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);
        }
    }
Example #4
0
 public Vector3 GetRestingPosition()
 {
     BallTrajectory.Point item = this.m_points[this.m_points.Count - 1];
     return(item.pos);
 }