Inheritance: MonoBehaviour
Example #1
0
        private void OnCarDamage(Message message, IClient client)
        {
            using (DarkRiftReader reader = message.GetReader())
            {
                CarDamage  damage = reader.ReadSerializable <CarDamage>();
                WorldTrain train  = worldTrains.FirstOrDefault(t => t.Guid == damage.Guid);
                if (train == null)
                {
                    train = new WorldTrain()
                    {
                        Guid = damage.Guid,
                    };
                    worldTrains.Add(train);
                }

                switch (damage.DamageType)
                {
                case DamageType.Car:
                    train.CarHealth     = damage.NewHealth;
                    train.CarHealthData = damage.Data;
                    break;

                case DamageType.Cargo:
                    train.CargoHealth = damage.NewHealth;
                    break;
                }
            }

            Logger.Trace("[SERVER] > TRAIN_DAMAGE");
            ReliableSendToOthers(message, client);
        }
        public IActionResult FormModal(string routeValues)
        {
            string[]         split    = routeValues.Split(',');
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            provider.NumberGroupSeparator   = ",";
            provider.NumberGroupSizes       = new int[] { 3 };
            double    offsetx = Convert.ToDouble(split[0], provider);
            double    offsety = Convert.ToDouble(split[1], provider);
            Guid      id      = new Guid(split[2]);
            Guid      carId   = new Guid(split[3]);
            bool      enddmg  = false;
            CarDamage damage  = new CarDamage
            {
                OffsetX     = offsetx,
                OffsetY     = offsety,
                Id          = id,
                CarId       = carId,
                RentId      = Guid.Empty,
                IsEndDamage = enddmg,
                DateMarked  = DateTime.Now,
            };

            _carDamagesRepository.Add(damage);
            RentFormModalViewModel model = new RentFormModalViewModel
            {
                Id = id
            };

            return(PartialView(model));
        }
    private void OnEnable()
    {
        m_CarDamage  = GetComponent <CarDamage>();
        m_CarVisuals = GetComponent <CarVisuals>();
        ApplyEnabled(WheelFL, true);
        ApplyEnabled(WheelFR, true);
        ApplyEnabled(WheelRL, true);
        ApplyEnabled(WheelRR, true);

        if (CenterOfMass)
        {
            rigidbody.centerOfMass = new Vector3(CenterOfMass.localPosition.x * tr.localScale.x, CenterOfMass.localPosition.y * tr.localScale.y, CenterOfMass.localPosition.z * tr.localScale.z);
        }
        var     WheelC = WheelFL.GetComponent <WheelCollider>();
        Vector3 V      = rigidbody.centerOfMass - tr.InverseTransformPoint(WheelC.transform.position);
        float   h      = Mathf.Abs((V.y + WheelC.radius + WheelC.suspensionDistance / 2.0f) * tr.localScale.y);
        float   l      = Mathf.Abs(V.x * tr.localScale.x);

        m_maxRollAngle = Mathf.Atan2(l, h) * Mathf.Rad2Deg;
        rigidbody.maxAngularVelocity = 10;
        rigidbody.useConeFriction    = false;
        if (optimized)
        {
            ApplyCommonParameters(WheelFL);
            ApplyCommonParameters(WheelFR);
            ApplyCommonParameters(WheelRL);
            ApplyCommonParameters(WheelRR);
            WheelFL.RecalculateStuff();
            WheelFR.RecalculateStuff();
            WheelRL.RecalculateStuff();
            WheelRR.RecalculateStuff();
        }
    }
 public IActionResult PostModal(RentFormModalViewModel model)
 {
     if (ModelState.IsValid)
     {
         CarDamage damage = _carDamagesRepository.GetCarDamage(model.Id);
         damage.Description = model.Description;
         damage.DamageType  = model.DamageType;
         _carDamagesRepository.Update(damage);
     }
     return(PartialView("CloseModal"));
 }
        public IActionResult PopulateModal(Guid id)
        {
            CarDamage damage = _carDamagesRepository.GetCarDamage(id);
            RentPopulateModalViewModel model = new RentPopulateModalViewModel
            {
                DamageType  = damage.DamageType.ToString(),
                Description = damage.Description
            };

            return(PartialView(model));
        }
Example #6
0
 void Start()
 {
     if (brakeLights == null)
     {
         brakeLights = GetComponent <BrakeLights>();
     }
     if (drivetrain == null)
     {
         drivetrain = GetComponent <Drivetrain>();
     }
     if (aerodynamicResistance == null)
     {
         aerodynamicResistance = GetComponent <AerodynamicResistance>();
     }
     if (soundController == null)
     {
         soundController = GetComponent <SoundController>();
     }
     if (carDynamics == null)
     {
         carDynamics = GetComponent <CarDynamics>();
     }
     if (axles == null)
     {
         axles = GetComponent <Axles>();
     }
     if (axisCarController == null)
     {
         axisCarController = GetComponent <AxisCarController>();
     }
     if (carDamage == null)
     {
         carDamage = GetComponent <CarDamage>();
     }
     if (arcader == null)
     {
         arcader = GetComponent <Arcader>();
     }
     if (setup == null)
     {
         setup = GetComponent <Setup>();
     }
     if (bodyRb == null)
     {
         bodyRb = GetComponent <Rigidbody>();
     }
     if (camerasController == null)
     {
         camerasController = GetComponent <CamerasController>();
     }
 }
Example #7
0
 public override void OnInspectorGUI()
 {
     t         = (CarDamage)target;
     GUI.color = new Color32(255, 0, 51, 255);
     if (GUILayout.Button("Find Meshes"))
     {
         t.FindMeshes();
     }
     GUI.color = Color.white;
     DrawDefaultInspector();
     if (GUI.changed)
     {
         EditorUtility.SetDirty(t);
         EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
     }
 }
Example #8
0
	public IEnumerator ChangeCar(GameObject mselectedCar){
		if(mselectedCar!=null){
			mTransform=mselectedCar.transform;
			mrigidbody = mselectedCar.GetComponent<Rigidbody>();
			carDynamics = mselectedCar.GetComponent<CarDynamics>();
			drivetrain = mselectedCar.GetComponent<Drivetrain>();
			aerodynamicResistance = mselectedCar.GetComponent<AerodynamicResistance>();
			carDebug =  mTransform.GetComponent<CarDebug>();
			carDamage = mselectedCar.GetComponent<CarDamage>();
			carController = mselectedCar.GetComponent<CarDynamics>().carController;
			dashBoard=mselectedCar.transform.GetComponentInChildren<DashBoard>();
			arcader=mselectedCar.transform.GetComponentInChildren<Arcader>();
			setup= mselectedCar.GetComponent<Setup>();
			axles=mselectedCar.GetComponent<Axles>();
			fuelTanks=mselectedCar.GetComponentsInChildren<FuelTank>();
			currentFuels=new float[fuelTanks.Length];
			
			if (setup!=null && setup.enabled==true) {while (setup.loadingSetup==true) yield return new WaitForSeconds(0.02f);}
			if (drivetrain.engineTorqueFromFile==true) drivetrain.CalcValues(factor,drivetrain.engineTorqueFromFile);
			drivetrain.engineTorqueFromFile=false;

			if (Application.isEditor && setup!=null && setup.enabled==true){
				GridEntrys = new string[] {"Engine", "Transmission", "Suspensions", "Brakes" ,"Tires", "Body", "Assistance","Save Setup"};
				entrysCount=8;
			}
			else{
				GridEntrys = new string[] {"Engine", "Transmission", "Suspensions", "Brakes" ,"Tires", "Body", "Assistance"};
				entrysCount=7;
			}			
			
			if (arcader) arcader.enabled=false;
			m_maxTorque=drivetrain.maxTorque;
			//ESP=carController.ESP;
			selectedCar=mselectedCar;
			//carDynamics.SetTiresType();
			tiresTypeFront=(int)axles.frontAxle.tires;
			tiresTypeRear=(int)axles.rearAxle.tires;
			//drivetrain.SetTransmission(drivetrain.transmission);
			transmissionType=oldTransmissionType=(int)drivetrain.transmission;
			//SetCOGPosition(carDynamics.zlocalPosition);
			
			boundingSize=carDynamics.BoundingSize(selectedCar.GetComponentsInChildren<Collider>());
			zlocalPositionLimit=0.8f*boundingSize.x/4.5f;
						
			engageRPM=drivetrain.engageRPM;
			maxRPM=(Mathf.CeilToInt(drivetrain.maxRPM/1000)+1)*1000;
			maxKmh=Mathf.RoundToInt(maxRPM*axles.frontAxle.leftWheel.radius*2*0.1885f/(drivetrain.gearRatios[drivetrain.gearRatios.Length-1]*drivetrain.finalDriveRatio)); // Mathf.PI*3.6f/60 -> 0.1885
			mass=mrigidbody.mass;
			
			StartSize = new Vector2(Screen.width, Screen.height);
			if (grid!=null) floor=(grid.height - gridHeight)/2;
			top=gridHeight+Mathf.RoundToInt(gridHeight*0.17f)+floor;
			RectCalculation(StartSize);
			ScrollRectCalculation(StartSize, drivetrain.gearRatios.Length-2);					
			factor=1;
			if (grid!=null){
				switch(GridInt) {
					case 0: ApplyEngineTorque();break;
					case 1: ApplyGears();break;
				}
			}
		}
	}		
    private void OnEnable()
    {
        m_CarDamage = GetComponent<CarDamage>();
        m_CarVisuals = GetComponent<CarVisuals>();
        ApplyEnabled(WheelFL, true);
        ApplyEnabled(WheelFR, true);
        ApplyEnabled(WheelRL, true);
        ApplyEnabled(WheelRR, true);

        if (CenterOfMass)
            rigidbody.centerOfMass = new Vector3(CenterOfMass.localPosition.x * tr.localScale.x, CenterOfMass.localPosition.y * tr.localScale.y, CenterOfMass.localPosition.z * tr.localScale.z);
        var WheelC = WheelFL.GetComponent<WheelCollider>();
        Vector3 V = rigidbody.centerOfMass - tr.InverseTransformPoint(WheelC.transform.position);
        float h = Mathf.Abs((V.y + WheelC.radius + WheelC.suspensionDistance / 2.0f) * tr.localScale.y);
        float l = Mathf.Abs(V.x * tr.localScale.x);
        m_maxRollAngle = Mathf.Atan2(l, h) * Mathf.Rad2Deg;
        rigidbody.maxAngularVelocity = 10;
        rigidbody.useConeFriction = false;
        if (optimized)
        {
            ApplyCommonParameters(WheelFL);
            ApplyCommonParameters(WheelFR);
            ApplyCommonParameters(WheelRL);
            ApplyCommonParameters(WheelRR);
            WheelFL.RecalculateStuff();
            WheelFR.RecalculateStuff();
            WheelRL.RecalculateStuff();
            WheelRR.RecalculateStuff();
        }
    }