Пример #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go">Vehicle game object.</param>
        public GameVehicle(GameObject go)
        {
            gameObject = go;

            dynamics = gameObject.GetComponent <CarDynamics>();
            Client.Assert(dynamics != null, "Missing car dynamics!");

            driveTrain = gameObject.GetComponent <Drivetrain>();

            axisCarController = gameObject.GetComponent <AxisCarController>();
            mpCarController   = gameObject.AddComponent <MPCarController>();

            PlayMakerFSM[] fsms = gameObject.GetComponentsInChildren <PlayMakerFSM>();

            foreach (var fsm in fsms)
            {
                if (fsm.FsmName == "PlayerTrigger")
                {
                    SetupPlayerTriggerHooks(fsm);

                    // Temp - use player trigger..
                    seatGameObject = fsm.gameObject;
                }
            }
        }
Пример #2
0
    void Start()
    {
        myTransform = transform;
        body        = rigidbody;
        if (meshFilters.Length == 0)
        {
            //meshFilters = GetComponentsInChildren<MeshFilter>();
            m_meshFilters = GetComponentsInChildren <MeshFilter>();

            int k = 0;
            for (i = 0; i < m_meshFilters.Length; i++)
            {
                if (m_meshFilters[i].collider == null)
                {
                    k++;
                }
            }
            meshFilters = new MeshFilter[k];
            k           = 0;
            for (i = 0; i < m_meshFilters.Length; i++)
            {
                if (m_meshFilters[i].collider == null)
                {
                    meshFilters[k] = m_meshFilters[i];
                    k++;
                }
            }
        }

        if (meshCollider != null)
        {
            //meshFilterColl=meshCollider.gameObject.GetComponent<MeshFilter>();
            colliderVerts = meshCollider.sharedMesh.vertices;
        }

        LoadoriginalMeshData();

        foreach (Transform child in transform)
        {
            if (child.gameObject.tag == "Body" || child.gameObject.name == "Body" || child.gameObject.name == "body")
            {
                GObody = child.gameObject;
            }
        }
        if (GObody)
        {
            sign = Mathf.Cos(GObody.transform.localEulerAngles.y * Mathf.Deg2Rad);
            if (GObody.transform.localEulerAngles.x != 0)
            {
                rot = Quaternion.AngleAxis(GObody.transform.localEulerAngles.x * 3, Vector3.right);
            }
        }

        carDynamics = GetComponent <CarDynamics>();
        axles       = GetComponent <Axles>();
        wheelLayer  = axles.allWheels[0].transform.gameObject.layer;
        carLayer    = transform.gameObject.layer;
    }
 protected virtual void Start()
 {
     body        = rigidbody;
     cardynamics = GetComponent <CarDynamics>();
     drivetrain  = GetComponent <Drivetrain>();
     axles       = GetComponent <Axles>();
     allWheels   = axles.allWheels;
     myTransform = transform;
 }
Пример #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go"></param>
        public AIVehicle(GameObject go, ObjectSyncComponent osc)
        {
            gameObject       = go;
            syncComponent    = osc;
            parentGameObject = go.transform.parent.gameObject;

            // Set vehicle type, used to apply vehicle-specific event hooks.
            string goName = gameObject.transform.parent.gameObject.name;

            if (goName == "AMIS2" || goName == "KYLAJANI")
            {
                type = VehicleTypes.Amis;
            }
            else if (goName == "BUS")
            {
                type = VehicleTypes.Bus;
            }
            else if (goName == "FITTAN" && parentGameObject.transform.FindChild("Navigation") != null)
            {
                type = VehicleTypes.Fitan;
            }
            else if (parentGameObject.transform.FindChild("NavigationCW") != null || parentGameObject.transform.FindChild("NavigationCCW") != null)
            {
                type = VehicleTypes.TrafficDirectional;
            }
            else
            {
                type = VehicleTypes.Traffic;
            }

            rigidbody = parentGameObject.GetComponent <Rigidbody>();

            dynamics = parentGameObject.GetComponent <CarDynamics>();

            throttleFsm = Utils.GetPlaymakerScriptByName(parentGameObject, "Throttle");

            if (type == VehicleTypes.TrafficDirectional)
            {
                if (parentGameObject.transform.FindChild("NavigationCW") != null)
                {
                    navigationFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("NavigationCW").gameObject, "Navigation");
                    isClockwise   = 1;
                }
                else
                {
                    navigationFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("NavigationCCW").gameObject, "Navigation");
                    isClockwise   = 0;
                }
                directionFsm = Utils.GetPlaymakerScriptByName(parentGameObject, "Direction");
            }
            else
            {
                navigationFsm = Utils.GetPlaymakerScriptByName(parentGameObject.transform.FindChild("Navigation").gameObject, "Navigation");
            }

            EventHooks();
        }
 public void Start()
 {
     myTransform = transform;
     mtarget     = target;
     if (mtarget)
     {
         cardynamics = mtarget.GetComponent <CarDynamics>();
     }
 }
Пример #6
0
 void Start()
 {
     body        = GetComponent <Rigidbody>();
     cardynamics = GetComponent <CarDynamics>();
     drivetrain  = GetComponent <Drivetrain>();
     axles       = GetComponent <Axles>();
     allWheels   = axles.allWheels;
     myTransform = transform;
 }
        public Car(string name, string meshFile, Vector3 offset, Attitude adjust)
            : base(name, meshFile, offset, adjust)
        {
            m_dynamics = new CarDynamics();

            // start the engine
//			m_dynamics.Gear = CarDynamics.GearState.Park;
            m_dynamics.Ignition = CarDynamics.IgnitionState.IgnitionStart;
            m_dynamics.Gear     = CarDynamics.GearState.Drive;
        }
Пример #8
0
	void Start(){
		body=rigidbody;
		carDynamics = GetComponent<CarDynamics>();
		axles = GetComponent<Axles>();
		if (overallStrength<0) overallStrength=0;
		if (COGHelperStrength<0) COGHelperStrength=0;
		if (torqueHelperStrength<0) torqueHelperStrength=0;
		if (gripHelperStrength<0) gripHelperStrength=0;
		
	}
    void Start()
    {
        //soundVolume = GameObject.Find("SoundVolume").GetComponent<UISlider>();
        selectCarController = GameObject.Find("Controller").GetComponent <SelectCarController>();
        carController       = GetComponent <CarController>();
        cardynamics         = GetComponent <CarDynamics>();
        drivetrain          = GetComponent <Drivetrain>();
        physicMaterials     = GetComponent <PhysicMaterials>();
        axles = GetComponent <Axles>();

        Vector3 enginePositionV = Vector3.zero;

        if (enginePosition != null)
        {
            enginePositionV = enginePosition.transform.position;
        }
        engineThrottleSource     = CreateAudioSource(engineThrottle, true, true, enginePositionV);
        engineNoThrottleSource   = CreateAudioSource(engineNoThrottle, true, true, enginePositionV);
        transmissionSource       = CreateAudioSource(transmission, true, true, Vector3.zero);
        brakeNoiseSource         = CreateAudioSource(brakeNoise, true, true, Vector3.zero);
        startEngineSource        = CreateAudioSource(startEngine, true, false, enginePositionV);
        startEngineSource.volume = startEngineVolume * selectCarController.VolumeEffects;//b
        startEngineSource.pitch  = startEnginePitch;

        System.Array.Resize(ref skidSource, axles.allWheels.Length);
        i = 0;
        foreach (Wheel w in axles.allWheels)
        {
            skidSource[i] = CreateAudioSource(skid, true, true, w.transform.localPosition);
            i++;
        }

        crashHiSpeedSource        = CreateAudioSource(crashHiSpeed, false, false, Vector3.zero);
        crashLowSpeedSource       = CreateAudioSource(crashLowSpeed, false, false, Vector3.zero);
        scrapeNoiseSource         = CreateAudioSource(scrapeNoise, false, false, Vector3.zero);
        ABSTriggerSource          = CreateAudioSource(ABSTrigger, false, false, Vector3.zero);
        ABSTriggerSource.volume   = ABSTriggerVolume;
        shiftTriggerSource        = CreateAudioSource(shiftTrigger, false, false, Vector3.zero);
        shiftTriggerSource.volume = shiftTriggerVolume;
        windSource = CreateAudioSource(wind, true, true, Vector3.zero);

        if (physicMaterials)
        {
            System.Array.Resize(ref rollingNoiseSource, axles.allWheels.Length);
            i = 0;
            foreach (Wheel w in axles.allWheels)
            {
                rollingNoiseSource[i] = CreateAudioSource(rollingNoiseGrass, true, false, w.transform.localPosition);
                i++;
            }
        }
    }
Пример #10
0
	void Start () {
		Transform trs = transform;
		myTransform=transform;
				
		while (trs != null && trs.rigidbody == null)
			trs = trs.parent;
		if (trs != null)
			body = trs.rigidbody;
		
		trs = transform;
		while (trs.GetComponent<CarDynamics>() == null)  trs = trs.parent;
		cardynamics = trs.GetComponent<CarDynamics>();		
	}
Пример #11
0
        private IEnumerator SetupMod()
        {
            while (GameObject.Find("PLAYER") == null ||
                   GameObject.Find("PLAYER/Pivot/Camera/FPSCamera/FPSCamera/AudioRain") == null)
            {
                yield return(null);
            }

            ModConsole.Print("Dirt mod loading assetbundle...");
            var path = MSCDirtMod.assetPath;

            if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL") && Application.platform == RuntimePlatform.WindowsPlayer)
            {
                path = Path.Combine(path, "bundle-linux");                 // apparently fixes opengl
            }
            else if (Application.platform == RuntimePlatform.WindowsPlayer)
            {
                path = Path.Combine(path, "bundle-windows");
            }
            else if (Application.platform == RuntimePlatform.OSXPlayer)
            {
                path = Path.Combine(path, "bundle-osx");
            }
            else if (Application.platform == RuntimePlatform.LinuxPlayer)
            {
                path = Path.Combine(path, "bundle-linux");
            }

            if (!File.Exists(path))
            {
                ModConsole.Error("Couldn't find asset bundle from path " + path);
                yield break;
            }

            m_bundle = AssetBundle.CreateFromMemoryImmediate(File.ReadAllBytes(path));
            LoadAssets();

            ModConsole.Print("Dirt mod doing final setup...");
            m_rainAudioSource = GameObject.Find("PLAYER/Pivot/Camera/FPSCamera/FPSCamera/AudioRain").GetComponent <AudioSource>();

            m_satsuma     = PlayMakerGlobals.Instance.Variables.GetFsmGameObject("TheCar").Value;
            m_carDynamics = m_satsuma.GetComponentInChildren <CarDynamics>();
            m_wiperPivot  = m_satsuma.transform.FindChild("Wipers/WiperLeftPivot");

            ModConsole.Print("Setting up buckets...");
            SetupBuckets();
            ModConsole.Print("Setting up audio...");
            SetupAudio();
            ModConsole.Print("Dirt Mod Setup!");
            m_isSetup = true;
        }
Пример #12
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>();
     }
 }
Пример #13
0
    void Start()
    {
        myTransform = transform;
        mtarget     = target;
        if (mtarget)
        {
            CarDynamics carDynamics = mtarget.GetComponent <CarDynamics>();

            if (carDynamics)
            {
                this.carDynamics = carDynamics;
            }
        }
    }
Пример #14
0
	void SetComponent(){
		drivetrain = GetComponent<Drivetrain>();
		cardynamics = GetComponent<CarDynamics>();
		forceFeedback= GetComponent<ForceFeedback>();
		physicMaterials =GetComponent<PhysicMaterials>();
		arcader= GetComponent<Arcader>();
		aerodynamicResistance= GetComponent<AerodynamicResistance>();
		axles= GetComponent<Axles>();
		axisCarController = GetComponent <AxisCarController>();
		mouseCarController = GetComponent <MouseCarController>();
		mobileCarController = GetComponent <MobileCarController>();		
		fuelTanks=GetComponentsInChildren<FuelTank>();
		wings=GetComponentsInChildren<Wing>();
	}
Пример #15
0
        /// <summary>
        /// Sets all ffb to the current vehicle.
        /// </summary>
        private bool setFfbForVehicle()
        {
            // Written, 23.10.2020

            string _currentVehicleName = getCurrentVehicle;
            bool   isSet = (_currentVehicleName ?? "") == currentVehicleName;

            if (!isSet)
            {
                switch (_currentVehicleName)
                {
                case "Satsuma":
                    vehicle     = GameObject.Find("SATSUMA(557kg, 248)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Jonnez":
                    vehicle     = GameObject.Find("JONNEZ ES(Clone)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Kekmet":
                    vehicle     = GameObject.Find("KEKMET(350-400psi)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Hayosiko":
                    vehicle     = GameObject.Find("HAYOSIKO(1500kg, 250)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                case "Gifu":
                    vehicle     = GameObject.Find("GIFU(750/450psi)");
                    carDynamics = vehicle.GetComponent <CarDynamics>();
                    drivetrain  = vehicle.GetComponent <Drivetrain>();
                    break;

                default:
                    vehicle = null;
                    break;
                }
                currentVehicleName = _currentVehicleName;
            }
            return(vehicle != null);
        }
Пример #16
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go"></param>
        public PlayerVehicle(GameObject go, ObjectSyncComponent osc)
        {
            gameObject       = go;
            syncComponent    = osc;
            ParentGameObject = go.transform.parent.parent.gameObject;

            rigidbody  = ParentGameObject.GetComponent <Rigidbody>();
            dynamics   = ParentGameObject.GetComponent <CarDynamics>();
            driveTrain = ParentGameObject.GetComponent <Drivetrain>();

            axisCarController = ParentGameObject.GetComponent <AxisCarController>();
            mpCarController   = ParentGameObject.AddComponent <MPCarController>();

            FindFSMs();
        }
Пример #17
0
    void Start()
    {
        Transform trs = transform;

        myTransform = transform;

        while (trs != null && trs.rigidbody == null)
        {
            trs = trs.parent;
        }
        if (trs != null)
        {
            body = trs.rigidbody;
        }

        trs = transform;
        while (trs.GetComponent <CarDynamics>() == null)
        {
            trs = trs.parent;
        }
        cardynamics = trs.GetComponent <CarDynamics>();
    }
Пример #18
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="go"></param>
        public PlayerVehicle(GameObject go, ObjectSyncComponent osc)
        {
            gameObject       = go;
            syncComponent    = osc;
            ParentGameObject = go.transform.parent.parent.gameObject;

            if (ParentGameObject.name.StartsWith("JONNEZ"))
            {
                isBike        = true;
                steeringPivot = ParentGameObject.transform.FindChild("LOD/Suspension/Steering/SteeringPivot").gameObject;
            }

            rigidbody  = ParentGameObject.GetComponent <Rigidbody>();
            dynamics   = ParentGameObject.GetComponent <CarDynamics>();
            driveTrain = ParentGameObject.GetComponent <Drivetrain>();

            axisCarController = ParentGameObject.GetComponent <AxisCarController>();
            mpCarController   = ParentGameObject.AddComponent <MPCarController>();

            AddVehicleDoorSync();
            FindFSMs();
        }
Пример #19
0
 void Start()
 {
     body        = rigidbody;
     carDynamics = GetComponent <CarDynamics>();
     axles       = GetComponent <Axles>();
     if (overallStrength < 0)
     {
         overallStrength = 0;
     }
     if (COGHelperStrength < 0)
     {
         COGHelperStrength = 0;
     }
     if (torqueHelperStrength < 0)
     {
         torqueHelperStrength = 0;
     }
     if (gripHelperStrength < 0)
     {
         gripHelperStrength = 0;
     }
 }
Пример #20
0
        public GameVehicle(GameObject go)
        {
            gameObject = go;

            dynamics = gameObject.GetComponent <CarDynamics>();

            /*PlayMakerFSM loadingFsm = Utils.GetPlaymakerScriptByName(gameObject, "LOD");
             * if (loadingFsm != null) {
             *      Component.Destroy(loadingFsm);
             * }*/


            PlayMakerFSM[] fsms = gameObject.GetComponentsInChildren <PlayMakerFSM>();

            Logger.Log("FSMS of " + gameObject.name);
            foreach (var fsm in fsms)
            {
                if (fsm.FsmName != "PlayerTrigger")
                {
                    continue;
                }

                FsmState playerInCarState   = fsm.Fsm.GetState("Player in car");
                FsmState waitForPlayerState = fsm.Fsm.GetState("Wait for player");

                if (waitForPlayerState != null)
                {
                    PlayMakerUtils.AddNewAction(waitForPlayerState, new OnLeaveAction(this));
                }

                if (playerInCarState != null)
                {
                    PlayMakerUtils.AddNewAction(playerInCarState, new OnEnterAction(this));
                }
            }
        }
Пример #21
0
	public void Start()
	{
		cardynamics = GetComponent<CarDynamics>();
		InitialiseForceFeedback();
		SetAutoCenter(false);
	}
Пример #22
0
	public void Start(){
		myTransform=transform;
		mtarget=target;
		if(mtarget) cardynamics = mtarget.GetComponent<CarDynamics>();
	}
Пример #23
0
  protected virtual void Start()
  {
		body=rigidbody;
		cardynamics = GetComponent<CarDynamics>();
		drivetrain = GetComponent<Drivetrain>();
    axles = GetComponent <Axles>();
		allWheels=axles.allWheels;			
		myTransform=transform;
	}
Пример #24
0
        public override void OnLoad()
        {
            gameObjects = new List <Objects>();

            //Player Vehicles
            // For each vehicle in the game, a new instance of Vehicle class is initialized.
            SATSUMA      = new Vehicle("SATSUMA(557kg, 248)");
            FLATBED      = new Vehicle("FLATBED");
            GIFU         = new Gifu("GIFU(750/450psi)");
            HAYOSIKO     = new Vehicle("HAYOSIKO(1500kg, 250)");
            JONNEZ       = new Vehicle("JONNEZ ES(Clone)");
            KEKMET       = new Vehicle("KEKMET(350-400psi)");
            RUSKO        = new Vehicle("RCO_RUSCKO12(270)");
            FERNDALE     = new Vehicle("FERNDALE(1630kg)");
            CABIN        = GameObject.Find("CABIN");
            AXLES        = SATSUMA.Object.GetComponent <Axles>();
            CAR_DYNAMICS = SATSUMA.Object.GetComponent <CarDynamics>();

            ModConsole.Print("Cars Done");

            //Locations and objects that can be enabled and disabled easily on proximity
            gameObjects.Add(new Objects(GameObject.Find("BOAT"))); //Boat is not a Car, oddly enough.
            gameObjects.Add(new Objects(GameObject.Find("COTTAGE")));
            gameObjects.Add(new Objects(GameObject.Find("DANCEHALL")));
            gameObjects.Add(new Objects(GameObject.Find("INSPECTION")));
            gameObjects.Add(new Objects(GameObject.Find("LANDFILL")));
            gameObjects.Add(new Objects(GameObject.Find("PERAJARVI")));
            gameObjects.Add(new Objects(GameObject.Find("RYKIPOHJA")));
            gameObjects.Add(new Objects(GameObject.Find("SOCCER")));
            gameObjects.Add(new Objects(GameObject.Find("WATERFACILITY")));
            gameObjects.Add(new Objects(GameObject.Find("TREES1_COLL")));
            gameObjects.Add(new Objects(GameObject.Find("TREES2_COLL")));
            gameObjects.Add(new Objects(GameObject.Find("TREES3_COLL")));

            // Initialize Store class
            STORE      = new Store();
            REPAIRSHOP = new RepairShop();
            gameObjects.Add(new Objects(GameObject.Find("DRAGRACE"), 1100));

            Transform buildings = GameObject.Find("Buildings").transform;

            // Find house of Teimo and detach it from Perajarvi, so it can be loaded and unloaded separately
            // It shouldn't cause any issues, but that needs testing.
            GameObject perajarvi = GameObject.Find("PERAJARVI");

            perajarvi.transform.Find("HouseRintama4").parent = buildings;
            // Same for chicken house
            perajarvi.transform.Find("ChickenHouse").parent = buildings;

            // Chicken house (barn) close to player's house
            Transform playerChickenHouse = GameObject.Find("Buildings").transform.Find("ChickenHouse");

            playerChickenHouse.parent = null;

            // Fix for church wall. Changing it's parent ot NULL, so it will not be loaded or unloaded.
            // It used to be changed to CHURCH gameobject,
            // but the Amis cars (yellow and grey cars) used to end up in the graveyard area.
            GameObject.Find("CHURCHWALL").transform.parent = null;

            // Fix for old house on the way from Perajarvi to Ventti's house (HouseOld5)
            perajarvi.transform.Find("HouseOld5").parent = buildings;

            // Perajarvi fixes for multiple objects with the same name.
            // Instead of being the part of Perajarvi, we're changing it to be the part of Buildings.
            foreach (Transform trans in perajarvi.GetComponentsInChildren <Transform>())
            {
                // Fix for disappearing grain processing plant
                // https://my-summer-car.fandom.com/wiki/Grain_processing_plant
                if (trans.gameObject.name.Contains("silo"))
                {
                    trans.parent = buildings;
                    continue;
                }

                // Fix for Ventti's and Teimo's mailboxes (and pretty much all mailboxes that are inside of Perajarvi)
                if (trans.gameObject.name == "MailBox")
                {
                    trans.parent = buildings;
                    continue;
                }

                // Fix for greenhouses on the road from Perajarvi to Ventti's house
                if (trans.name == "Greenhouse")
                {
                    trans.parent = buildings;
                    continue;
                }
            }

            // Possible fix for Jokke.
            // Needs testing
            foreach (Transform trans in GameObject.Find("KILJUGUY").transform.GetComponentsInChildren <Transform>())
            {
                gameObjects.Add(new Objects(trans.gameObject));
            }

            // Removes the mansion from the Buildings, so the tires will not land under the mansion.
            GameObject.Find("autiotalo").transform.parent = null;

            ModConsole.Print("GameObjects Done");

            //Things that should be enabled when out of proximity of the house
            gameObjects.Add(new Objects(GameObject.Find("NPC_CARS"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("RALLY"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("TRAFFIC"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("TRAIN"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("Buildings"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("TrafficSigns"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("ELEC_POLES"), awayFromHouse: true));
            gameObjects.Add(new Objects(GameObject.Find("StreetLights"), awayFromHouse: true));

            //TODO: Solve Bugs from Unloading/Reloading Satsuma
            // Bugs:
            // Can't open doors
            // May randomly fall through floor

            //TODO:
            // (*2) Figure out how to make repairs works at Fleetari's without loading it
            // (*1) Figure out how to trigger a restock at Tiemos on Thursdays without loading it.

            //NOTES:
            // (*1) Partially addressed the Teimo's issue, by unloading part of the shop
            // (*2) Partially addressed the same way as for Teimo's shop

            //Camera.main.farClipPlane = (int)RenderDistance.Value; //Helps with lower end GPU's. This specific value. Any others are wrong.
            PLAYER    = GameObject.Find("PLAYER");
            YARD      = GameObject.Find("YARD");                //Used to find out how far the player is from the Object
            KINEMATIC = SATSUMA.Object.GetComponent <Rigidbody>();

            // Initialize MinorObjects
            new MinorObjects();

            ModConsole.Print("[KruFPS] Found all objects");
            DrawDistance = float.Parse(RenderDistance.GetValue().ToString()); //Update saved draw distance variable
            HookAllSavePoints();                                              //Hook all save points (it's before first pass of Update)

            //Camera.main.gameObject.AddComponent<CameraHook>();
        }
Пример #25
0
 void Start()
 {
     body = GetComponent <Rigidbody>();
     //mytransform=transform;
     cardynamics = GetComponent <CarDynamics>();
 }
Пример #26
0
	void LoadControllerData(CarController carController, CarDynamics.Controller controller){
		value=LoadValue("smoothInput",controller+"Controller"); if (value!="") carController.smoothInput=bool.Parse(value);
		value=LoadValue("throttleTime",controller+"Controller"); if (value!="") carController.throttleTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("throttleReleaseTime",controller+"Controller"); if (value!="") carController.throttleReleaseTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("maxThrottleInReverse",controller+"Controller"); if (value!="") carController.maxThrottleInReverse=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("brakesTime",controller+"Controller"); if (value!="") carController.brakesTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("brakesReleaseTime",controller+"Controller"); if (value!="") carController.brakesReleaseTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("steerTime",controller+"Controller"); if (value!="") carController.steerTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("steerReleaseTime",controller+"Controller"); if (value!="") carController.steerReleaseTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("veloSteerTime",controller+"Controller"); if (value!="") carController.veloSteerTime=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("veloSteerReleaseTime",controller+"Controller"); if (value!="") carController.veloSteerReleaseTime =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("steerCorrectionFactor",controller+"Controller"); if (value!="") carController.steerCorrectionFactor =float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("steerAssistance",controller+"Controller"); if (value!="") carController.steerAssistance=bool.Parse(value);
		value=LoadValue("SteerAssistanceMinVelocity",controller+"Controller"); if (value!="") carController.SteerAssistanceMinVelocity=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("TCS",controller+"Controller"); if (value!="") carController.TCS=bool.Parse(value);
		value=LoadValue("TCSThreshold",controller+"Controller"); if (value!="") carController.TCSThreshold=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("TCSMinVelocity",controller+"Controller"); if (value!="") carController.TCSMinVelocity=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("ABS",controller+"Controller"); if (value!="") carController.ABS=bool.Parse(value);
		value=LoadValue("ABSThreshold",controller+"Controller"); if (value!="") carController.ABSThreshold=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("ABSMinVelocity",controller+"Controller"); if (value!="") carController.ABSMinVelocity=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("ESP",controller+"Controller"); if (value!="") carController.ESP=bool.Parse(value);
		value=LoadValue("ESPStrength",controller+"Controller"); if (value!="") carController.ESPStrength=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
		value=LoadValue("ESPMinVelocity",controller+"Controller"); if (value!="") carController.ESPMinVelocity=float.Parse(value,System.Globalization.CultureInfo.InvariantCulture.NumberFormat);	
	}
	void Start(){
		body=rigidbody;
		//mytransform=transform;
		cardynamics = GetComponent<CarDynamics>();
	}
Пример #28
0
	void Start(){
		myTransform=transform;
		
		trs = myTransform.parent;
		while (trs != null && trs.rigidbody == null) trs = trs.parent;
		if (trs != null) body = trs.rigidbody;
		
		trs = myTransform.parent;
		while (trs.GetComponent<PhysicMaterials>() == null)  {if (trs.parent) trs = trs.parent; else break;}
		physicMaterials = trs.GetComponent<PhysicMaterials>();

		trs = myTransform.parent;		
		while (trs.GetComponent<CarDynamics>() == null)  trs = trs.parent;
		cardynamics = trs.GetComponent<CarDynamics>();
		drivetrain = trs.GetComponent<Drivetrain>();
		axles = trs.GetComponent<Axles>();
		
		localScale=1/(trs.localScale.y*myTransform.localScale.y);
		
		layerMask=1<<trs.gameObject.layer | 1<<myTransform.gameObject.layer;//LayerMask.NameToLayer("Wheel");
		layerMask=~layerMask;	
		
		radiusLoaded=radius;
		if (rimRadius==0) rimRadius=radius*0.735f;
		sidewallHeight=radius - rimRadius;

		if (mass<50*cardynamics.invFixedTimeStepScalar) mass=50*cardynamics.invFixedTimeStepScalar;
		if (rotationalInertia==0 || rotationalInertia<(mass/2)*radius*radius) rotationalInertia=(mass/2)*radius*radius;
		originalMass=mass;
				
		if (model==null) {
			model = new GameObject("temp_model");
			model.transform.parent=transform;
			model.transform.localPosition=new Vector3(0,0,0);
			model.transform.localRotation=Quaternion.identity;
			Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" +trs.name+ ")");
		}
		
		modelTransform=model.transform;
		if (caliperModel!=null) caliperModelTransform=caliperModel.transform;
	
		skidmarks = cardynamics.skidmarks;
		if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter;
		
		suspensionLineRenderer=gameObject.GetComponent<LineRenderer>();
		if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>();
		suspensionLineRenderer.material = new Material(Shader.Find("Diffuse"));
		suspensionLineRenderer.material.color = Color.yellow;
		suspensionLineRenderer.SetWidth(0.01f,0.1f);
		suspensionLineRenderer.useWorldSpace = false;
		suspensionLineRenderer.castShadows = false;
	
		camber*=1; // to avoid never assigned warning
		if (camber==0){
			up = myTransform.up;
		}
		else{
			camberRotation = Quaternion.AngleAxis(-camber,forwardNormal);
			up = camberRotation*myTransform.up;
		}			
		
		SetTireStiffness();
	}
Пример #29
0
        public override void OnLoad()
        {
            gameObjects = new List <GameObject>();

            //Player Vehicles
            // For each vehicle in the game, a new instance of Vehicle class is initialized.
            SATSUMA      = new Vehicle("SATSUMA(557kg, 248)");
            SATSUMA_2    = GameObject.Find("SATSUMA(557kg, 248)");
            FLATBED      = new Vehicle("FLATBED");
            GIFU         = new Gifu("GIFU(750/450psi)");
            HAYOSIKO     = new Vehicle("HAYOSIKO(1500kg, 250)");
            JONNEZ       = new Vehicle("JONNEZ ES(Clone)");
            KEKMET       = new Vehicle("KEKMET(350-400psi)");
            RUSKO        = new Vehicle("RCO_RUSCKO12(270)");
            FERNDALE     = new Vehicle("FERNDALE(1630kg)");
            CABIN        = GameObject.Find("CABIN");
            AXLES        = SATSUMA_2.GetComponent <Axles>();
            CAR_DYNAMICS = SATSUMA_2.GetComponent <CarDynamics>();
            ModConsole.Print("Cars Done");

            //Locations and objects that can be enabled and disabled easily on proximity
            gameObjects.Add(GameObject.Find("BOAT")); //Boat is not a Car, oddly enough.
            //gameObjects.Add(GameObject.Find("CABIN"));
            gameObjects.Add(GameObject.Find("COTTAGE"));
            gameObjects.Add(GameObject.Find("DANCEHALL"));
            //gameObjects.Add(GameObject.Find("DRAGRACE")); //Is broken when disabled, so leave enabled
            gameObjects.Add(GameObject.Find("INSPECTION"));
            gameObjects.Add(GameObject.Find("LANDFILL"));
            gameObjects.Add(GameObject.Find("PERAJARVI"));
            //gameObjects.Add(GameObject.Find("REPAIRSHOP")); //Has to be loaded for repairs and such - Maybe fixable
            gameObjects.Add(GameObject.Find("RYKIPOHJA"));
            gameObjects.Add(GameObject.Find("SOCCER"));
            gameObjects.Add(GameObject.Find("WATERFACILITY"));
            gameObjects.Add(GameObject.Find("KILJUGUY"));
            gameObjects.Add(GameObject.Find("CHURCHWALL"));
            gameObjects.Add(GameObject.Find("TREES1_COLL"));
            gameObjects.Add(GameObject.Find("TREES2_COLL"));
            gameObjects.Add(GameObject.Find("TREES3_COLL"));

            // Initialize Store class
            STORE      = new Store();
            REPAIRSHOP = new RepairShop();

            // Find house of Teimo and detach it from Perajarvi, so it can be loaded and unloaded separately
            // It shouldn't cause any issues, but that needs testing.
            GameObject perajarvi   = GameObject.Find("PERAJARVI");
            GameObject TEIMO_HOUSE = perajarvi.transform.Find("HouseRintama4").gameObject;

            TEIMO_HOUSE.transform.parent = null;
            // Same for chicken house
            GameObject CHICKEN_HOUSE = perajarvi.transform.Find("ChickenHouse").gameObject;

            CHICKEN_HOUSE.transform.parent = null;

            // Now that Teimo's house and chicken house is separated from Perajarvi, we can manage them separately. We're throwing them to gameObjects.
            // Fixes the bug with both dissapearing when leaving Perajarvi, even tho logically they should still load when approached.
            gameObjects.Add(TEIMO_HOUSE);
            gameObjects.Add(CHICKEN_HOUSE);

            // Fix for disappearing grain processing plant
            // https://my-summer-car.fandom.com/wiki/Grain_processing_plant
            //
            // It also puts them to farGameObjects - objects that are larger and need to be rendered from further distance
            foreach (Transform trans in perajarvi.GetComponentsInChildren <Transform>())
            {
                if (trans.gameObject.name.Contains("silo"))
                {
                    trans.parent = null;
                    farGameObjects.Add(trans.gameObject);
                }
            }

            // Chicken house (barn) close to player's house
            Transform playerChickenHouse = GameObject.Find("Buildings").transform.Find("ChickenHouse");

            playerChickenHouse.parent = null;
            gameObjects.Add(playerChickenHouse.gameObject);

            ModConsole.Print("GameObjects Done");

            //Things that should be enabled when out of proximity of the house
            awayFromHouse = new List <GameObject>();
            awayFromHouse.Add(GameObject.Find("NPC_CARS"));
            awayFromHouse.Add(GameObject.Find("RALLY"));
            awayFromHouse.Add(GameObject.Find("TRAFFIC"));
            awayFromHouse.Add(GameObject.Find("TRAIN"));
            awayFromHouse.Add(GameObject.Find("Buildings"));
            awayFromHouse.Add(GameObject.Find("TrafficSigns"));
            awayFromHouse.Add(GameObject.Find("ELEC_POLES"));

            //TODO: Solve Bugs from Unloading/Reloading Satsuma
            // Bugs:
            // Can't open doors
            // May randomly fall through floor

            //TODO:
            // Figure out how to make repairs works at Fleetari's without loading it
            // (*1) Figure out how to trigger a restock at Tiemos on Thursdays without loading it.

            //NOTES:
            // (*1) Partially addressed the Teimo's issue, by unloading part of the shop

            //Camera.main.farClipPlane = (int)RenderDistance.Value; //Helps with lower end GPU's. This specific value. Any others are wrong.
            PLAYER    = GameObject.Find("PLAYER");
            YARD      = GameObject.Find("YARD");                //Used to find out how far the player is from the Object
            KINEMATIC = SATSUMA.Object.GetComponent <Rigidbody>();

            // Get all minor objects from the game world (like beer cases, sausages)
            // Only items that are in the listOfMinorObjects list, and also contain "(itemx)" in their name will be loaded
            // UPDATED: added support for (Clone) items
            GameObject[] allObjects = Object.FindObjectsOfType <GameObject>();
            foreach (GameObject gameObject in allObjects)
            {
                foreach (string itemName in listOfMinorObjects)
                {
                    if (gameObject.name.Contains(itemName) && gameObject.name.ContainsAny("(itemx)", "(Clone)"))
                    {
                        minorObjects.Add(gameObject);
                    }
                }
            }

            ModConsole.Print("[KruFPS] Found all objects");
            DrawDistance = float.Parse(RenderDistance.GetValue().ToString()); //Update saved draw distance variable
            HookAllSavePoints();                                              //Hook all save points (it's before first pass of Update)
        }
	void Start () {
		carController = GetComponent<CarController>();
		cardynamics = GetComponent<CarDynamics>();
		drivetrain= GetComponent<Drivetrain>();
		physicMaterials =GetComponent<PhysicMaterials>();
		axles=GetComponent<Axles>();
		
		Vector3 enginePositionV=Vector3.zero;
		if (enginePosition!=null) enginePositionV=enginePosition.transform.position;
		engineThrottleSource = CreateAudioSource(engineThrottle, true, true,enginePositionV);
		engineNoThrottleSource = CreateAudioSource(engineNoThrottle, true, true,enginePositionV);
		transmissionSource = CreateAudioSource(transmission, true, true,Vector3.zero);
		brakeNoiseSource = CreateAudioSource(brakeNoise, true, true,Vector3.zero);
		startEngineSource= CreateAudioSource(startEngine, true, false,enginePositionV);
		startEngineSource.volume=startEngineVolume;
		startEngineSource.pitch=startEnginePitch;
		
		System.Array.Resize(ref skidSource,axles.allWheels.Length);
		i=0;
		foreach(Wheel w in axles.allWheels){
			skidSource[i] = CreateAudioSource(skid, true, true,w.transform.localPosition);
			i++;
		}	

		crashHiSpeedSource = CreateAudioSource(crashHiSpeed, false, false,Vector3.zero);
		crashLowSpeedSource = CreateAudioSource(crashLowSpeed, false, false,Vector3.zero);
		scrapeNoiseSource = CreateAudioSource(scrapeNoise, false, false,Vector3.zero);
		ABSTriggerSource= CreateAudioSource(ABSTrigger, false, false,Vector3.zero);
		ABSTriggerSource.volume=ABSTriggerVolume;
		shiftTriggerSource= CreateAudioSource(shiftTrigger, false, false,Vector3.zero);
		shiftTriggerSource.volume=shiftTriggerVolume;
		windSource = CreateAudioSource(wind, true, true,Vector3.zero);
		
		if (physicMaterials){
			System.Array.Resize(ref rollingNoiseSource,axles.allWheels.Length);
			i=0;
			foreach(Wheel w in axles.allWheels){
				rollingNoiseSource[i]=CreateAudioSource(rollingNoiseGrass, true, false,w.transform.localPosition);
				i++;
			}	
		}
	}
Пример #31
0
	void SaveControllerData(CarController carController, CarDynamics.Controller controller){
		SaveValue("smoothInput", carController.smoothInput+"",controller+"Controller");
		SaveValue("throttleTime", carController.throttleTime +"",controller+"Controller");
		SaveValue("throttleReleaseTime", carController.throttleReleaseTime +"",controller+"Controller");
		SaveValue("maxThrottleInReverse", carController.maxThrottleInReverse+"",controller+"Controller");
		SaveValue("brakesTime", carController.brakesTime +"",controller+"Controller");
		SaveValue("brakesReleaseTime", carController.brakesReleaseTime +"",controller+"Controller");
		SaveValue("steerTime", carController.steerTime +"",controller+"Controller");
		SaveValue("steerReleaseTime", carController.steerReleaseTime +"",controller+"Controller");
		SaveValue("veloSteerTime", carController.veloSteerTime+"",controller+"Controller");
		SaveValue("veloSteerReleaseTime", carController.veloSteerReleaseTime +"",controller+"Controller");
		SaveValue("steerCorrectionFactor", carController.steerCorrectionFactor +"",controller+"Controller");
		SaveValue("steerAssistance", carController.steerAssistance+"",controller+"Controller");
		SaveValue("SteerAssistanceMinVelocity", carController.SteerAssistanceMinVelocity+"",controller+"Controller");
		SaveValue("TCS", carController.TCS +"",controller+"Controller");
		SaveValue("TCSThreshold", carController.TCSThreshold+"",controller+"Controller");
		SaveValue("TCSMinVelocity", carController.TCSMinVelocity+"",controller+"Controller");
		SaveValue("ABS", carController.ABS+"",controller+"Controller");
		SaveValue("ABSThreshold",carController.ABSThreshold+"",controller+"Controller");
		SaveValue("ABSMinVelocity",carController.ABSMinVelocity+"",controller+"Controller");
		SaveValue("ESP",carController.ESP+"",controller+"Controller");
		SaveValue("ESPStrength",carController.ESPStrength+"",controller+"Controller");
		SaveValue("ESPMinVelocity",carController.ESPMinVelocity+"",controller+"Controller");	
	}
Пример #32
0
	//[MenuItem("GameObject/Create Other/UnityCar")]
	public static GameObject CreateNewCar(){
		Debug.LogWarning("Create new car");
		GameObject unityCarObj=new GameObject("UnityCar");
						
		if (unityCarObj.rigidbody==null){
			mrigidbody=unityCarObj.AddComponent<Rigidbody>() as Rigidbody;
			mrigidbody.mass=1000;
			mrigidbody.angularDrag=0;
			mrigidbody.interpolation=RigidbodyInterpolation.Interpolate;
		}
		else
			mrigidbody=unityCarObj.GetComponent<Rigidbody>();

		if (unityCarObj.GetComponent<CarDynamics>()==null)
			carDynamics=unityCarObj.AddComponent<CarDynamics>() as CarDynamics;
		else
			carDynamics=unityCarObj.GetComponent<CarDynamics>();
			
		centerOfMassObject=new GameObject("COG");
		centerOfMassObject.transform.parent=unityCarObj.transform;
		centerOfMassObject.transform.localPosition=Vector3.zero;
		centerOfMassObject.transform.localRotation=Quaternion.identity;
		
		carDynamics.centerOfMass=centerOfMassObject.transform;			
				
		if (unityCarObj.GetComponent<Drivetrain>()==null)
			drivetrain =unityCarObj.AddComponent<Drivetrain>() as Drivetrain;
		else
			drivetrain=unityCarObj.GetComponent<Drivetrain>();
			
		
		if (unityCarObj.GetComponent<AxisCarController>()==null)
			axisCarController=unityCarObj.AddComponent<AxisCarController>() as AxisCarController;
		else
			axisCarController=unityCarObj.GetComponent<AxisCarController>();
			
/* 
		if (unityCarObj.GetComponent<SoundController>()==null)
			soundController=unityCarObj.AddComponent<SoundController>() as SoundController;
		else
			soundController=unityCarObj.GetComponent<SoundController>();
			
		soundController.enabled=false; */

		if (unityCarObj.GetComponent<Axles>()==null)
			axles =unityCarObj.AddComponent<Axles>() as Axles;
		else
			axles =unityCarObj.GetComponent<Axles>();
			
		// to avoid car assigned to default layer
		unityCarObj.layer=1; 

		if (unityCarObj.transform.Find("Body")==null){
			bodyDown = GameObject.CreatePrimitive(PrimitiveType.Cube);
			bodyDown.name="Body";
			Object.DestroyImmediate(bodyDown.collider);
			bodyDown.transform.parent=unityCarObj.transform;
			bodyDown.transform.localPosition=Vector3.zero;
			bodyDown.transform.localRotation=Quaternion.identity;
			bodyDown.transform.localScale=new Vector3(1.5f,0.5f,4);
			
			bodyUp = GameObject.CreatePrimitive(PrimitiveType.Cube);
			bodyUp.name="Body";
			Object.DestroyImmediate(bodyUp.collider);
			bodyUp.transform.parent=unityCarObj.transform;
			bodyUp.transform.localRotation=Quaternion.identity;
			bodyUp.transform.localScale=new Vector3(bodyDown.transform.localScale.x,bodyDown.transform.localScale.y*0.666f,bodyDown.transform.localScale.z/2);
			bodyUp.transform.localPosition=new Vector3(0,bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y-bodyUp.transform.localScale.y)/2,0);
		}
		else{
			bodyDown=unityCarObj.transform.Find("Body").gameObject;
		}
		
		if (unityCarObj.transform.Find("Collider")==null){
			mcollider= new GameObject("ColliderDown");
			mcollider.transform.parent=unityCarObj.transform;
			mcollider.transform.localPosition=Vector3.zero;
			mcollider.transform.localRotation=Quaternion.identity;
			boxColliderDown = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider;
			boxColliderDown.transform.localScale=new Vector3(1.5f,0.5f,4);

			mcollider= new GameObject("ColliderUp");
			mcollider.transform.parent=unityCarObj.transform;
			mcollider.transform.localRotation=Quaternion.identity;		
			boxColliderUp = mcollider.gameObject.AddComponent<BoxCollider>() as BoxCollider;
			boxColliderUp.transform.localScale=new Vector3(boxColliderDown.transform.localScale.x,boxColliderDown.transform.localScale.y*0.666f,boxColliderDown.transform.localScale.z/2);
			boxColliderUp.transform.localPosition=new Vector3(0,boxColliderDown.transform.localScale.y-(boxColliderDown.transform.localScale.y-boxColliderUp.transform.localScale.y)/2,0);			
		}
		else{
			mcollider=unityCarObj.transform.Find("Collider").gameObject;
			boxColliderDown = mcollider.gameObject.GetComponent<BoxCollider>();
		}
		
 		if (unityCarObj.transform.Find("wheelFL")==null){
			wheelFL = new GameObject("wheelFL");
			wheelFL.transform.parent=unityCarObj.transform;
			wheel = wheelFL.gameObject.AddComponent<Wheel>() as Wheel;
			wheelFL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8);
			wheelFL.transform.localRotation=Quaternion.identity;
	
			wheel.showForces=false;
			wheel.wheelPos=WheelPos.FRONT_LEFT;
			axles.frontAxle.leftWheel=wheel;

			model = GameObject.CreatePrimitive(PrimitiveType.Sphere);
			model.name="modelFL";
			Object.DestroyImmediate(model.collider);			
			model.transform.parent=wheelFL.transform;
			model.transform.localPosition=Vector3.zero;
			model.transform.localRotation=Quaternion.identity;
			model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2);
			wheel.model=model;
		}
		else{
			wheelFL=unityCarObj.transform.Find("wheelFL").gameObject;
		}
		
		if (LayerMask.NameToLayer("Wheel")!=-1) wheelFL.gameObject.layer=LayerMask.NameToLayer("Wheel");
		
  	if (unityCarObj.transform.Find("wheelFR")==null){
			wheelFR = new GameObject("wheelFR");
			wheelFR.transform.parent=unityCarObj.transform;
			wheel = wheelFR.gameObject.AddComponent<Wheel>() as Wheel;
			wheelFR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8);
			wheelFR.transform.localRotation=Quaternion.identity;		
			
			wheel.showForces=false;
			wheel.wheelPos=WheelPos.FRONT_RIGHT;
			axles.frontAxle.rightWheel=wheel;

			model = GameObject.CreatePrimitive(PrimitiveType.Sphere);
			model.name="modelFR";
			Object.DestroyImmediate(model.collider);			
			model.transform.parent=wheelFR.transform;
			model.transform.localPosition=Vector3.zero;
			model.transform.localRotation=Quaternion.identity;
			model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2);
			wheel.model=model;
		}
		else{
			wheelFR=unityCarObj.transform.Find("wheelFR").gameObject;
		}
		if (LayerMask.NameToLayer("Wheel")!=-1) wheelFR.gameObject.layer=LayerMask.NameToLayer("Wheel");
		
  	if (unityCarObj.transform.Find("wheelRL")==null){
			wheelRL = new GameObject("wheelRL");
			wheelRL.transform.parent=unityCarObj.transform;
			wheel = wheelRL.gameObject.AddComponent<Wheel>() as Wheel;
			wheelRL.transform.localPosition=new Vector3(-boxColliderDown.transform.localScale.x/2+wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8));
			wheelRL.transform.localRotation=Quaternion.identity;		
			
			wheel.showForces=false;
			wheel.wheelPos=WheelPos.REAR_LEFT;
			axles.rearAxle.leftWheel=wheel;
			
			model = GameObject.CreatePrimitive(PrimitiveType.Sphere);
			model.name="modelRL";
			Object.DestroyImmediate(model.collider);			
			model.transform.parent=wheelRL.transform;
			model.transform.localPosition=Vector3.zero;
			model.transform.localRotation=Quaternion.identity;
			model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2);
			wheel.model=model;
		}
		else{
			wheelRL=unityCarObj.transform.Find("wheelRL").gameObject;
		}		
		if (LayerMask.NameToLayer("Wheel")!=-1) wheelRL.gameObject.layer=LayerMask.NameToLayer("Wheel");
		
  	if (unityCarObj.transform.Find("wheelRR")==null){
			wheelRR = new GameObject("wheelRR");
			wheelRR.transform.parent=unityCarObj.transform;
			wheel = wheelRR.gameObject.AddComponent<Wheel>() as Wheel;
			wheelRR.transform.localPosition=new Vector3(boxColliderDown.transform.localScale.x/2-wheel.width/2, -0.1f, -(boxColliderDown.transform.localScale.z/2 - boxColliderDown.transform.localScale.z/8));
			wheelRR.transform.localRotation=Quaternion.identity;		
			
			wheel.showForces=false;
			wheel.wheelPos=WheelPos.REAR_RIGHT;
			axles.rearAxle.rightWheel=wheel;
			
			model = GameObject.CreatePrimitive(PrimitiveType.Sphere);
			model.name="modelRR";
			Object.DestroyImmediate(model.collider);			
			model.transform.parent=wheelRR.transform;
			model.transform.localPosition=Vector3.zero;
			model.transform.localRotation=Quaternion.identity;
			model.transform.localScale=new Vector3(wheel.width,wheel.radius*2,wheel.radius*2);
			wheel.model=model;
		}
		else{
			wheelRR=unityCarObj.transform.Find("wheelRR").gameObject;
		}		
		if (LayerMask.NameToLayer("Wheel")!=-1) wheelRR.gameObject.layer=LayerMask.NameToLayer("Wheel");
				
		axles.frontAxle.maxSteeringAngle=33;
		axles.frontAxle.handbrakeFrictionTorque=0;
		axles.rearAxle.maxSteeringAngle=0;
		axles.rearAxle.handbrakeFrictionTorque=1000;
		axles.frontAxle.tires=CarDynamics.Tires.competition_front;
		axles.rearAxle.tires=CarDynamics.Tires.competition_rear;

		axles.SetWheels();
			
/*  		dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard"));
		if (dashBoard ){
			dashBoard.transform.parent=unityCarObj.transform;
			dashBoard.transform.localPosition=Vector3.zero;
			dashBoard.transform.localRotation=Quaternion.identity;				
		} */

		// These are to avoid warning about "assigned but never used"
		drivetrain.enabled=true;
		axisCarController.enabled=true;
		  		
		return unityCarObj;
	}
Пример #33
0
    public static GameObject CreateNewCar()
    {
        GameObject unityCarObj = new GameObject("UnityCar");

        if (unityCarObj.rigidbody == null)
        {
            mrigidbody               = unityCarObj.AddComponent <Rigidbody>() as Rigidbody;
            mrigidbody.mass          = 1000;
            mrigidbody.angularDrag   = 0;
            mrigidbody.interpolation = RigidbodyInterpolation.Interpolate;
        }
        else
        {
            mrigidbody = unityCarObj.GetComponent <Rigidbody>();
        }

        if (unityCarObj.GetComponent <CarDynamics>() == null)
        {
            carDynamics = unityCarObj.AddComponent <CarDynamics>() as CarDynamics;
        }
        else
        {
            carDynamics = unityCarObj.GetComponent <CarDynamics>();
        }

        centerOfMassObject = new GameObject("COG");
        centerOfMassObject.transform.parent        = unityCarObj.transform;
        centerOfMassObject.transform.localPosition = Vector3.zero;
        centerOfMassObject.transform.localRotation = Quaternion.identity;

        carDynamics.centerOfMass = centerOfMassObject.transform;

        if (unityCarObj.GetComponent <Drivetrain>() == null)
        {
            drivetrain = unityCarObj.AddComponent <Drivetrain>() as Drivetrain;
        }
        else
        {
            drivetrain = unityCarObj.GetComponent <Drivetrain>();
        }


        if (unityCarObj.GetComponent <AxisCarController>() == null)
        {
            axisCarController = unityCarObj.AddComponent <AxisCarController>() as AxisCarController;
        }
        else
        {
            axisCarController = unityCarObj.GetComponent <AxisCarController>();
        }

/*
 *              if (unityCarObj.GetComponent<SoundController>()==null)
 *                      soundController=unityCarObj.AddComponent<SoundController>() as SoundController;
 *              else
 *                      soundController=unityCarObj.GetComponent<SoundController>();
 *
 *              soundController.enabled=false; */

        if (unityCarObj.GetComponent <Axles>() == null)
        {
            axles = unityCarObj.AddComponent <Axles>() as Axles;
        }
        else
        {
            axles = unityCarObj.GetComponent <Axles>();
        }

        // to avoid car assigned to default layer
        unityCarObj.layer = 1;

        if (unityCarObj.transform.Find("Body") == null)
        {
            bodyDown      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            bodyDown.name = "Body";
            Object.DestroyImmediate(bodyDown.collider);
            bodyDown.transform.parent        = unityCarObj.transform;
            bodyDown.transform.localPosition = Vector3.zero;
            bodyDown.transform.localRotation = Quaternion.identity;
            bodyDown.transform.localScale    = new Vector3(1.5f, 0.5f, 4);

            bodyUp      = GameObject.CreatePrimitive(PrimitiveType.Cube);
            bodyUp.name = "Body";
            Object.DestroyImmediate(bodyUp.collider);
            bodyUp.transform.parent        = unityCarObj.transform;
            bodyUp.transform.localRotation = Quaternion.identity;
            bodyUp.transform.localScale    = new Vector3(bodyDown.transform.localScale.x, bodyDown.transform.localScale.y * 0.666f, bodyDown.transform.localScale.z / 2);
            bodyUp.transform.localPosition = new Vector3(0, bodyDown.transform.localScale.y - (bodyDown.transform.localScale.y - bodyUp.transform.localScale.y) / 2, 0);
        }
        else
        {
            bodyDown = unityCarObj.transform.Find("Body").gameObject;
        }

        if (unityCarObj.transform.Find("Collider") == null)
        {
            mcollider = new GameObject("ColliderDown");
            mcollider.transform.parent        = unityCarObj.transform;
            mcollider.transform.localPosition = Vector3.zero;
            mcollider.transform.localRotation = Quaternion.identity;
            boxColliderDown = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider;
            boxColliderDown.transform.localScale = new Vector3(1.5f, 0.5f, 4);

            mcollider = new GameObject("ColliderUp");
            mcollider.transform.parent        = unityCarObj.transform;
            mcollider.transform.localRotation = Quaternion.identity;
            boxColliderUp = mcollider.gameObject.AddComponent <BoxCollider>() as BoxCollider;
            boxColliderUp.transform.localScale    = new Vector3(boxColliderDown.transform.localScale.x, boxColliderDown.transform.localScale.y * 0.666f, boxColliderDown.transform.localScale.z / 2);
            boxColliderUp.transform.localPosition = new Vector3(0, boxColliderDown.transform.localScale.y - (boxColliderDown.transform.localScale.y - boxColliderUp.transform.localScale.y) / 2, 0);
        }
        else
        {
            mcollider       = unityCarObj.transform.Find("Collider").gameObject;
            boxColliderDown = mcollider.gameObject.GetComponent <BoxCollider>();
        }

        if (unityCarObj.transform.Find("wheelFL") == null)
        {
            wheelFL = new GameObject("wheelFL");
            wheelFL.transform.parent = unityCarObj.transform;
            wheel = wheelFL.gameObject.AddComponent <Wheel>() as Wheel;
            wheelFL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8);
            wheelFL.transform.localRotation = Quaternion.identity;

            wheel.showForces          = false;
            wheel.wheelPos            = WheelPos.FRONT_LEFT;
            axles.frontAxle.leftWheel = wheel;

            model      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            model.name = "modelFL";
            Object.DestroyImmediate(model.collider);
            model.transform.parent        = wheelFL.transform;
            model.transform.localPosition = Vector3.zero;
            model.transform.localRotation = Quaternion.identity;
            model.transform.localScale    = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2);
            wheel.model = model;
        }
        else
        {
            wheelFL = unityCarObj.transform.Find("wheelFL").gameObject;
        }

        if (LayerMask.NameToLayer("Wheel") != -1)
        {
            wheelFL.gameObject.layer = LayerMask.NameToLayer("Wheel");
        }

        if (unityCarObj.transform.Find("wheelFR") == null)
        {
            wheelFR = new GameObject("wheelFR");
            wheelFR.transform.parent = unityCarObj.transform;
            wheel = wheelFR.gameObject.AddComponent <Wheel>() as Wheel;
            wheelFR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8);
            wheelFR.transform.localRotation = Quaternion.identity;

            wheel.showForces           = false;
            wheel.wheelPos             = WheelPos.FRONT_RIGHT;
            axles.frontAxle.rightWheel = wheel;

            model      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            model.name = "modelFR";
            Object.DestroyImmediate(model.collider);
            model.transform.parent        = wheelFR.transform;
            model.transform.localPosition = Vector3.zero;
            model.transform.localRotation = Quaternion.identity;
            model.transform.localScale    = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2);
            wheel.model = model;
        }
        else
        {
            wheelFR = unityCarObj.transform.Find("wheelFR").gameObject;
        }
        if (LayerMask.NameToLayer("Wheel") != -1)
        {
            wheelFR.gameObject.layer = LayerMask.NameToLayer("Wheel");
        }

        if (unityCarObj.transform.Find("wheelRL") == null)
        {
            wheelRL = new GameObject("wheelRL");
            wheelRL.transform.parent = unityCarObj.transform;
            wheel = wheelRL.gameObject.AddComponent <Wheel>() as Wheel;
            wheelRL.transform.localPosition = new Vector3(-boxColliderDown.transform.localScale.x / 2 + wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8));
            wheelRL.transform.localRotation = Quaternion.identity;

            wheel.showForces         = false;
            wheel.wheelPos           = WheelPos.REAR_LEFT;
            axles.rearAxle.leftWheel = wheel;

            model      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            model.name = "modelRL";
            Object.DestroyImmediate(model.collider);
            model.transform.parent        = wheelRL.transform;
            model.transform.localPosition = Vector3.zero;
            model.transform.localRotation = Quaternion.identity;
            model.transform.localScale    = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2);
            wheel.model = model;
        }
        else
        {
            wheelRL = unityCarObj.transform.Find("wheelRL").gameObject;
        }
        if (LayerMask.NameToLayer("Wheel") != -1)
        {
            wheelRL.gameObject.layer = LayerMask.NameToLayer("Wheel");
        }

        if (unityCarObj.transform.Find("wheelRR") == null)
        {
            wheelRR = new GameObject("wheelRR");
            wheelRR.transform.parent = unityCarObj.transform;
            wheel = wheelRR.gameObject.AddComponent <Wheel>() as Wheel;
            wheelRR.transform.localPosition = new Vector3(boxColliderDown.transform.localScale.x / 2 - wheel.width / 2, -0.1f, -(boxColliderDown.transform.localScale.z / 2 - boxColliderDown.transform.localScale.z / 8));
            wheelRR.transform.localRotation = Quaternion.identity;

            wheel.showForces          = false;
            wheel.wheelPos            = WheelPos.REAR_RIGHT;
            axles.rearAxle.rightWheel = wheel;

            model      = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            model.name = "modelRR";
            Object.DestroyImmediate(model.collider);
            model.transform.parent        = wheelRR.transform;
            model.transform.localPosition = Vector3.zero;
            model.transform.localRotation = Quaternion.identity;
            model.transform.localScale    = new Vector3(wheel.width, wheel.radius * 2, wheel.radius * 2);
            wheel.model = model;
        }
        else
        {
            wheelRR = unityCarObj.transform.Find("wheelRR").gameObject;
        }
        if (LayerMask.NameToLayer("Wheel") != -1)
        {
            wheelRR.gameObject.layer = LayerMask.NameToLayer("Wheel");
        }

        axles.frontAxle.maxSteeringAngle        = 33;
        axles.frontAxle.handbrakeFrictionTorque = 0;
        axles.rearAxle.maxSteeringAngle         = 0;
        axles.rearAxle.handbrakeFrictionTorque  = 1000;
        axles.frontAxle.tires = CarDynamics.Tires.competition_front;
        axles.rearAxle.tires  = CarDynamics.Tires.competition_rear;

        axles.SetWheels();

/*          dashBoard = (GameObject)Instantiate(Resources.Load("Samples/Prefabs/Cars/DashBoard"));
 *              if (dashBoard ){
 *                      dashBoard.transform.parent=unityCarObj.transform;
 *                      dashBoard.transform.localPosition=Vector3.zero;
 *                      dashBoard.transform.localRotation=Quaternion.identity;
 *              } */

        // These are to avoid warning about "assigned but never used"
        drivetrain.enabled        = true;
        axisCarController.enabled = true;

        return(unityCarObj);
    }
Пример #34
0
        /// <summary>
        /// Initialize class
        /// </summary>
        /// <param name="gameObjectName"></param>
        public Vehicle(string gameObjectName)
        {
            // gameObject the object by name
            gameObject = GameObject.Find(gameObjectName);

            // Use Resources.FindObjectsOfTypeAll method, if the vehicle was not found.
            if (gameObject == null)
            {
                gameObject = Resources.FindObjectsOfTypeAll <GameObject>().FirstOrDefault(g => g.name == gameObjectName);
            }

            if (gameObject == null)
            {
                ModConsole.Error($"[MOP] Could not find {gameObjectName} vehicle.");
                return;
            }

            // Get the object position and rotation
            Position = gameObject.transform.localPosition;
            Rotation = gameObject.transform.localRotation;

            // Creates a new gameobject that is names after the original file + '_TEMP' (ex. "SATSUMA(557kg, 248)_TEMP")
            temporaryParent = new GameObject($"{gameObject.name}_TEMP").transform;

            preventToggleOnObjects = new List <PreventToggleOnObject>();

            // This should fix bug that leads to items inside of vehicles to fall through it.
            PlayMakerFSM lodFSM = gameObject.GetPlayMakerByName("LOD");

            if (lodFSM != null)
            {
                lodFSM.Fsm.RestartOnEnable = false;
                FsmState resetState = lodFSM.FindFsmState("Fix Collider");
                if (resetState != null)
                {
                    resetState.Actions = new FsmStateAction[] { new CustomStopAction() };
                    resetState.SaveActions();
                }

                lodFSM.FindFsmState("Load game").Actions = new FsmStateAction[] { new CustomNullState() };
            }

            if (gameObject.name == "BOAT")
            {
                return;
            }

            // Get the object's child which are responsible for audio
            foreach (Transform audioObject in FindAudioObjects())
            {
                preventToggleOnObjects.Add(new PreventToggleOnObject(audioObject));
            }

            // Fix for fuel level resetting after respawn
            Transform fuelTank = gameObject.transform.Find("FuelTank");

            if (fuelTank != null)
            {
                PlayMakerFSM fuelTankFSM = fuelTank.GetComponent <PlayMakerFSM>();
                if (fuelTankFSM)
                {
                    fuelTankFSM.Fsm.RestartOnEnable = false;
                }
            }

            // If the vehicle is Gifu, find knobs and add them to list of unloadable objects
            if (gameObject.name == "GIFU(750/450psi)")
            {
                Transform knobs = gameObject.transform.Find("Dashboard/Knobs");
                foreach (PlayMakerFSM knobsFSMs in knobs.GetComponentsInChildren <PlayMakerFSM>())
                {
                    knobsFSMs.Fsm.RestartOnEnable = false;
                }

                PlayMakerFSM          shitFsm          = gameObject.transform.Find("ShitTank").gameObject.GetComponent <PlayMakerFSM>();
                FsmState              loadGame         = shitFsm.FindFsmState("Load game");
                List <FsmStateAction> loadArrayActions = new List <FsmStateAction> {
                    new CustomNullState()
                };
                loadArrayActions.Add(new CustomNullState());
                loadGame.Actions = loadArrayActions.ToArray();
                loadGame.SaveActions();
            }

            // Fixed kickstand resetting to the default value.
            if (gameObject.name == "JONNEZ ES(Clone)")
            {
                PlayMakerFSM          kickstandFsm     = gameObject.transform.Find("Kickstand").gameObject.GetComponent <PlayMakerFSM>();
                FsmState              loadGame         = kickstandFsm.FindFsmState("Load game");
                List <FsmStateAction> loadArrayActions = new List <FsmStateAction> {
                    new CustomNullState()
                };
                loadArrayActions.Add(new CustomNullState());
                loadGame.Actions = loadArrayActions.ToArray();
                loadGame.SaveActions();

                // Disable on restart for wheels script.
                Transform wheelsParent = transform.Find("Wheels");
                foreach (Transform wheel in wheelsParent.GetComponentsInChildren <Transform>())
                {
                    if (!wheel.gameObject.name.StartsWith("Moped_wheel"))
                    {
                        continue;
                    }
                    wheel.gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false;
                }
            }

            carDynamics = gameObject.GetComponent <CarDynamics>();
            axles       = gameObject.GetComponent <Axles>();
            rb          = gameObject.GetComponent <Rigidbody>();

            // Hook HookFront and HookRear
            // Get hooks first
            Transform hookFront = transform.Find("HookFront");
            Transform hookRear  = transform.Find("HookRear");

            // If hooks exists, attach the RopeHookUp and RopeUnhook to appropriate states
            if (hookFront != null)
            {
                fsmHookFront = hookFront.GetComponent <PlayMakerFSM>();
            }

            if (hookRear != null)
            {
                fsmHookRear = hookRear.GetComponent <PlayMakerFSM>();
            }

            // If vehicle is flatbed, hook SwitchToggleMethod to Add scale script
            if (gameObject.name == "FLATBED")
            {
                PlayMakerFSM          logTriggerFsm    = transform.Find("Bed/LogTrigger").gameObject.GetComponent <PlayMakerFSM>();
                FsmState              loadGame         = logTriggerFsm.FindFsmState("Load game");
                List <FsmStateAction> loadArrayActions = new List <FsmStateAction> {
                    new CustomNullState()
                };
                loadGame.Actions = loadArrayActions.ToArray();
                loadGame.SaveActions();

                GameObject trailerLogUnderFloorCheck = new GameObject("MOP_TrailerLogUnderFloorFix");
                trailerLogUnderFloorCheck.transform.parent = gameObject.transform;
                trailerLogUnderFloorCheck.AddComponent <TrailerLogUnderFloor>();
            }

            // Set default toggling method - that is entire vehicle
            Toggle = ToggleActive;

            isHayosiko = gameObject.name == "HAYOSIKO(1500kg, 250)";
            isKekmet   = gameObject.name == "KEKMET(350-400psi)";

            // If the user selected to toggle vehicle's physics only, it overrided any previous set for Toggle method
            if (Rules.instance.SpecialRules.ToggleAllVehiclesPhysicsOnly)
            {
                Toggle = IgnoreToggle;
            }

            // Get all HingeJoints and add HingeManager to them
            // Ignore for Satsuma or cars that use ToggleUnityCar method (and force for Hayosiko - no matter what)
            if (SatsumaScript == null && Toggle != ToggleUnityCar || isHayosiko)
            {
                HingeJoint[] joints = gameObject.transform.GetComponentsInChildren <HingeJoint>();
                foreach (HingeJoint joint in joints)
                {
                    joint.gameObject.AddComponent <HingeManager>();
                }
            }

            // Get one of the wheels.
            wheel      = axles.allWheels[0];
            drivetrain = gameObject.GetComponent <Drivetrain>();

            // Ignore Rules.
            IgnoreRule vehicleRule = Rules.instance.IgnoreRules.Find(v => v.ObjectName == this.gameObject.name);

            if (vehicleRule != null)
            {
                Toggle = IgnoreToggle;

                if (vehicleRule.TotalIgnore)
                {
                    IsActive = false;
                }
            }

            // Prevent Toggle On Object Rule.
            IgnoreRuleAtPlace[] preventToggleOnObjectRule = Rules.instance.IgnoreRulesAtPlaces
                                                            .Where(v => v.Place == this.gameObject.name).ToArray();
            if (preventToggleOnObjectRule.Length > 0)
            {
                foreach (var p in preventToggleOnObjectRule)
                {
                    Transform t = transform.FindRecursive(p.ObjectName);
                    if (t == null)
                    {
                        ModConsole.Error($"[MOP] Couldn't find {p.ObjectName} in {p.Place}.");
                        continue;
                    }

                    preventToggleOnObjects.Add(new PreventToggleOnObject(t));
                }
            }

            eventSounds = gameObject.GetComponent <EventSounds>();

            // Odometers fix.
            switch (gameObject.name)
            {
            case "GIFU(750/450psi)":
                transform.Find("Dashboard/Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false;
                break;

            case "HAYOSIKO(1500kg, 250)":
                transform.Find("Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false;
                break;

            case "KEKMET(350-400psi)":
                transform.Find("Dashboard/HourMeter").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false;
                break;

            case "SATSUMA(557kg, 248)":
                GameObject.Find("dashboard meters(Clone)").transform.Find("Gauges/Odometer").gameObject.GetComponent <PlayMakerFSM>().Fsm.RestartOnEnable = false;
                break;
            }
        }
Пример #35
0
	void Start()
	{
		myTransform=transform;
		body=rigidbody;	
    if(meshFilters.Length==0){
			//meshFilters = GetComponentsInChildren<MeshFilter>();
			m_meshFilters = GetComponentsInChildren<MeshFilter>();
				
			int k=0;
			for (i = 0; i < m_meshFilters.Length; i++){
				if (m_meshFilters[i].collider==null) k++;
			}
			meshFilters=new MeshFilter[k];
			k=0;
			for (i = 0; i < m_meshFilters.Length; i++){
				if (m_meshFilters[i].collider==null){
					meshFilters[k]=m_meshFilters[i];
					k++;
				}
			}
		}
		
		if (meshCollider!=null){
			//meshFilterColl=meshCollider.gameObject.GetComponent<MeshFilter>();
			colliderVerts = meshCollider.sharedMesh.vertices;
		}
	
		LoadoriginalMeshData();

		foreach(Transform child in transform){
			if (child.gameObject.tag=="Body" || child.gameObject.name=="Body" || child.gameObject.name=="body") GObody=child.gameObject;
		}
		if (GObody) {
			sign=Mathf.Cos(GObody.transform.localEulerAngles.y*Mathf.Deg2Rad);
			if (GObody.transform.localEulerAngles.x!=0) rot=Quaternion.AngleAxis(GObody.transform.localEulerAngles.x*3,Vector3.right);
		}
		
		carDynamics = GetComponent<CarDynamics>();
		axles = GetComponent<Axles>();
		wheelLayer=axles.allWheels[0].transform.gameObject.layer;
		carLayer=transform.gameObject.layer;
   }
Пример #36
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;
				}
			}
		}
	}		
Пример #37
0
 public void Start()
 {
     cardynamics = GetComponent <CarDynamics>();
     InitialiseForceFeedback();
     SetAutoCenter(false);
 }
Пример #38
0
    void Start()
    {
        myTransform = transform;

        trs = myTransform.parent;

        //while (trs != null && trs.rigidbody == null) trs = trs.parent;
        //if (trs != null) body = trs.rigidbody;
        //Rigidbody rb = trs.GetComponent<Rigidbody>();
        //while (trs != null && trs.gameObject.GetComponent<Rigidbody>() == null) trs = trs.parent;
        //if (trs != null) body = trs.gameObject.GetComponent<Rigidbody>();

        if (body == null)
        {
            Rigidbody rb;
            do
            {
                rb  = trs.GetComponent <Rigidbody>();
                trs = trs.parent;
            }while (trs != null && rb == null);
            if (trs != null)
            {
                body = rb;
            }
        }

        //if (!trs.TryGetComponent<Rigidbody>(out body)) trs = trs.parent;

        trs = myTransform.parent;
        while (trs.GetComponent <PhysicMaterials>() == null)
        {
            if (trs.parent)
            {
                trs = trs.parent;
            }
            else
            {
                break;
            }
        }
        physicMaterials = trs.GetComponent <PhysicMaterials>();

        trs = myTransform.parent;
        while (trs.GetComponent <CarDynamics>() == null)
        {
            trs = trs.parent;
        }
        cardynamics = trs.GetComponent <CarDynamics>();
        drivetrain  = trs.GetComponent <Drivetrain>();
        axles       = trs.GetComponent <Axles>();

        localScale = 1 / (trs.localScale.y * myTransform.localScale.y);

        layerMask = 1 << trs.gameObject.layer | 1 << myTransform.gameObject.layer;  //LayerMask.NameToLayer("Wheel");
        layerMask = ~layerMask;

        radiusLoaded = radius;
        if (rimRadius == 0)
        {
            rimRadius = radius * 0.735f;
        }
        sidewallHeight = radius - rimRadius;

        if (mass < 50 * cardynamics.invFixedTimeStepScalar)
        {
            mass = 50 * cardynamics.invFixedTimeStepScalar;
        }
        if (rotationalInertia == 0 || rotationalInertia < (mass / 2) * radius * radius)
        {
            rotationalInertia = (mass / 2) * radius * radius;
        }
        originalMass = mass;

        if (model == null)
        {
            model = new GameObject("temp_model");
            model.transform.parent        = transform;
            model.transform.localPosition = new Vector3(0, 0, 0);
            model.transform.localRotation = Quaternion.identity;
            Debug.LogWarning("UnityCar: wheel model in " + wheelPos + " is missing. Using empty object" + " (" + trs.name + ")");
        }

        modelTransform = model.transform;
        if (caliperModel != null)
        {
            caliperModelTransform = caliperModel.transform;
        }

        skidmarks = cardynamics.skidmarks;
        //if (skidmarks) skidSmoke = skidmarks.GetComponentInChildren(typeof(ParticleEmitter)) as ParticleEmitter;

        //suspensionLineRenderer=gameObject.GetComponent<LineRenderer>();
        //if (suspensionLineRenderer==null) suspensionLineRenderer = gameObject.AddComponent<LineRenderer>();
        //suspensionLineRenderer.material = new Material(Shader.Find("Diffuse"));
        //suspensionLineRenderer.material.color = Color.yellow;
        //suspensionLineRenderer.SetWidth(0.01f,0.1f);
        //suspensionLineRenderer.useWorldSpace = false;
        //suspensionLineRenderer.castShadows = false;

        camber *= 1;       // to avoid never assigned warning
        if (camber == 0)
        {
            up = myTransform.up;
        }
        else
        {
            camberRotation = Quaternion.AngleAxis(-camber, forwardNormal);
            up             = camberRotation * myTransform.up;
        }

        SetTireStiffness();
    }