示例#1
0
    public void SetTrajectory(BallTrajectory trajectory)
    {
        this.m_trajectory = trajectory;
        Transform vector3 = base.transform;

        vector3.position = vector3.position + new Vector3(0f, 0f, -0.1f);
        base.StartCoroutine(this.WaitFor(0.1f, () =>
        {
            this.m_trajectory.ResetTime();
            base.transform.position = this.m_trajectory.GetCurrentPosition();
            this.m_motionType       = CBall.MotionType.Trajectory;
        }));
    }
示例#2
0
    private void Awake()
    {
        this.m_motionType = CBall.MotionType.Fixed;
        this.m_trajectory = null;
        this.ballTrail    = base.GetComponent <TrailRenderer>();
        //this.mat = this.ballTrail.material;
        //this.mat2 = Resources.Load("Tracers/Tracer_MAT_3", typeof(Material)) as Material;
        //this.SetTracerInvis(true);
        Transform vector3  = base.gameObject.transform;
        float     single   = base.gameObject.transform.position.x;
        Vector3   vector31 = base.gameObject.transform.position;

        vector3.position = new Vector3(single, vector31.y, 0f);
    }
示例#3
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);
            }
        }
    }
    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);
    }
示例#5
0
    public BallTrajectory CalculateFlightTrajectory(Vector3 origin, double BallSpeed, double LaunchAngle, double BackSpin, double SideSpin, double SideAngle, bool Lefty, List <SimulationGreen> greens)
    {
        BallTrajectory ballTrajectory = new BallTrajectory();

        //this.Greens = greens;
        this.SetTerrainCoefficients(0, 0);
        this.Flight(BallSpeed, LaunchAngle, BackSpin, SideSpin, SideAngle, Lefty, (double)(origin.y * 3.28084f));

        Assert(this.TrajDt >= (long)2);
        Assert(this.TrajOffLine[0] == 0);
        Assert(this.TrajHeight[0] == 0);
        Assert(this.TrajDownRange[0] == 0);
        ballTrajectory.AddPoint(origin, 0f);
        double physicsFPS = 1 / this.PhysicsFPS;

        for (int i = 1; (long)i < this.TrajDt; i++)
        {
            Vector3 vector3 = new Vector3((float)this.TrajOffLine[i], (float)this.TrajHeight[i], (float)this.TrajDownRange[i]) * 0.3048f;
            ballTrajectory.AddPoint(origin + vector3, (float)physicsFPS);
            //AppLog.Log(string.Format("m_launchPosition {0}", vector3));
        }
        ballTrajectory.firstBounceFrame = (int)this.FirstBounceFrame;
        return(ballTrajectory);
    }
示例#6
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);
        }
    }