public virtual void Start()
        {
            vp = transform.GetTopmostParentComponent <VehicleParent>();

            // Get engine sound
            snd = GetComponent <AudioSource>();
            if (snd)
            {
                snd.pitch = minPitch;
            }

            // Get boost sound
            if (boostLoopSnd)
            {
                GameObject newBoost = Instantiate(boostLoopSnd.gameObject, boostLoopSnd.transform.position, boostLoopSnd.transform.rotation) as GameObject;
                boostSnd = newBoost.GetComponent <AudioSource>();
                boostSnd.transform.parent        = boostLoopSnd.transform;
                boostSnd.transform.localPosition = Vector3.zero;
                boostSnd.transform.localRotation = Quaternion.identity;
                boostSnd.loop = false;
            }

            if (smoke)
            {
                initialSmokeEmission = smoke.emission.rateOverTime.constantMax;
            }
        }
示例#2
0
        public void Initialize(GameObject newVehicle)
        {
            if (!newVehicle)
            {
                return;
            }
            targetVehicle = newVehicle;
            vp            = targetVehicle.GetComponent <VehicleParent>();

            trans = targetVehicle.GetComponentInChildren <Transmission>();
            if (trans)
            {
                if (trans is GearboxTransmission)
                {
                    gearbox = trans as GearboxTransmission;
                }
                else if (trans is ContinuousTransmission)
                {
                    varTrans = trans as ContinuousTransmission;
                }
            }

            if (stuntMode)
            {
                stunter = targetVehicle.GetComponent <StuntDetect>();
            }

            engine         = targetVehicle.GetComponentInChildren <Motor>();
            propertySetter = targetVehicle.GetComponent <PropertyToggleSetter>();

            stuntText.gameObject.SetActive(stuntMode);
            scoreText.gameObject.SetActive(stuntMode);
        }
示例#3
0
 void Start()
 {
     tr = transform;
     rb = GetComponent <Rigidbody>();
     vp = GetComponent <VehicleParent>();
     initialAngularDrag = rb.angularDrag;
 }
        void Start()
        {
            tr           = transform;
            rb           = GetComponent <Rigidbody>();
            vp           = GetComponent <VehicleParent>();
            va           = GetComponent <VehicleAssist>();
            initialSpeed = speed;

            InitializeTarget();
        }
        public void SpawnVehicle(int vehicle)
        {
            newVehicle = Instantiate(vehicles[vehicle], spawnPoint, Quaternion.LookRotation(spawnRot, GlobalControl.worldUpDir)) as GameObject;
            cam.target = newVehicle.transform;
            cam.Initialize();
            vp = newVehicle.GetComponent <VehicleParent>();

            trans = newVehicle.GetComponentInChildren <Transmission>();
            if (trans)
            {
                trans.automatic = autoShift;
                newVehicle.GetComponent <VehicleParent>().brakeIsReverse = autoShift;

                if (trans is GearboxTransmission)
                {
                    gearbox = trans as GearboxTransmission;
                }
                else if (trans is ContinuousTransmission)
                {
                    varTrans = trans as ContinuousTransmission;

                    if (!autoShift)
                    {
                        vp.brakeIsReverse = true;
                    }
                }
            }

            if (newVehicle.GetComponent <VehicleAssist>())
            {
                newVehicle.GetComponent <VehicleAssist>().enabled = assist;
            }

            if (newVehicle.GetComponent <FlipControl>() && newVehicle.GetComponent <StuntDetect>())
            {
                newVehicle.GetComponent <FlipControl>().flipPower          = stuntMode && assist ? new Vector3(10, 10, -10) : Vector3.zero;
                newVehicle.GetComponent <FlipControl>().rotationCorrection = stuntMode ? Vector3.zero : (assist ? new Vector3(5, 1, 10) : Vector3.zero);
                newVehicle.GetComponent <FlipControl>().stopFlip           = assist;
                stunter = newVehicle.GetComponent <StuntDetect>();
            }

            engine         = newVehicle.GetComponentInChildren <Motor>();
            propertySetter = newVehicle.GetComponent <PropertyToggleSetter>();

            stuntText.gameObject.SetActive(stuntMode);
            scoreText.gameObject.SetActive(stuntMode);
        }
示例#6
0
        void Start()
        {
            vp = GetComponent <VehicleParent>();

            // Get transmission for using reverse lights
            if (transmission)
            {
                if (transmission is GearboxTransmission)
                {
                    gearTrans = transmission as GearboxTransmission;
                }
                else if (transmission is ContinuousTransmission)
                {
                    conTrans = transmission as ContinuousTransmission;
                }
            }
        }
示例#7
0
        void Start()
        {
            snd    = GetComponent <AudioSource>();
            vp     = transform.GetTopmostParentComponent <VehicleParent>();
            wheels = new Wheel[vp.wheels.Length];

            //Get wheels and average slip threshold
            for (int i = 0; i < vp.wheels.Length; i++)
            {
                wheels[i] = vp.wheels[i];
                if (vp.wheels[i].GetComponent <TireMarkCreate>())
                {
                    float newThreshold = vp.wheels[i].GetComponent <TireMarkCreate>().slipThreshold;
                    slipThreshold = i == 0 ? newThreshold : (slipThreshold + newThreshold) * 0.5f;
                }
            }
        }
        void Start()
        {
            tr = transform;
            rb = GetComponent <Rigidbody>();
            vp = GetComponent <VehicleParent>();

            //Tell VehicleParent not to play crashing sounds because this script takes care of it
            vp.playCrashSounds = false;
            vp.playCrashSparks = false;

            //Set up mesh data
            tempMeshes    = new Mesh[deformMeshes.Length];
            damagedMeshes = new bool[deformMeshes.Length];
            meshVertices  = new meshVerts[deformMeshes.Length];
            for (int i = 0; i < deformMeshes.Length; i++)
            {
                tempMeshes[i]                = deformMeshes[i].mesh;
                meshVertices[i]              = new meshVerts();
                meshVertices[i].verts        = deformMeshes[i].mesh.vertices;
                meshVertices[i].initialVerts = deformMeshes[i].mesh.vertices;
                damagedMeshes[i]             = false;
            }

            //Set up mesh collider data
            tempCols    = new Mesh[deformColliders.Length];
            damagedCols = new bool[deformColliders.Length];
            colVertices = new meshVerts[deformColliders.Length];
            for (int i = 0; i < deformColliders.Length; i++)
            {
                tempCols[i]                 = (Mesh)Instantiate(deformColliders[i].sharedMesh);
                colVertices[i]              = new meshVerts();
                colVertices[i].verts        = deformColliders[i].sharedMesh.vertices;
                colVertices[i].initialVerts = deformColliders[i].sharedMesh.vertices;
                damagedCols[i]              = false;
            }

            //Set initial positions for displaced parts
            initialPartPositions = new Vector3[displaceParts.Length];
            for (int i = 0; i < displaceParts.Length; i++)
            {
                initialPartPositions[i] = displaceParts[i].localPosition;
            }
        }
        void Start()
        {
            tr                = transform;
            rb                = tr.GetTopmostParentComponent <Rigidbody>();
            vp                = tr.GetTopmostParentComponent <VehicleParent>();
            targetDrive       = GetComponent <DriveForce>();
            flippedSide       = Vector3.Dot(tr.forward, vp.transform.right) < 0;
            flippedSideFactor = flippedSide ? -1 : 1;
            initialRotation   = tr.localRotation;

            if (Application.isPlaying)
            {
                GetCamber();

                //Generate the hard collider
                if (generateHardCollider)
                {
                    GameObject cap = new GameObject("Compress Collider");
                    cap.layer                    = GlobalControl.ignoreWheelCastLayer;
                    compressTr                   = cap.transform;
                    compressTr.parent            = tr;
                    compressTr.localPosition     = Vector3.zero;
                    compressTr.localEulerAngles  = new Vector3(camberAngle, 0, -casterAngle * flippedSideFactor);
                    compressCol                  = cap.AddComponent <CapsuleCollider>();
                    compressCol.direction        = 1;
                    setHardColliderRadiusFactor  = hardColliderRadiusFactor;
                    hardColliderRadiusFactorPrev = setHardColliderRadiusFactor;
                    compressCol.radius           = wheel.rimWidth * hardColliderRadiusFactor;
                    compressCol.height           = (wheel.popped ? wheel.rimRadius : Mathf.Lerp(wheel.rimRadius, wheel.tireRadius, wheel.tirePressure)) * 2;
                    compressCol.material         = GlobalControl.frictionlessMatStatic;
                }

                steerRangeMax = Mathf.Max(steerRangeMin, steerRangeMax);

                properties = GetComponent <SuspensionPropertyToggle>();
                if (properties)
                {
                    UpdateProperties();
                }
            }
        }
示例#10
0
        void Start()
        {
            tr = transform;
            rb = tr.GetTopmostParentComponent <Rigidbody>();
            vp = tr.GetTopmostParentComponent <VehicleParent>();
            flippedSideFactor = Vector3.Dot(tr.forward, vp.transform.right) < 0 ? 1 : -1;
            canDetach         = detachForce < Mathf.Infinity && Application.isPlaying;
            bufferDistance    = Mathf.Min(hoverDistance, bufferDistance);

            if (canDetach)
            {
                detachedWheel           = new GameObject(vp.transform.name + "'s Detached Wheel");
                detachedWheel.layer     = LayerMask.NameToLayer("Detachable Part");
                detachFilter            = detachedWheel.AddComponent <MeshFilter>();
                detachFilter.sharedMesh = visualWheel.GetComponent <MeshFilter>().sharedMesh;
                MeshRenderer detachRend = detachedWheel.AddComponent <MeshRenderer>();
                detachRend.sharedMaterial = visualWheel.GetComponent <MeshRenderer>().sharedMaterial;
                detachedCol        = detachedWheel.AddComponent <MeshCollider>();
                detachedCol.convex = true;
                detachedBody       = detachedWheel.AddComponent <Rigidbody>();
                detachedBody.mass  = mass;
                detachedWheel.SetActive(false);
            }
        }
        public void Initialize()
        {
            //lookObj is an object used to help position and rotate the camera
            if (!lookObj)
            {
                GameObject lookTemp = new GameObject("Camera Looker");
                lookObj = lookTemp.transform;
            }

            //Set variables based on target vehicle's properties
            if (target)
            {
                vp          = target.GetComponent <VehicleParent>();
                distance   += vp.cameraDistanceChange;
                height     += vp.cameraHeightChange;
                forwardLook = target.forward;
                upLook      = target.up;
                targetBody  = target.GetComponent <Rigidbody>();
            }

            //Set the audio listener update mode to fixed, because the camera moves in FixedUpdate
            //This is necessary for doppler effects to sound correct
            GetComponent <AudioListener>().velocityUpdateMode = AudioVelocityUpdateMode.Fixed;
        }
        void Start()
        {
            tr = transform;
            rb = (Rigidbody)F.GetTopmostParentComponent <Rigidbody>(tr);
            vp = (VehicleParent)F.GetTopmostParentComponent <VehicleParent>(tr);
            suspensionParent    = tr.parent.GetComponent <Suspension>();
            travelDist          = suspensionParent.targetCompression;
            canDetach           = detachForce < Mathf.Infinity && Application.isPlaying;
            initialTirePressure = tirePressure;

            if (tr.childCount > 0)
            {
                //Get rim
                rim = tr.GetChild(0);

                //Set up rim glow material
                if (rimGlow > 0 && Application.isPlaying)
                {
                    rimMat = new Material(rim.GetComponent <MeshRenderer>().sharedMaterial);
                    rimMat.EnableKeyword("_EMISSION");
                    rim.GetComponent <MeshRenderer>().material = rimMat;
                }

                //Create detached wheel
                if (canDetach)
                {
                    detachedWheel           = new GameObject(vp.transform.name + "'s Detached Wheel");
                    detachedWheel.layer     = LayerMask.NameToLayer("Detachable Part");
                    detachFilter            = detachedWheel.AddComponent <MeshFilter>();
                    detachFilter.sharedMesh = rim.GetComponent <MeshFilter>().sharedMesh;
                    MeshRenderer detachRend = detachedWheel.AddComponent <MeshRenderer>();
                    detachRend.sharedMaterial = rim.GetComponent <MeshRenderer>().sharedMaterial;
                    detachedCol        = detachedWheel.AddComponent <MeshCollider>();
                    detachedCol.convex = true;
                    detachedBody       = detachedWheel.AddComponent <Rigidbody>();
                    detachedBody.mass  = mass;
                }

                //Get tire
                if (rim.childCount > 0)
                {
                    tire = rim.GetChild(0);
                    if (deformAmount > 0 && Application.isPlaying)
                    {
                        tireMat = new Material(tire.GetComponent <MeshRenderer>().sharedMaterial);
                        tire.GetComponent <MeshRenderer>().material = tireMat;
                    }

                    //Create detached tire
                    if (canDetach)
                    {
                        detachedTire = new GameObject("Detached Tire");
                        detachedTire.transform.parent        = detachedWheel.transform;
                        detachedTire.transform.localPosition = Vector3.zero;
                        detachedTire.transform.localRotation = Quaternion.identity;
                        detachTireFilter            = detachedTire.AddComponent <MeshFilter>();
                        detachTireFilter.sharedMesh = tire.GetComponent <MeshFilter>().sharedMesh;
                        MeshRenderer detachTireRend = detachedTire.AddComponent <MeshRenderer>();
                        detachTireRend.sharedMaterial = tireMat ? tireMat : tire.GetComponent <MeshRenderer>().sharedMaterial;
                    }
                }

                if (Application.isPlaying)
                {
                    //Generate hard collider
                    if (generateHardCollider)
                    {
                        GameObject sphereColNew = new GameObject("Rim Collider");
                        sphereColNew.layer        = GlobalControl.ignoreWheelCastLayer;
                        sphereColTr               = sphereColNew.transform;
                        sphereCol                 = sphereColNew.AddComponent <SphereCollider>();
                        sphereColTr.parent        = tr;
                        sphereColTr.localPosition = Vector3.zero;
                        sphereColTr.localRotation = Quaternion.identity;
                        sphereCol.radius          = Mathf.Min(rimWidth * 0.5f, rimRadius * 0.5f);
                        sphereCol.material        = GlobalControl.frictionlessMatStatic;
                    }

                    if (canDetach)
                    {
                        detachedWheel.SetActive(false);
                    }
                }
            }

            targetDrive = GetComponent <DriveForce>();
            currentRPM  = 0;
        }
示例#13
0
 void Start()
 {
     vp     = GetComponent <VehicleParent>();
     setter = FindObjectOfType <MobileInput>();
 }
示例#14
0
 void Start()
 {
     tr = transform;
     vp = (VehicleParent)F.GetTopmostParentComponent <VehicleParent>(tr);
 }
示例#15
0
 public virtual void Start()
 {
     vp          = transform.GetTopmostParentComponent <VehicleParent>();
     targetDrive = GetComponent <DriveForce>();
     newDrive    = gameObject.AddComponent <DriveForce>();
 }
 void Start()
 {
     vp             = GetComponent <VehicleParent>();
     carElectricity = GetComponent <CarElectricity>();
 }
 void Start()
 {
     tr       = transform;
     vp       = tr.GetTopmostParentComponent <VehicleParent>();
     steerRot = rotationOffset;
 }
 void Start()
 {
     vp = GetComponent <VehicleParent>();
 }
示例#19
0
 void Start()
 {
     tr = transform;
     rb = GetComponent <Rigidbody>();
     vp = GetComponent <VehicleParent>();
 }
 void Start()
 {
     tr = transform;
     vp = tr.GetTopmostParentComponent <VehicleParent>();
 }
        public override void OnInspectorGUI()
        {
            GUIStyle boldFoldout = new GUIStyle(EditorStyles.foldout);

            boldFoldout.fontStyle = FontStyle.Bold;
            VehicleParent targetScript = (VehicleParent)target;

            VehicleParent[] allTargets = new VehicleParent[targets.Length];
            isPrefab = F.IsPrefab(targetScript);

            for (int i = 0; i < targets.Length; i++)
            {
                Undo.RecordObject(targets[i], "Vehicle Parent Change");
                allTargets[i] = targets[i] as VehicleParent;
            }

            wheelMissing = false;
            if (targetScript.wheelGroups != null)
            {
                if (targetScript.wheelGroups.Length > 0)
                {
                    if (targetScript.hover)
                    {
                        foreach (HoverWheel curWheel in targetScript.hoverWheels)
                        {
                            bool wheelfound = false;
                            foreach (WheelCheckGroup curGroup in targetScript.wheelGroups)
                            {
                                foreach (HoverWheel curWheelInstance in curGroup.hoverWheels)
                                {
                                    if (curWheel == curWheelInstance)
                                    {
                                        wheelfound = true;
                                    }
                                }
                            }

                            if (!wheelfound)
                            {
                                wheelMissing = true;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (Wheel curWheel in targetScript.wheels)
                        {
                            bool wheelfound = false;
                            foreach (WheelCheckGroup curGroup in targetScript.wheelGroups)
                            {
                                foreach (Wheel curWheelInstance in curGroup.wheels)
                                {
                                    if (curWheel == curWheelInstance)
                                    {
                                        wheelfound = true;
                                    }
                                }
                            }

                            if (!wheelfound)
                            {
                                wheelMissing = true;
                                break;
                            }
                        }
                    }
                }
            }

            if (wheelMissing)
            {
                EditorGUILayout.HelpBox("If there is at least one wheel group, all wheels must be part of a group.", MessageType.Error);
            }

            DrawDefaultInspector();

            if (!isPrefab && targetScript.gameObject.activeInHierarchy)
            {
                showButtons = EditorGUILayout.Foldout(showButtons, "Quick Actions", boldFoldout);
                EditorGUI.indentLevel++;
                if (showButtons)
                {
                    if (GUILayout.Button("Get Engine"))
                    {
                        foreach (VehicleParent curTarget in allTargets)
                        {
                            curTarget.engine = curTarget.transform.GetComponentInChildren <Motor>();
                        }
                    }

                    if (GUILayout.Button("Get Wheels"))
                    {
                        foreach (VehicleParent curTarget in allTargets)
                        {
                            if (curTarget.hover)
                            {
                                curTarget.hoverWheels = curTarget.transform.GetComponentsInChildren <HoverWheel>();
                            }
                            else
                            {
                                curTarget.wheels = curTarget.transform.GetComponentsInChildren <Wheel>();
                            }
                        }
                    }
                }
                EditorGUI.indentLevel--;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(targetScript);
            }
        }
示例#22
0
        public override void OnInspectorGUI()
        {
            GUIStyle boldFoldout = new GUIStyle(EditorStyles.foldout);

            boldFoldout.fontStyle = FontStyle.Bold;
            Suspension targetScript = (Suspension)target;

            Suspension[] allTargets = new Suspension[targets.Length];
            isPrefab = PrefabUtility.GetPrefabType(targetScript) == PrefabType.Prefab;

            for (int i = 0; i < targets.Length; i++)
            {
                Undo.RecordObject(targets[i], "Suspension Change");
                allTargets[i] = targets[i] as Suspension;
            }

            if (!targetScript.wheel)
            {
                EditorGUILayout.HelpBox("Wheel must be assigned.", MessageType.Error);
            }

            DrawDefaultInspector();

            if (!isPrefab && targetScript.gameObject.activeInHierarchy)
            {
                showButtons = EditorGUILayout.Foldout(showButtons, "Quick Actions", boldFoldout);
                EditorGUI.indentLevel++;
                if (showButtons)
                {
                    if (GUILayout.Button("Get Wheel"))
                    {
                        foreach (Suspension curTarget in allTargets)
                        {
                            curTarget.wheel = curTarget.transform.GetComponentInChildren <Wheel>();
                        }
                    }

                    if (GUILayout.Button("Get Opposite Wheel"))
                    {
                        foreach (Suspension curTarget in allTargets)
                        {
                            VehicleParent vp         = (VehicleParent)F.GetTopmostParentComponent <VehicleParent>(curTarget.transform);
                            Suspension    closestOne = null;
                            float         closeDist  = Mathf.Infinity;

                            foreach (Wheel curWheel in vp.wheels)
                            {
                                float curDist = Vector2.Distance(new Vector2(curTarget.transform.localPosition.y, curTarget.transform.localPosition.z), new Vector2(curWheel.transform.parent.localPosition.y, curWheel.transform.parent.localPosition.z));
                                if (Mathf.Sign(curTarget.transform.localPosition.x) != Mathf.Sign(curWheel.transform.parent.localPosition.x) && curDist < closeDist)
                                {
                                    closeDist  = curDist;
                                    closestOne = curWheel.transform.parent.GetComponent <Suspension>();
                                }
                            }

                            curTarget.oppositeWheel = closestOne;
                        }
                    }
                }
                EditorGUI.indentLevel--;
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(targetScript);
            }
        }