示例#1
0
        //-----------------------------------------------------------------------------------
        private void ChangeToReplayingModeDone()
        {
            Int64 checksum = SimulationManager.CalculateChecksum();

            CarDebug.Log(string.Format("Finished in {0:F3} secs. Checksum: " + Convert.ToString(checksum, 16), SimulationManager.GetSimulatingRealTime()));

            stopRequested_ = false;
            SimulationManager.ChangeToReplayingDone();

            manager_.BuildBakerData();
            manager_.BuildDisplayerVisibilityIntervals();

            EditorApplication.update -= UpdateSimulating;
            EditorApplication.update += UpdateReplaying;

            SimulationManager.SetReplayingFrame((uint)frame_, true);

            playbackRangeMin_ = 0;
            playbackRangeMax_ = frame_;

            SceneView.RepaintAll();
            CarManagerEditor.RepaintIfOpen();
        }
示例#2
0
	void Update() {		
		if(Input.GetKeyUp(KeyCode.B))
			isEnabled = !isEnabled;
			
		if (Input.GetKeyUp (KeyCode.N))
			if (dashBoard!=null) dashBoard.gameObject.SetActive(!dashBoard.gameObject.activeSelf);

		if (Input.GetKeyUp(KeyCode.G)){
			showForces=!showForces;
			foreach(Wheel w in axles.allWheels){
				w.showForces=showForces;
			}
		}
				
		if (Input.GetKeyDown(KeyCode.Escape)){
			Restore();
			Application.LoadLevel(0);
		}
		
		if (Input.GetKeyDown (KeyCode.LeftShift)){
			drivetrain.engageRPM=drivetrain.maxPowerRPM;
			if (carController.TCS==true) {carController.TCS=false;TCSChanged=true;}
			if (carController.ESP==true) {carController.ESP=false;ESPChanged=true;}
		}
		
		if (Input.GetKeyUp (KeyCode.LeftShift)){
			drivetrain.engageRPM=engageRPM;
			if (TCSChanged==true) {carController.TCS=true;TCSChanged=false;}
			if (ESPChanged==true) {carController.ESP=true;ESPChanged=false;}
		}		
		
		if (Input.GetKeyDown (KeyCode.R)){
			if (Input.GetKey (KeyCode.LeftShift)){
				carDamage.repair=true;
			}
			else{
				ResetCarPosition();
			}
		}
		
		if (Input.GetKeyDown (KeyCode.F1)){
			if (Time.timeScale!=1) Time.timeScale=1;
			else Time.timeScale=0.05f;
		}

		if (Input.GetKeyDown (KeyCode.F2) && Application.isEditor){
			if (carDebug==null) carDebug=mTransform.gameObject.AddComponent<CarDebug>();
			else carDebug.enabled=!carDebug.enabled;
		}
				
		if (startTimer) {
			timer+=Time.deltaTime;
			if (timer >=2.5f) {timer=0; startTimer=false;}
		}
		
		// Handbrake Logic
		if (carController!=null){
			if (carController.handbrakeInput!=0) {
				startTimer=true; 
				if (carController.steerAssistance==true) {carController.steerAssistance=false; steerAssistanceStateChanged=true;}
				if (carController.ESP==true) {carController.ESP=false; ESPStateChanged=true;}
				if (carController.ABS==true) {carController.ABS=false; ABSStateChanged=true;}
				if (drivetrain.autoClutch==true) drivetrain.clutch.SetClutchPosition(0);
				if (carController.TCS==true) {TCSStateChanged=true;}
			}
			else {
				if (steerAssistanceStateChanged==true && startTimer==false) {carController.steerAssistance=!carController.steerAssistance; steerAssistanceStateChanged=false;}
				if (ESPStateChanged==true && startTimer==false) {carController.ESP=!carController.ESP; ESPStateChanged=false;}
				if (ABSStateChanged==true) {carController.ABS=!carController.ABS; ABSStateChanged=false;}
				if (TCSStateChanged==true && startTimer==false) {TCSStateChanged=false;}
			}
		}
		
		if (carDynamics!=null){
			if (carDynamics.AllWheelsOnGround()==false && mrigidbody.velocity.sqrMagnitude<=1) startTimer1=true;
			else startTimer1=false;
		}
		
		if (startTimer1) {
			timer1+=Time.deltaTime;
			if (timer1 >=2) {ResetCarPosition();timer1=0; startTimer1=false;}
		}
		else
			timer1=0;
	}
示例#3
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;
				}
			}
		}
	}		
示例#4
0
        public static void UpdateFxDataVersionIfNeeded(Caronte_Fx fxData)
        {
            GameObject dataHolder = fxData.GetDataGameObject();

            if (fxData.DataVersion < 1)
            {
                CNBody[] arrBodyNode = dataHolder.GetComponents <CNBody>();

                foreach (CNBody bodyNode in arrBodyNode)
                {
                    bodyNode.OmegaStart_inDegSeg *= Mathf.Rad2Deg;
                    EditorUtility.SetDirty(bodyNode);
                }

                fxData.DataVersion = 1;
                EditorUtility.SetDirty(fxData);
                CarDebug.Log("Updated " + fxData.name + " definitions to version 1.");
            }
            if (fxData.DataVersion < 2)
            {
                CNJointGroups[] arrJgGroups = dataHolder.GetComponents <CNJointGroups>();
                foreach (CNJointGroups jgGroups in arrJgGroups)
                {
                    jgGroups.ContactAngleMaxInDegrees *= Mathf.Rad2Deg;
                    if (jgGroups.ContactAngleMaxInDegrees > 180f ||
                        jgGroups.ContactAngleMaxInDegrees < 0f)
                    {
                        jgGroups.ContactAngleMaxInDegrees -= (jgGroups.ContactAngleMaxInDegrees % 180f) * 180f;
                        EditorUtility.SetDirty(jgGroups);
                    }
                }
                fxData.DataVersion = 2;
                EditorUtility.SetDirty(fxData);
                CarDebug.Log("Updated " + fxData.name + " definitions to version 2.");
            }
            if (fxData.DataVersion < 3)
            {
                CNSoftbody[] arrSoftbodyNode = dataHolder.GetComponents <CNSoftbody>();
                foreach (CNSoftbody sbNode in arrSoftbodyNode)
                {
                    sbNode.LengthStiffness = Mathf.Clamp(sbNode.LengthStiffness, 0f, 30f);
                    EditorUtility.SetDirty(sbNode);
                }
                fxData.DataVersion = 3;
                EditorUtility.SetDirty(fxData);
                CarDebug.Log("Updated " + fxData.name + " definitions to version 3.");
            }
            if (fxData.DataVersion < 4)
            {
                CNFracture[] arrFractureNode = dataHolder.GetComponents <CNFracture>();
                foreach (CNFracture frNode in arrFractureNode)
                {
                    if (frNode.ChopGeometry != null)
                    {
                        frNode.FieldSteeringGeometry.GameObjects.Add(frNode.ChopGeometry);
                        EditorUtility.SetDirty(frNode);
                    }
                    if (frNode.CropGeometry != null)
                    {
                        frNode.FieldRestrictionGeometry.GameObjects.Add(frNode.CropGeometry);
                        EditorUtility.SetDirty(frNode);
                    }
                }
                fxData.DataVersion = 4;
                EditorUtility.SetDirty(fxData);
                CarDebug.Log("Updated " + fxData.name + " definitions to version 4.");
            }
            if (fxData.DataVersion < 5)
            {
                CNServos[] arrServos = dataHolder.GetComponents <CNServos>();
                foreach (CNServos svNode in arrServos)
                {
                    svNode.TargetExternal_LOCAL_NEW = new CarVector3Curve(svNode.TargetExternal_LOCAL, fxData.effect.totalTime_);
                    EditorUtility.SetDirty(svNode);
                }
                fxData.DataVersion = 5;
                EditorUtility.SetDirty(fxData);
                CarDebug.Log("Updated " + fxData.name + " definitions to version 5.");
            }
        }