Exemple #1
0
 protected override void ThreadFunction()
 {
     if (c != null)
     {
         car = Analyzer.AnalyzeCar(c);
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (isRunning && analyzerJob.IsDone)
        {
            isRunning = false;
            car       = analyzerJob.car;

            if (car != null)
            {
                Debug.Log("Succ calculated car");
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        counter += Time.deltaTime;
        if (counter > refreshRate)
        {
            counter = 0f;

            if (buildingCalculatorTester.Car != null)
            {
                car = buildingCalculatorTester.Car;
                refreshTexts();
            }
        }
    }
Exemple #4
0
    public void OpenGarage(int garageIndex)
    {
        selectedGarage     = garageIndex;
        Level1.garageIndex = selectedGarage;
        calculatedCar      = Analyzer.AnalyzeCar(".\\model" + selectedGarage + ".baguette");
        //calculatedCar = Analyzer.AnalyzeCarD(".\\model" + selectedGarage + ".baguette");

        if (calculatedCar != null)
        {
            textAnalyzed.text     = calculatedCar.ToString();
            buttonTestCar.enabled = true;
        }
        else
        {
            textAnalyzed.text     = "Car could not be calculated";
            buttonTestCar.enabled = false;
        }
    }
    // Use this for initialization
    void Start()
    {
        if (garageNumber != -1)
        {
            calculatedCar = Analyzer.AnalyzeCar(".\\model" + garageNumber + ".baguette");
            connFile      = FileLoader.LoadConnFile(".\\model" + garageNumber + ".connb");
            carProps      = FileLoader.LoadSettingFromFile(connFile.PropertiesFile);

            if (calculatedCar == null)
            {
                SceneManager.LoadScene("Garages");
            }
            else
            {
                car.GetComponent <TestCar>().Freeze = true;
                car.GetComponent <TestCar>().ApplyCar(calculatedCar, carProps);
                car.transform.position = new Vector3(0f, 0f, 0f);
            }
        }
        else
        {
            SceneManager.LoadScene("Garages");
        }
    }
Exemple #6
0
    public void SetPlayerCarBytes(byte playerID, byte[] carBytes)
    {
        CalculatedCar calculatedCar = Analyzer.AnalyzeCar(carBytes);

        if (otherPlayers[playerID] != null && calculatedCar != null)
        {
            OtherCar otherCar = otherPlayers[playerID].GetComponent <OtherCar>();
            otherCar.TestCar = testCar;
            otherCar.ApplyCar(calculatedCar);
            otherCar.PlayerDisplayname = players[playerID].PlayerName;
            Debug.Log("The car was applied");
        }
        else
        {
            if (calculatedCar == null)
            {
                Debug.Log("calculatedCar was null");
            }
            else
            {
                Debug.Log("otherPlayers was null");
            }
        }
    }
Exemple #7
0
    public void ApplyCar(CalculatedCar car)
    {
        steerWheelIndexes = new List <int>();
        powerWheelIndexes = new List <int>();

        if (car != null)
        {
            //mParts = new MovingPart[car.PartStatics.Length];
            List <MovingPart> tempParts = new List <MovingPart>();
            tempParts.Add(((GameObject)Instantiate(partMovingPart)).GetComponent <MovingPart>());
            tempParts[tempParts.Count - 1].tag          = gameObject.tag;
            tempParts[tempParts.Count - 1].CarReference = this;
            int vertsCount = 0;
            for (int i = 0; i < car.PartStatics.Length; i++)
            {
                //mParts[i] = ((GameObject)Instantiate(partMovingPart)).GetComponent<MovingPart>();
                //mParts[i].tag = gameObject.tag;
                //mParts[i].SetProperties(car.PartStatics[i].Type, car.PartStatics[i].Direction, car.PartStatics[i].Rotation, new Vector3Int(car.PartStatics[i].Position));
                //mParts[i].CarReference = this;

                vertsCount = tempParts[tempParts.Count - 1].AddProperties(car.PartStatics[i].Type, car.PartStatics[i].Direction, car.PartStatics[i].Rotation, new Vector3Int(car.PartStatics[i].Position));
                if (vertsCount > 50000)
                {
                    tempParts.Add(((GameObject)Instantiate(partMovingPart)).GetComponent <MovingPart>());
                    tempParts[tempParts.Count - 1].tag          = gameObject.tag;
                    tempParts[tempParts.Count - 1].CarReference = this;
                }
            }
            mParts = tempParts.ToArray();
            Debug.Log("MovingPartsAmount: " + mParts.Length);


            mMiniguns = new MovingMinigun[car.PartMiniguns.Length];
            for (int i = 0; i < car.PartMiniguns.Length; i++)
            {
                mMiniguns[i]     = ((GameObject)Instantiate(partMovingMinigun)).GetComponent <MovingMinigun>();
                mMiniguns[i].tag = gameObject.tag;
                mMiniguns[i].SetProperties(car.PartMiniguns[i].Type, car.PartMiniguns[i].Direction, car.PartMiniguns[i].Rotation, new Vector3Int(car.PartMiniguns[i].Position));
                mMiniguns[i].CarReference = this;
            }

            mPowertrainAxes = new MovingPowertrainAxe[car.PartPowertrainAxes.Length];
            for (int i = 0; i < car.PartPowertrainAxes.Length; i++)
            {
                mPowertrainAxes[i] = ((GameObject)Instantiate(partMovingPowertrainAxe)).GetComponent <MovingPowertrainAxe>();
                mPowertrainAxes[i].SetProperties(car.PartPowertrainAxes[i].Type, car.PartPowertrainAxes[i].Direction, car.PartPowertrainAxes[i].Rotation, new Vector3Int(car.PartPowertrainAxes[i].Position), car.PartPowertrainAxes[i].RotateAroundAxe, car.PartPowertrainAxes[i].FactorToWheel);
                mPowertrainAxes[i].CarReference = this;
            }

            mWheels = new MovingWheel[car.PartWheels.Length];

            //m_WheelMeshLocalRotations = new Quaternion[mWheels.Length];
            //m_WheelColliders = new WheelCollider[mWheels.Length];

            for (int i = 0; i < car.PartWheels.Length; i++)
            {
                mWheels[i] = ((GameObject)Instantiate(partMovingWheel)).GetComponent <MovingWheel>();
                mWheels[i].SetProperties(car.PartWheels[i].Type, car.PartWheels[i].Direction, car.PartWheels[i].Rotation, new Vector3Int(car.PartWheels[i].Position));
                mWheels[i].CarReference = this;

                if (car.PartWheels[i].Powering)
                {
                    powerWheelIndexes.Add(i);
                }
                if (car.PartWheels[i].Steering)
                {
                    steerWheelIndexes.Add(i);
                }

                //m_WheelColliders[i] = ((GameObject)Instantiate(wheelColliderPrefab)).GetComponent<WheelCollider>();
                //
                //m_WheelColliders[i].gameObject.transform.parent = transform;
                //
                //m_WheelColliders[i].gameObject.transform.position = car.PartWheels[i].Position;
                //m_WheelColliders[i].radius = car.PartWheels[i].Radius;
                //m_WheelMeshes[i] = mWheels[i].instPart;
                //m_WheelMeshLocalRotations[i] = m_WheelMeshes[i].transform.localRotation;
            }

            backTireRadius = car.PartWheels[2].Radius;

            float kwToTorqueFactor = 50f;
            //m_SpeedType = SpeedType.KPH;
            //m_FullTorqueOverAllWheels = car.FullTorque * kwToTorqueFactor;
            m_Topspeed = car.TopSpeed;

            //for (int i = 0; i < m_WheelColliders.Length; i++)
            //{
            //    float ffFact = 0.07f;
            //    float sfFact = 0.2f;
            //    WheelFrictionCurve ff = new WheelFrictionCurve();
            //    ff.extremumSlip = 0.4f + car.Grip * 4f * ffFact;
            //    ff.extremumValue = 1f + car.Grip * 10f * ffFact;
            //    ff.asymptoteSlip = 0.8f + car.Grip * 8f * ffFact;
            //    ff.asymptoteValue = 0.5f + car.Grip * 5f * ffFact;
            //    ff.stiffness = 1f;
            //    WheelFrictionCurve sf = new WheelFrictionCurve();
            //    sf.extremumSlip = 0.2f + car.Grip * 2f * sfFact;
            //    sf.extremumValue = 1f + car.Grip * 10f * sfFact;
            //    sf.asymptoteSlip = 0.5f + car.Grip * 5f * sfFact;
            //    sf.asymptoteValue = 0.75f + car.Grip * 7.5f * sfFact;
            //    sf.stiffness = 1f;
            //    m_WheelColliders[i].forwardFriction = ff;
            //    m_WheelColliders[i].sidewaysFriction = sf;
            //}
            //
            //m_WheelColliders[0].attachedRigidbody.centerOfMass = Vector3.zero;
            //
            //m_MaxHandbrakeTorque = float.MaxValue;

            //m_Rigidbody = GetComponent<Rigidbody>();
            //m_CurrentTorque = m_FullTorqueOverAllWheels - (m_TractionControl * m_FullTorqueOverAllWheels);

            //m_Rigidbody.mass = car.Weight;


            //transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
            transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);


            model3DLoaded = true;
        }
    }
 // Use this for initialization
 void Start()
 {
     analyzerJob = new AnalyzerJob();
     car         = null;
 }
Exemple #9
0
 public void ApplyCar(CalculatedCar car)
 {
     ApplyCar(car, null);
 }
Exemple #10
0
    public void ApplyCar(CalculatedCar car, CarPropertiesSetting carProps)
    {
        steerWheelIndexes = new List <int>();
        powerWheelIndexes = new List <int>();

        calculatedCar = car;
        carProperties = carProps;

        if (car != null)
        {
            maximumHealth = car.Health;
            currentHealth = maximumHealth;

            //mParts = new MovingPart[car.PartStatics.Length];
            List <MovingPart> tempParts = new List <MovingPart>();
            tempParts.Add(((GameObject)Instantiate(partMovingPart)).GetComponent <MovingPart>());
            tempParts[tempParts.Count - 1].tag          = gameObject.tag;
            tempParts[tempParts.Count - 1].CarReference = this;
            int vertsCount = 0;
            for (int i = 0; i < car.PartStatics.Length; i++)
            {
                //mParts[i] = ((GameObject)Instantiate(partMovingPart)).GetComponent<MovingPart>();
                //mParts[i].tag = gameObject.tag;
                //mParts[i].SetProperties(car.PartStatics[i].Type, car.PartStatics[i].Direction, car.PartStatics[i].Rotation, new Vector3Int(car.PartStatics[i].Position));
                //mParts[i].CarReference = this;

                //mParts[i] = ((GameObject)Instantiate(partMovingPart)).GetComponent<MovingPart>();
                if (vertsCount == 0)
                {
                    partDestruct = new PartConfiguration(car.PartStatics[i].Direction, car.PartStatics[i].Rotation, new Vector3Int(car.PartStatics[i].Position), car.PartStatics[i].Type);
                }
                vertsCount = tempParts[tempParts.Count - 1].AddProperties(car.PartStatics[i].Type, car.PartStatics[i].Direction, car.PartStatics[i].Rotation, new Vector3Int(car.PartStatics[i].Position));

                if (vertsCount > 50000)
                {
                    tempParts.Add(((GameObject)Instantiate(partMovingPart)).GetComponent <MovingPart>());
                    tempParts[tempParts.Count - 1].tag          = gameObject.tag;
                    tempParts[tempParts.Count - 1].CarReference = this;
                }
                Debug.Log("VertsCurrentCount: " + vertsCount);
            }
            mParts = tempParts.ToArray();
            Debug.Log("MovingPartsAmount: " + mParts.Length);

            mMiniguns = new MovingMinigun[car.PartMiniguns.Length];
            for (int i = 0; i < car.PartMiniguns.Length; i++)
            {
                mMiniguns[i]     = ((GameObject)Instantiate(partMovingMinigun)).GetComponent <MovingMinigun>();
                mMiniguns[i].tag = gameObject.tag;
                mMiniguns[i].SetProperties(car.PartMiniguns[i].Type, car.PartMiniguns[i].Direction, car.PartMiniguns[i].Rotation, new Vector3Int(car.PartMiniguns[i].Position));
                mMiniguns[i].CarReference = this;
            }


            mPowertrainAxes = new MovingPowertrainAxe[car.PartPowertrainAxes.Length];
            for (int i = 0; i < car.PartPowertrainAxes.Length; i++)
            {
                mPowertrainAxes[i]     = ((GameObject)Instantiate(partMovingPowertrainAxe)).GetComponent <MovingPowertrainAxe>();
                mPowertrainAxes[i].tag = gameObject.tag;
                mPowertrainAxes[i].SetProperties(car.PartPowertrainAxes[i].Type, car.PartPowertrainAxes[i].Direction, car.PartPowertrainAxes[i].Rotation, new Vector3Int(car.PartPowertrainAxes[i].Position), car.PartPowertrainAxes[i].RotateAroundAxe, car.PartPowertrainAxes[i].FactorToWheel);
                mPowertrainAxes[i].CarReference = this;
            }

            mSteerParts = new MovingSteerPart[car.PartSteerParts.Length];
            for (int i = 0; i < car.PartSteerParts.Length; i++)
            {
                mSteerParts[i]     = ((GameObject)Instantiate(partMovingSteerPart)).GetComponent <MovingSteerPart>();
                mSteerParts[i].tag = gameObject.tag;
                mSteerParts[i].SetProperties(car.PartSteerParts[i].Type, car.PartSteerParts[i].Direction, car.PartSteerParts[i].Rotation, new Vector3Int(car.PartSteerParts[i].Position), car.PartSteerParts[i].InvertedDirection);
                mSteerParts[i].CarReference = this;
            }

            mSteerBars = new MovingSteerBar[car.PartSteerBars.Length];
            for (int i = 0; i < car.PartSteerBars.Length; i++)
            {
                mSteerBars[i]     = ((GameObject)Instantiate(partMovingSteerBar)).GetComponent <MovingSteerBar>();
                mSteerBars[i].tag = gameObject.tag;
                mSteerBars[i].SetProperties(car.PartSteerBars[i].Type, car.PartSteerBars[i].Direction, car.PartSteerBars[i].Rotation, new Vector3Int(car.PartSteerBars[i].Position), car.PartSteerBars[i].AxeMoveAlong, car.PartSteerBars[i].HalfwayDistance);
                mSteerBars[i].CarReference = this;
            }

            mWheels = new MovingWheel[car.PartWheels.Length];

            m_WheelMeshLocalRotations = new Quaternion[mWheels.Length];
            m_WheelColliders          = new WheelCollider[mWheels.Length];

            for (int i = 0; i < car.PartWheels.Length; i++)
            {
                mWheels[i]     = ((GameObject)Instantiate(partMovingWheel)).GetComponent <MovingWheel>();
                mWheels[i].tag = gameObject.tag;
                mWheels[i].SetProperties(car.PartWheels[i].Type, car.PartWheels[i].Direction, car.PartWheels[i].Rotation, new Vector3Int(car.PartWheels[i].Position));
                mWheels[i].CarReference = this;

                if (car.PartWheels[i].Powering)
                {
                    powerWheelIndexes.Add(i);
                }
                if (car.PartWheels[i].Steering)
                {
                    steerWheelIndexes.Add(i);
                }

                m_WheelColliders[i] = ((GameObject)Instantiate(wheelColliderPrefab)).GetComponent <WheelCollider>();

                m_WheelColliders[i].gameObject.transform.parent = transform;

                m_WheelColliders[i].gameObject.transform.position = car.PartWheels[i].Position;
                m_WheelColliders[i].radius   = car.PartWheels[i].Radius;
                m_WheelMeshes[i]             = mWheels[i].instPart;
                m_WheelMeshLocalRotations[i] = m_WheelMeshes[i].transform.localRotation;
            }

            float kwToTorqueFactor = 50f;
            m_SpeedType = SpeedType.KPH;
            m_FullTorqueOverAllWheels = car.FullTorque * kwToTorqueFactor;
            m_Topspeed = car.TopSpeed;

            for (int i = 0; i < m_WheelColliders.Length; i++)
            {
                float ffFact          = 0.07f;
                float sfFact          = 0.2f;
                WheelFrictionCurve ff = new WheelFrictionCurve();
                ff.extremumSlip   = 0.4f + car.Grip * 4f * ffFact;
                ff.extremumValue  = 1f + car.Grip * 10f * ffFact;
                ff.asymptoteSlip  = 0.8f + car.Grip * 8f * ffFact;
                ff.asymptoteValue = 0.5f + car.Grip * 5f * ffFact;
                ff.stiffness      = 1f;
                WheelFrictionCurve sf = new WheelFrictionCurve();
                sf.extremumSlip   = 0.2f + car.Grip * 2f * sfFact;
                sf.extremumValue  = 1f + car.Grip * 10f * sfFact;
                sf.asymptoteSlip  = 0.5f + car.Grip * 5f * sfFact;
                sf.asymptoteValue = 0.75f + car.Grip * 7.5f * sfFact;
                sf.stiffness      = 1f;
                m_WheelColliders[i].forwardFriction  = ff;
                m_WheelColliders[i].sidewaysFriction = sf;

                JointSpring js = new JointSpring();
                //js.spring = 35000 * (car.Weight * 0.001f) * 0.6f;
                //js.damper = 4500 * (car.Weight * 0.001f) * 0.6f;
                if (carProps == null)
                {
                    js.spring = car.PartWheels[i].SpringStrength;
                    js.damper = car.PartWheels[i].DamperStrength;
                }
                else
                {
                    switch (i)
                    {
                    case 0:
                        js.spring = carProps.SpringStrengthLF;
                        js.damper = carProps.DamperStrengthLF;
                        break;

                    case 1:
                        js.spring = carProps.SpringStrengthRF;
                        js.damper = carProps.DamperStrengthRF;
                        break;

                    case 2:
                        js.spring = carProps.SpringStrengthLR;
                        js.damper = carProps.DamperStrengthLR;
                        break;

                    case 3:
                        js.spring = carProps.SpringStrengthRR;
                        js.damper = carProps.DamperStrengthRR;
                        break;
                    }
                }
                js.targetPosition = 0.5f;
                m_WheelColliders[i].suspensionSpring = js;
            }

            m_WheelColliders[0].attachedRigidbody.centerOfMass = Vector3.zero;

            m_MaxHandbrakeTorque = float.MaxValue;

            m_Rigidbody     = GetComponent <Rigidbody>();
            m_CurrentTorque = m_FullTorqueOverAllWheels - (m_TractionControl * m_FullTorqueOverAllWheels);

            m_Rigidbody.mass = car.Weight;


            //transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
            transform.localScale = new Vector3(0.3f, 0.3f, 0.3f);
        }
    }