Ejemplo n.º 1
0
    public static CarPropertiesSetting LoadSettingFromFile(string filename)
    {
        CarPropertiesSetting cps = new CarPropertiesSetting();

        PropertyInfo[] props = cps.GetType().GetProperties();

        if (File.Exists(filename))
        {
            string[] lines = File.ReadAllLines(filename);

            for (int i = 0; i < lines.Length; i++)
            {
                if (lines[i].Split(':').Length == 2 && lines[i].Split('=').Length == 2)
                {
                    string propName = lines[i].Split(':')[0];
                    string datatype = lines[i].Split(':')[1].Split('=')[0];
                    string strValue = lines[i].Split('=')[1];

                    for (int j = 0; j < props.Length; j++)
                    {
                        if (props[j].Name == propName)
                        {
                            props[j].SetValue(cps, getValFromStr(datatype, strValue), null);
                            break;
                        }
                    }
                }
            }
        }

        return(cps);
    }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        // Eine Datei zu jedem Model schreiben, in der der Pfad zur Properties-file steht
        // Die hier einfach laden, bzw erstellen. Dann das inputField zum Path mit dem Pfad zur Properties-file füllen. Wenn nicht, leer lassen.
        connFile = FileLoader.LoadConnFile(".\\model" + Level1.garageIndex + ".connb");
        inputPropertiesPath.text = connFile.PropertiesFile;

        if (File.Exists(connFile.PropertiesFile))
        {
            carProps = FileLoader.LoadSettingFromFile(connFile.PropertiesFile);
        }
        else
        {
            carProps = new CarPropertiesSetting();
        }

        // TODO
        // Fill inputFields with carProps

        inputPropDamperheightLF.text   = Convert.ToString(carProps.DamperHeightLF);
        inputPropDamperheightRF.text   = Convert.ToString(carProps.DamperHeightRF);
        inputPropDamperheightLR.text   = Convert.ToString(carProps.DamperHeightLR);
        inputPropDamperheightRR.text   = Convert.ToString(carProps.DamperHeightRR);
        inputPropDamperstrengthLF.text = Convert.ToString(carProps.DamperStrengthLF);
        inputPropDamperstrengthRF.text = Convert.ToString(carProps.DamperStrengthRF);
        inputPropDamperstrengthLR.text = Convert.ToString(carProps.DamperStrengthLR);
        inputPropDamperstrengthRR.text = Convert.ToString(carProps.DamperStrengthRR);
        inputPropSpringstrengthLF.text = Convert.ToString(carProps.SpringStrengthLF);
        inputPropSpringstrengthRF.text = Convert.ToString(carProps.SpringStrengthRF);
        inputPropSpringstrengthLR.text = Convert.ToString(carProps.SpringStrengthLR);
        inputPropSpringstrengthRR.text = Convert.ToString(carProps.SpringStrengthRR);

        GetComponent <Canvas>().enabled = false;
        GetComponent <Canvas>().enabled = true;
    }
Ejemplo n.º 3
0
    public static bool SavePropsToFile(CarPropertiesSetting setting, string filename)
    {
        List <string> lines = new List <string>();

        PropertyInfo[] props = setting.GetType().GetProperties();
        for (int i = 0; i < props.Length; i++)
        {
            if (props[i].CanRead && props[i].CanWrite)
            {
                lines.Add(props[i].Name + ":" + props[i].PropertyType.Name + "=" + props[i].GetValue(setting, null));
            }
        }

        File.WriteAllLines(filename, lines.ToArray());

        return(true);
    }
Ejemplo n.º 4
0
    void Start()
    {
        ConnectorFile        connFile = FileLoader.LoadConnFile(".\\model" + Level1.garageIndex + ".connb");
        CarPropertiesSetting carProps = FileLoader.LoadSettingFromFile(connFile.PropertiesFile);

        testCar.GetComponent <TestCar>().Freeze = true;
        testCar.GetComponent <TestCar>().ApplyCar(Racing.calculatedCarNew, carProps);
        testCar.transform.position = startPosition.position;

        beforeShootings = new bool[testCar.GetComponent <TestCar>().ShootingWeapon.Length];

        if (miniMap != null)
        {
            miniMap.AddObject(testCar, IpAndPort.playername);
        }

        players      = new OtherPlayer[255];
        otherPlayers = new GameObject[255];


        //Instantiate(maps[0]);
    }
Ejemplo n.º 5
0
    // 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");
        }
    }
Ejemplo n.º 6
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);
        }
    }