GTA SA Vehicle Mechanic

Лучший способ помочь другим, поделиться своими находками.

GTA SA Vehicle Mechanic

Сообщение Skript47 13 авг 2015, 18:58



Код для автоматической работы с моделями авто из GTA SA, достаточно просто сохранить файл в FBX и добавить данный скрипт.
Сам по себе код может быть немного сырым, на Unity 4 особо не тестировался. Но если кто хочет - может использовать, может что полезное вырежет, собственно для школьников которые сотый раз уже GTA на Unity портируют...
Если у кого будут вопросы или замечания по поводу работы то без проблем могу ответить на них.

Синтаксис:
Используется csharp
using UnityEngine;
using System.Xml;
using System.IO;
using System.Collections;
using System.Collections.Generic;

public class Vehicle_Mechanic : MonoBehaviour
{
    public int Car_ID = 0;
    public string Car_Name;
    public float Wheel_Size = 1;
    public float Wheel_Angle_Max = 30;
    public int Health = 1000;
    public int LOD_Distance = 500;
    public Vector3[] View = new Vector3[3]
    {
        new Vector3 (0, -6, 1.5F),
        new Vector3 (0.4F, -0.75F, 0.45F),
        new Vector3 (0, 2.7F, 0.2F)
    } ;
    public AudioClip[] Engine_Sound = new AudioClip[10];
    public bool D_Wheel_Left_Front;
    public bool D_Wheel_Right_Front;
    public bool D_Wheel_Left_Rear;
    public bool D_Wheel_Right_Rear;
    public bool D_Bonnet;
    public bool D_Boot;
    public bool D_Bump_Front;
    public bool D_Bump_Rear;
    public bool D_Door_Left_Front;
    public bool D_Door_Right_Front;
    public bool D_Door_Left_Rear;
    public bool D_Door_Right_Rear;
    public bool D_Windscreen;
    public int S_Radio = 0;
    public int S_Radio_Max = 9;
    public int S_View = 0;
    public int S_Extra = 0;
    public int S_Spoiler = 0;
    public int S_Roof = 0;
    public int S_Nitro = 0;
    public int S_Paintjob = 0;
    public bool S_Bonnet;
    public bool S_Boot;
    public bool S_Door_Left_Front;
    public bool S_Door_Right_Front;
    public bool S_Door_Left_Rear;
    public bool S_Door_Right_Rear;
    public bool S_Engine;
    public bool S_Light;
    public bool S_Light_Left_Front;
    public bool S_Light_Right_Front;
    public bool S_Light_Left_Rear;
    public bool S_Light_Right_Rear;
    public int Wheel_Direction = 0;
    public float Wheel_Speed = 0;
    public Color Primary = new Vector4 (0.5F, 0.5F, 0.5F, 1);
    public Color Secondary = new Vector4 (0.5F, 0.5F, 0.5F, 1);
    public List<Material> Primary_Material = new List<Material> ();
    public List<Material> Secondary_Material = new List<Material> ();
    public Texture[] Paintjob = new Texture [10];
    public Transform[] Extra = new Transform[10];
    public Transform Chassis_Collision;
    public Transform Chassis;
    public Transform Chassis_vlo;
    public Transform Engine;
    public Transform Ug_Spoiler;
    public Transform Ug_Roof;
    public Transform Ug_Nitro;
    public Transform Headlights;
    public Transform Headlights_copy;
    public Transform Headlights2;
    public Transform Headlights2_copy;
    public Transform Taillights;
    public Transform Taillights_copy;
    public Transform Taillights2;
    public Transform Taillights2_copy;
    public Transform Ped_Frontseat_R;
    public Transform Ped_Frontseat_L;
    public Transform Ped_Backseat_R;
    public Transform Ped_Backseat_L;
    public Transform Exhaust;
    public Transform Wheel_LB_Dummy;
    public Transform Wheel_LF_Dummy;
    public Transform Wheel_RB_Dummy;
    public Transform Wheel_RF_Dummy;
    public Transform Bonnet_Dummy;
    public Transform Boot_Dummy;
    public Transform Bump_Front_Dummy;
    public Transform Bump_Rear_Dummy;
    public Transform Door_LF_Dummy;
    public Transform Door_RF_Dummy;
    public Transform Door_LR_Dummy;
    public Transform Door_RR_Dummy;
    public Transform Windscreen_Dummy;
    public Transform Radio_Dummy;
    public Transform Camera_Dummy;
    public Transform Horn_Dummy;
    public WheelCollider Wheel_C_LB;
    public WheelCollider Wheel_C_LF;
    public WheelCollider Wheel_C_RB;
    public WheelCollider Wheel_C_RF;
    public WheelFrictionCurve wfc;
    public WheelFrictionCurve wsc;

    void Start ()
    {
        Car_Name = gameObject.name;
        Car_ID = 0;

        if (gameObject.tag == "Player")
            S_Engine = true;

        S_Extra = Random.Range(0, 3);
        foreach (GameObject obj in Object.FindObjectsOfType(typeof(GameObject)))
        {
            if (obj.transform.root == this.transform)
            {
                if (obj.name == "chassis")
                {
                    Chassis = obj.transform;
                    Chassis.gameObject.SetActive (false);
                    Chassis_Collision = Instantiate (Chassis, Chassis.transform.position, Chassis.transform.rotation) as Transform;
                    Chassis_Collision.gameObject.SetActive (true);
                    Chassis_Collision.transform.parent = this.transform;
                    Chassis_Collision.name = "collision";
                    Chassis_Collision.GetComponent<MeshCollider> ().convex = true;
                    Chassis_Collision.gameObject.layer = 2;
                    Destroy (Chassis_Collision.GetComponent ("Renderer"));
                    Destroy (Chassis_Collision.GetComponent ("MeshFilter"));
                    Chassis.gameObject.SetActive (true);
                    foreach (Transform child in Chassis_Collision.transform)
                        GameObject.Destroy (child.gameObject);
                }
                if (obj.name == "chassis_vlo")
                    Chassis_vlo = obj.transform;
                if (obj.name == "ug_spoiler")
                    Ug_Spoiler = obj.transform;
                if (obj.name == "ug_roof")
                    Ug_Roof = obj.transform;
                if (obj.name == "ug_nitro")
                    Ug_Nitro = obj.transform;
                if (obj.name == "bonnet" + "_dummy")
                    Bonnet_Dummy = obj.transform;
                if (obj.name == "boot" + "_dummy")
                    Boot_Dummy = obj.transform;
                if (obj.name == "bump_front" + "_dummy")
                    Bump_Front_Dummy = obj.transform;
                if (obj.name == "bump_rear" + "_dummy")
                    Bump_Rear_Dummy = obj.transform;
                if (obj.name == "door_lf" + "_dummy")
                    Door_LF_Dummy = obj.transform;
                if (obj.name == "door_rf" + "_dummy")
                    Door_RF_Dummy = obj.transform;
                if (obj.name == "door_lr" + "_dummy")
                    Door_LR_Dummy = obj.transform;
                if (obj.name == "door_rr" + "_dummy")
                    Door_RR_Dummy = obj.transform;
                if (obj.name == "windscreen" + "_dummy")
                    Windscreen_Dummy = obj.transform;
                if (obj.name == "wheel_lb" + "_dummy")
                    Wheel_LB_Dummy = obj.transform;
                if (obj.name == "wheel_lf" + "_dummy")
                    Wheel_LF_Dummy = obj.transform;
                if (obj.name == "wheel_rb" + "_dummy")
                    Wheel_RB_Dummy = obj.transform;
                if (obj.name == "wheel_rf" + "_dummy")
                    Wheel_RF_Dummy = obj.transform;
                if (obj.name == "engine")
                {
                    Engine = obj.transform;
                    Engine.gameObject.AddComponent<AudioSource> ();
                    Engine.audio.loop = true;
                }
                if (obj.name == "exhaust")
                    Exhaust = obj.transform;
                if (obj.name == "ped_frontseat")
                    Ped_Frontseat_R = obj.transform;
                if (obj.name == "ped_backseat")
                    Ped_Backseat_R = obj.transform;
                if (obj.name == "headlights")
                    Headlights = obj.transform;
                if (obj.name == "headlights2")
                    Headlights2 = obj.transform;
                if (obj.name == "taillights")
                    Taillights = obj.transform;
                if (obj.name == "taillights2")
                    Taillights2 = obj.transform;
                if (obj.name == "plate_rear_ok" | obj.name == "plate_rear_dam" | obj.name == "plate_rear")
                    obj.GetComponent<MeshCollider> ().enabled = false;
                for (int i = 0; i < Extra.Length; ++i)
                    if (obj.name == "extra" + i.ToString ())
                        Extra[i] = obj.transform;
            }
        }
        if (Ug_Spoiler & Resources.Load ("Tuning_Spoilers"))
        {
            Ug_Spoiler.transform.localRotation = Quaternion.identity;
            Transform Spoiler = (Instantiate (Resources.Load ("Tuning_Spoilers"), Ug_Spoiler.transform.position, Ug_Spoiler.transform.rotation) as GameObject).transform;
            Spoiler.transform.parent = Ug_Spoiler.transform;
            Spoiler.name = "Spoiler";
            ResetTransform (Spoiler.transform);
            int Parts = Spoiler.transform.childCount;
            for (int i = 0; i < Parts; ++i)
            {
                ResetTransform (Spoiler.GetChild(0));
                Spoiler.GetChild(0).name = "spoiler";
                foreach (Transform child in Spoiler.GetChild(0).transform)
                    ResetTransform (child);
                Spoiler.GetChild(0).transform.parent = Ug_Spoiler.transform;
            }
            Destroy(Spoiler.gameObject);
        }
        if (Ug_Roof & Resources.Load ("Tuning_Roofs"))
        {
            Transform Roof = Instantiate (Resources.Load ("Tuning_Roofs"), Ug_Roof.transform.position, Ug_Roof.transform.rotation) as Transform;
            Roof.transform.parent = Ug_Roof.transform;
            Roof.name = "Roof";
            ResetTransform (Roof.transform);
        }
        if (Exhaust & Resources.Load ("Exhaust_particle"))
        {
            Transform Exhaust_particle = (Instantiate (Resources.Load ("Exhaust_particle"), Exhaust.transform.position, Exhaust.transform.rotation) as GameObject).transform;
            Exhaust_particle.transform.parent = Exhaust.transform;
            Exhaust_particle.name = "Exhaust_particle";
        }
        if (Ped_Frontseat_R)
        {
            View[1] = Vector3.Scale(Ped_Frontseat_R.transform.localPosition, new Vector3(-1, 1, 1)) + new Vector3(0, -0.3F, +0.7F);
            Ped_Frontseat_L = Instantiate (Ped_Frontseat_R, Vector3.zero, Quaternion.identity) as Transform;
            Ped_Frontseat_L.transform.parent = this.transform;
            Ped_Frontseat_L.transform.localPosition = Vector3.Scale(Ped_Frontseat_R.transform.localPosition, new Vector3(-1, 1, 1));
            Ped_Frontseat_L.transform.localRotation = Ped_Frontseat_R.transform.localRotation;
            Ped_Frontseat_R.name = "ped_frontseat_r";
            Ped_Frontseat_L.name = "ped_frontseat_l";
        }
        if (Ped_Backseat_R)
        {
            Ped_Backseat_L = Instantiate (Ped_Backseat_R, Vector3.zero, Quaternion.identity) as Transform;
            Ped_Backseat_L.transform.parent = this.transform;
            Ped_Backseat_L.transform.localPosition = Vector3.Scale(Ped_Backseat_R.transform.localPosition, new Vector3(-1, 1, 1));
            Ped_Backseat_L.transform.localRotation = Ped_Backseat_R.transform.localRotation;
            Ped_Backseat_R.name = "ped_backseat_r";
            Ped_Backseat_L.name = "ped_backseat_l";
        }
        if (Headlights)
        {
            Headlights_copy = Instantiate (Headlights, Vector3.zero, Quaternion.identity) as Transform;
            Headlights_copy.transform.parent = this.transform;
            Headlights_copy.transform.localPosition = Vector3.Scale(Headlights.transform.localPosition, new Vector3(-1, 1, 1));
            Headlights_copy.transform.localRotation = Headlights.transform.localRotation;
            Headlights_copy.name = "headlights";
            if (Resources.Load ("Headlights_particle"))
            {
                Transform Headlights_particle = (Instantiate (Resources.Load ("Headlights_particle"), Headlights.transform.position, Headlights.transform.rotation) as GameObject).transform;
                Headlights_particle.transform.parent = Headlights;
                Headlights_particle.name = "headlights_particle";
                Transform Headlights_particle_2 = (Instantiate (Resources.Load ("Headlights_particle"), Headlights_copy.transform.position, Headlights_copy.transform.rotation) as GameObject).transform;
                Headlights_particle_2.transform.parent = Headlights_copy;
                Headlights_particle_2.name = "headlights_particle";
            }
        }
        if (Headlights2)
        {
            Headlights2_copy = Instantiate (Headlights2, Vector3.zero, Quaternion.identity) as Transform;
            Headlights2_copy.transform.parent = this.transform;
            Headlights2_copy.transform.localPosition = Vector3.Scale(Headlights2.transform.localPosition, new Vector3(-1, 1, 1));
            Headlights2_copy.transform.localRotation = Headlights2.transform.localRotation;
            Headlights2_copy.name = "headlights2";
            if (Resources.Load ("Headlights2_particle"))
            {
                Transform Headlights2_particle = (Instantiate (Resources.Load ("Headlights2_particle"), Headlights2.transform.position, Headlights2.transform.rotation) as GameObject).transform;
                Headlights2_particle.transform.parent = Headlights2;
                Headlights2_particle.name = "headlights2_particle";
                Transform Headlights2_particle_2 = (Instantiate (Resources.Load ("Headlights2_particle"), Headlights2_copy.transform.position, Headlights2_copy.transform.rotation) as GameObject).transform;
                Headlights2_particle_2.transform.parent = Headlights2_copy;
                Headlights2_particle_2.name = "headlights2_particle";
            }
        }
        if (Taillights)
        {
            Taillights_copy = Instantiate (Taillights, Vector3.zero, Quaternion.identity) as Transform;
            Taillights_copy.transform.parent = this.transform;
            Taillights_copy.transform.localPosition = Vector3.Scale(Taillights.transform.localPosition, new Vector3(-1, 1, 1));
            Taillights_copy.transform.localRotation = Taillights.transform.localRotation;
            Taillights_copy.name = "taillights";
            if (Resources.Load ("Taillights_particle"))
            {
                Transform Taillights_particle = (Instantiate (Resources.Load ("Taillights_particle"), Taillights.transform.position, Taillights.transform.rotation) as GameObject).transform;
                Taillights_particle.transform.parent = Taillights.transform;
                Taillights_particle.name = "taillights_particle";
                Transform Taillights_particle_2 = (Instantiate (Resources.Load ("Taillights_particle"), Taillights_copy.transform.position, Taillights_copy.transform.rotation) as GameObject).transform;
                Taillights_particle_2.transform.parent = Taillights_copy.transform;
                Taillights_particle_2.name = "taillights_particle";
            }
        }
        if (Taillights2)
        {
            Taillights2_copy = Instantiate (Taillights2, Vector3.zero, Quaternion.identity) as Transform;
            Taillights2_copy.transform.parent = this.transform;
            Taillights2_copy.transform.localPosition = Vector3.Scale(Taillights2.transform.localPosition, new Vector3(-1, 1, 1));
            Taillights2_copy.transform.localRotation = Taillights2.transform.localRotation;
            Taillights2_copy.name = "taillights2";
            if (Resources.Load ("Taillights2_particle"))
            {
                Transform Taillights2_particle = (Instantiate (Resources.Load ("Taillights2_particle"), Taillights2.transform.position, Taillights2.transform.rotation) as GameObject).transform;
                Taillights2_particle.transform.parent = Taillights2.transform;
                Taillights2_particle.name = "taillights2_particle";
                Transform Taillights2_particle_2 = (Instantiate (Resources.Load ("Taillights2_particle"), Taillights2_copy.transform.position, Taillights2_copy.transform.rotation) as GameObject).transform;
                Taillights2_particle_2.transform.parent = Taillights2_copy.transform;
                Taillights2_particle_2.name = "taillights2_particle";
            }
        }

        Radio_Dummy = new GameObject ("radio_dummy").transform;
        for (int i = 0; i != S_Radio_Max; i++)
        {
            GameObject S = new GameObject (i.ToString ());
            AudioSource component;
            component = S.gameObject.AddComponent<AudioSource> ();
            component.loop = true;
            S.gameObject.audio.clip = Resources.Load ("radio_" + i.ToString (), typeof(AudioClip)) as AudioClip;
            S.gameObject.audio.Play ();
            S.transform.parent = Radio_Dummy.transform;
        }
        Radio_Dummy.transform.parent = this.transform;
        ResetTransform (Radio_Dummy);

        Camera_Dummy = new GameObject ("camera_dummy").transform;
        Camera_Dummy.transform.parent = this.transform;
        ResetTransform (Camera_Dummy);

        Horn_Dummy = new GameObject ("horn_dummy").transform;
        Horn_Dummy.transform.parent = this.transform;
        Horn_Dummy.gameObject.AddComponent<AudioSource> ();
        ResetTransform (Horn_Dummy);

        if (!Engine_Sound [0])
            Engine_Sound [0] = Resources.Load ("horn", typeof(AudioClip)) as AudioClip;

        if (!gameObject.GetComponent<Rigidbody> ())
            gameObject.AddComponent<Rigidbody> ();
        rigidbody.mass = 1400;
        rigidbody.angularDrag = 1;
        rigidbody.centerOfMass = new Vector3 (0, 0, 0);

        if (Wheel_LB_Dummy & Wheel_LF_Dummy & Wheel_RB_Dummy & Wheel_RF_Dummy)
        {
            GameObject Wheel_LB_Dummy_2 = new GameObject ("wheel_lb" + "_collider");
            GameObject Wheel_LF_Dummy_2 = new GameObject ("wheel_lf" + "_collider");
            GameObject Wheel_RB_Dummy_2 = new GameObject ("wheel_rb" + "_collider");
            GameObject Wheel_RF_Dummy_2 = new GameObject ("wheel_rf" + "_collider");
            Wheel_LB_Dummy_2.transform.parent = this.transform;
            Wheel_LF_Dummy_2.transform.parent = this.transform;
            Wheel_RB_Dummy_2.transform.parent = this.transform;
            Wheel_RF_Dummy_2.transform.parent = this.transform;
            Wheel_LB_Dummy_2.transform.localScale = Vector3.one;
            Wheel_LF_Dummy_2.transform.localScale = Vector3.one;
            Wheel_RB_Dummy_2.transform.localScale = Vector3.one;
            Wheel_RF_Dummy_2.transform.localScale = Vector3.one;
            Wheel_LB_Dummy_2.transform.localPosition = Wheel_LB_Dummy.transform.localPosition;
            Wheel_LF_Dummy_2.transform.localPosition = Wheel_LF_Dummy.transform.localPosition;
            Wheel_RB_Dummy_2.transform.localPosition = Wheel_RB_Dummy.transform.localPosition;
            Wheel_RF_Dummy_2.transform.localPosition = Wheel_RF_Dummy.transform.localPosition;
            Wheel_C_LB = Wheel_LB_Dummy_2.AddComponent<WheelCollider> ();
            Wheel_C_LF = Wheel_LF_Dummy_2.AddComponent<WheelCollider> ();
            Wheel_C_RB = Wheel_RB_Dummy_2.AddComponent<WheelCollider> ();
            Wheel_C_RF = Wheel_RF_Dummy_2.AddComponent<WheelCollider> ();
            Wheel_C_LB.radius = Wheel_Size * 0.35F;
            Wheel_C_LF.radius = Wheel_Size * 0.35F;
            Wheel_C_RB.radius = Wheel_Size * 0.35F;
            Wheel_C_RF.radius = Wheel_Size * 0.35F;
            SetupWheelFrictionCurveF (1, 250, 2, 125, 1);
            SetupWheelFrictionCurveS (1, 250, 2, 125, 1);
            Wheel_C_LB.forwardFriction = wfc;
            Wheel_C_LF.forwardFriction = wfc;
            Wheel_C_RB.forwardFriction = wfc;
            Wheel_C_RF.forwardFriction = wfc;
            Wheel_C_LB.sidewaysFriction = wsc;
            Wheel_C_LF.sidewaysFriction = wsc;
            Wheel_C_RB.sidewaysFriction = wsc;
            Wheel_C_RF.sidewaysFriction = wsc;
            if (Wheel_RF_Dummy.transform.childCount != 0)
            {
                Transform wheel_lb = Instantiate (Wheel_RF_Dummy.transform.GetChild (0), Wheel_LB_Dummy.transform.position, Wheel_LB_Dummy.transform.rotation) as Transform;
                wheel_lb.transform.parent = Wheel_LB_Dummy.transform;
                wheel_lb.name = "wheel";
                wheel_lb.transform.localRotation = Quaternion.Euler (0, 0, 180);
                Transform wheel_lf = Instantiate (Wheel_RF_Dummy.transform.GetChild (0), Wheel_LF_Dummy.transform.position, Wheel_LF_Dummy.transform.rotation) as Transform;
                wheel_lf.transform.parent = Wheel_LF_Dummy.transform;
                wheel_lf.name = "wheel";
                wheel_lf.transform.localRotation = Quaternion.Euler (0, 0, 180);
                Transform wheel_rb = Instantiate (Wheel_RF_Dummy.transform.GetChild (0), Wheel_RB_Dummy.transform.position, Wheel_RB_Dummy.transform.rotation) as Transform;
                wheel_rb.transform.parent = Wheel_RB_Dummy.transform;
                wheel_rb.name = "wheel";
                wheel_rb.transform.localRotation = Quaternion.Euler (0, 0, 0);
            }
        }

        Renderer[] allChildren = GetComponentsInChildren<Renderer> ();
        foreach (Renderer child in allChildren)
        {
            for (int i = 0; i < child.materials.Length; i++)
            {
                if (child.materials [i].HasProperty("_Color"))
                    if (child.materials [i].name == "Primary (Instance)" | child.materials [i].color == new Color32(60, 255, 0, 255))
                        Primary_Material.Add (child.materials [i]);
                if (child.materials [i].HasProperty("_Color"))
                    if (child.materials [i].name == "Secondary (Instance)" | child.materials [i].color == new Color32(255, 0, 175, 255))
                        Secondary_Material.Add (child.materials [i]);
            }
        }
        if (Primary_Material.Count > 0)
        {
            Paintjob [0] = Primary_Material[0].GetTexture ("_MainTex") as Texture;
            for (int i = 0; i < Paintjob.Length; i++)
                Paintjob [i] = Resources.Load (Car_Name + i.ToString (), typeof(Texture)) as Texture;
        }
    }

    void Update ()
    {
        CarColor (Primary, Secondary);
        if (gameObject.tag == "Player")
            CarControl ();
        if (Engine)
            Engine.gameObject.audio.volume = Mathf.MoveTowards (Engine.gameObject.audio.volume, S_Engine ? 1 : 0, Time.deltaTime);

        S_Paintjob = Mathf.Clamp(S_Paintjob, 0, Paintjob.Length - 1);
        S_Extra = Mathf.Clamp(S_Extra, 0, Extra.Length - 1);
        S_View = Mathf.Clamp(S_View, 0, View.Length - 1);
        S_Spoiler = Mathf.Clamp(S_Spoiler, 0, 25);
        S_Roof = Mathf.Clamp(S_Roof, 0, 25);
        S_Nitro = Mathf.Clamp(S_Nitro, 0, 5);
        for (int i = 0; i < Primary_Material.Count; i++)
            Primary_Material[i].SetTexture("_MainTex", Paintjob [S_Paintjob] ? Paintjob [S_Paintjob] : Paintjob [0]);
        for (int i = 0; i < Extra.Length; ++i)
            if (Extra[i])
                Extra[i].gameObject.SetActive (i == S_Extra);
        if (Radio_Dummy)
            for (int i = 0; i < Radio_Dummy.transform.childCount; i++)
                Radio_Dummy.transform.GetChild (i).gameObject.audio.volume = (i == S_Radio ? 1 : 0);
        if (Ug_Spoiler)
            for (int i = 0; i < Ug_Spoiler.transform.childCount; i++)
                Ug_Spoiler.transform.GetChild (i).gameObject.SetActive (i == S_Spoiler - 1);
        if (Ug_Roof)
            for (int i = 0; i < Ug_Roof.transform.childCount; i++)
                Ug_Roof.transform.GetChild (i).gameObject.SetActive (i == S_Roof - 1);
        if (Ug_Nitro)
            for (int i = 0; i < Ug_Nitro.transform.childCount; i++)
                Ug_Nitro.transform.GetChild (i).gameObject.SetActive (i == S_Nitro - 1);
        if (Chassis_vlo)
        {
            bool LOD = Vector3.Distance (Chassis_vlo.transform.position, Camera.main.transform.position) > LOD_Distance;
            Chassis_vlo.gameObject.SetActive (LOD);
            Chassis.gameObject.SetActive (!LOD);
        }
        S_Light_Left_Front = !D_Bump_Front;
        S_Light_Right_Front = !D_Bump_Front;
        S_Light_Left_Rear = !D_Bump_Rear;
        S_Light_Right_Rear = !D_Bump_Rear;
        if (!S_Light)
        {
            S_Light_Left_Front = false;
            S_Light_Right_Front = false;
            S_Light_Left_Rear = false;
            S_Light_Right_Rear = false;
        }
        if (Headlights)
            Headlights.gameObject.SetActive (S_Light_Left_Front);
        if (Headlights_copy)
            Headlights_copy.gameObject.SetActive (S_Light_Left_Front);
        if (Headlights2)
            Headlights2.gameObject.SetActive (S_Light_Right_Front);
        if (Headlights2_copy)
            Headlights2_copy.gameObject.SetActive (S_Light_Right_Front);
        if (Taillights)
            Taillights.gameObject.SetActive (S_Light_Left_Rear);
        if (Taillights_copy)
            Taillights_copy.gameObject.SetActive (S_Light_Left_Rear);
        if (Taillights2)
            Taillights2.gameObject.SetActive (S_Light_Right_Rear);
        if (Taillights2_copy)
            Taillights2_copy.gameObject.SetActive (S_Light_Right_Rear);

        if (Wheel_LF_Dummy)
        {
            if (Wheel_LF_Dummy.transform.childCount > 0)
            {
                Wheel_LF_Dummy.transform.localRotation = Quaternion.Lerp (Wheel_LF_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, Wheel_Direction * Wheel_Angle_Max)), Time.deltaTime * 3);
                Wheel_C_LF.steerAngle = Wheel_LF_Dummy.transform.localRotation.eulerAngles.z;
                Wheel_LF_Dummy.transform.GetChild (0).Rotate (Vector3.right * Time.deltaTime * Wheel_Speed);
            }
        }
        if (Wheel_RF_Dummy)
        {
            if (Wheel_RF_Dummy.transform.childCount > 0)
            {
                Wheel_RF_Dummy.transform.localRotation = Quaternion.Lerp (Wheel_RF_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, Wheel_Direction * Wheel_Angle_Max)), Time.deltaTime * 3);
                Wheel_C_RF.steerAngle = Wheel_RF_Dummy.transform.localRotation.eulerAngles.z;
                Wheel_RF_Dummy.transform.GetChild (0).Rotate (Vector3.left * Time.deltaTime * Wheel_Speed);
            }
        }
        if (Wheel_LB_Dummy)
        {
            if (Wheel_LB_Dummy.transform.childCount > 0)
                Wheel_LB_Dummy.transform.GetChild (0).Rotate (Vector3.right * Time.deltaTime * Wheel_Speed);
        }
        if (Wheel_RB_Dummy)
        {
            if (Wheel_RB_Dummy.transform.childCount > 0)
                Wheel_RB_Dummy.transform.GetChild (0).Rotate (Vector3.left * Time.deltaTime * Wheel_Speed);
        }
        if (Bonnet_Dummy)
        {
            Bonnet_Dummy.transform.localRotation = Quaternion.Lerp (Bonnet_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 ((S_Bonnet ? 1 : 0) * 55, 0, 0)), Time.deltaTime * 3);
            Bonnet_Dummy.transform.GetChild (0).gameObject.SetActive (D_Bonnet);
            Bonnet_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Bonnet);
        }
        if (Boot_Dummy)
        {
            Boot_Dummy.transform.localRotation = Quaternion.Lerp (Boot_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 ((S_Boot ? 1 : 0) * - 55, 0, 0)), Time.deltaTime * 3);
            Boot_Dummy.transform.GetChild (0).gameObject.SetActive (D_Boot);
            Boot_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Boot);
        }
        if (Bump_Front_Dummy)
        {
            Bump_Front_Dummy.transform.GetChild (0).gameObject.SetActive (D_Bump_Front);
            Bump_Front_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Bump_Front);
        }
        if (Bump_Rear_Dummy)
        {
            Bump_Rear_Dummy.transform.GetChild (0).gameObject.SetActive (D_Bump_Rear);
            Bump_Rear_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Bump_Rear);
        }
        if (Door_LF_Dummy)
        {
            Door_LF_Dummy.transform.localRotation = Quaternion.Lerp (Door_LF_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, (S_Door_Left_Front ? 1 : 0) * 55)), Time.deltaTime * 3);
            Door_LF_Dummy.transform.GetChild (0).gameObject.SetActive (D_Door_Left_Front);
            Door_LF_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Door_Left_Front);
        }
        if (Door_RF_Dummy)
        {
            Door_RF_Dummy.transform.localRotation = Quaternion.Lerp (Door_RF_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, (S_Door_Right_Front ? 1 : 0) * -55)), Time.deltaTime * 3);
            Door_RF_Dummy.transform.GetChild (0).gameObject.SetActive (D_Door_Right_Front);
            Door_RF_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Door_Right_Front);
        }
        if (Door_LR_Dummy)
        {
            Door_LR_Dummy.transform.localRotation = Quaternion.Lerp (Door_LR_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, (S_Door_Left_Rear ? 1 : 0) * -55)), Time.deltaTime * 3);
            Door_LR_Dummy.transform.GetChild (0).gameObject.SetActive (D_Door_Left_Rear);
            Door_LR_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Door_Left_Rear);
        }
        if (Door_RR_Dummy)
        {
            Door_RR_Dummy.transform.localRotation = Quaternion.Lerp (Door_RR_Dummy.transform.localRotation, Quaternion.Euler (new Vector3 (0, 0, (S_Door_Right_Rear ? 1 : 0) * -55)), Time.deltaTime * 3);
            Door_RR_Dummy.transform.GetChild (0).gameObject.SetActive (D_Door_Right_Rear);
            Door_RR_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Door_Right_Rear);
        }
        if (Windscreen_Dummy)
        {
            Windscreen_Dummy.transform.GetChild (0).gameObject.SetActive (D_Windscreen);
            Windscreen_Dummy.transform.GetChild (1).gameObject.SetActive (!D_Windscreen);
        }
    }

    void CarColor (Color Primary, Color Secondary)
    {
        for (int i = 0; i < Primary_Material.Count; i++)
            if (Primary_Material [i])
                Primary_Material [i].SetColor ("_Color", S_Paintjob == 0 ? Primary : Color.white);
        for (int i = 0; i < Secondary_Material.Count; i++)
            if (Secondary_Material [i])
                Secondary_Material [i].SetColor ("_Color", S_Paintjob == 0 ? Secondary : Color.white);
    }

    void CarControl ()
    {
        CarCamera ();
        if (Input.GetKeyDown (KeyCode.R))
        {
            Primary = new Color (Random.value, Random.value, Random.value);
            Secondary = new Color (Random.value, Random.value, Random.value);
        }
        if (Input.GetKeyDown (KeyCode.KeypadPlus))
            S_Paintjob++;
        if (Input.GetKeyDown (KeyCode.KeypadMinus))
            S_Paintjob--;
        if (Input.GetKeyDown (KeyCode.L))
            S_Light = !S_Light;
        if (Input.GetKeyDown (KeyCode.B))
            S_Engine = !S_Engine;
        if (Input.GetKeyDown (KeyCode.H))
        {
            if (!Horn_Dummy.audio.isPlaying)
                if (Engine_Sound [0])
                {
                    Horn_Dummy.audio.clip = Engine_Sound [0];
                    Horn_Dummy.audio.Play();
                }
        }
        if (Input.GetKeyDown (KeyCode.V))
        {
            S_View = S_View < View.Length - 1 ? S_View + 1 : 0;
            if (S_View < 0)
                S_View = 0;
            Camera.main.transform.parent = null;
        }
        S_Radio += (int)(Mathf.CeilToInt (Mathf.Abs (Input.GetAxis ("Mouse ScrollWheel"))) * Mathf.Sign (Input.GetAxis ("Mouse ScrollWheel")));
        S_Radio = Mathf.Clamp (S_Radio, 0, S_Radio_Max);
        if (Input.GetKeyDown (KeyCode.O))
        {
            S_Bonnet = true;
            S_Boot = true;
            S_Door_Left_Front = true;
            S_Door_Right_Front = true;
            S_Door_Left_Rear = true;
            S_Door_Right_Rear = true;
        }
        if (Input.GetKeyDown (KeyCode.P))
        {
            S_Bonnet = false;
            S_Boot = false;
            S_Door_Left_Front = false;
            S_Door_Right_Front = false;
            S_Door_Left_Rear = false;
            S_Door_Right_Rear = false;
        }
        if (Input.GetKeyDown (KeyCode.N))
        {
            D_Bonnet = true;
            D_Boot = true;
            D_Bump_Front = true;
            D_Bump_Rear = true;
            D_Door_Left_Front = true;
            D_Door_Right_Front = true;
            D_Door_Left_Rear = true;
            D_Door_Right_Rear = true;
            D_Windscreen = true;
        }
        if (Input.GetKeyDown (KeyCode.M))
        {
            D_Bonnet = false;
            D_Boot = false;
            D_Bump_Front = false;
            D_Bump_Rear = false;
            D_Door_Left_Front = false;
            D_Door_Right_Front = false;
            D_Door_Left_Rear = false;
            D_Door_Right_Rear = false;
            D_Windscreen = false;
        }
    }

    void CarCamera ()
    {
        if (Camera.main.transform.parent != Camera_Dummy.transform)
        {
            Camera.main.transform.parent = Camera_Dummy.transform;
            Camera.main.transform.localPosition = View [S_View];
            Camera.main.transform.localScale = new Vector3 (1, 1, 1);
            Camera.main.transform.localRotation = Quaternion.Euler (-90, 180, 0);
        }
        if (S_View == 0)
            Camera_Dummy.transform.Rotate (new Vector3 (0, 0, Input.GetAxis ("Mouse X") * 100) * Time.deltaTime, Space.Self);
        else
            Camera_Dummy.transform.localRotation = Quaternion.Euler (0, 0, 0);

        Camera.main.fieldOfView = Mathf.Lerp (Camera.main.fieldOfView, Mathf.Clamp (60 + rigidbody.velocity.magnitude * 0.5F, 50, 70), Time.deltaTime * 10);
        Camera.main.transform.localRotation = Quaternion.Lerp (Camera.main.transform.localRotation, Quaternion.Euler (-90, 180 + Input.GetAxisRaw ("Horizontal") * -2, 0), Time.deltaTime * 1);
    }

    void SetupWheelFrictionCurveF (int extremumSlip, int extremumValue, int asymptoteSlip, int asymptoteValue, int stiffness)
    {
        wfc = new WheelFrictionCurve ();
        wfc.extremumSlip = extremumSlip;
        wfc.extremumValue = extremumValue;
        wfc.asymptoteSlip = asymptoteSlip;
        wfc.asymptoteValue = asymptoteValue;
        wfc.stiffness = stiffness;
    }

    void SetupWheelFrictionCurveS (int extremumSlip, int extremumValue, int asymptoteSlip, int asymptoteValue, int stiffness)
    {
        wsc = new WheelFrictionCurve ();
        wsc.extremumSlip = extremumSlip;
        wsc.extremumValue = extremumValue;
        wsc.asymptoteSlip = asymptoteSlip;
        wsc.asymptoteValue = asymptoteValue;
        wsc.stiffness = stiffness;
    }

    void ResetTransform (Transform O)
    {
        O.transform.localPosition = Vector3.zero;
        O.transform.localScale = Vector3.one;
        O.transform.localRotation = Quaternion.identity;
    }
}


Ссылка на весь проект: https://yadi.sk/d/q1F5QOyOiPMw4
Аватара пользователя
Skript47
UNIт
 
Сообщения: 51
Зарегистрирован: 03 фев 2013, 12:41

Re: GTA SA Vehicle Mechanic

Сообщение beatsspam 08 мар 2016, 20:29

Интересный скрипт, но не могу понять о каком FBX идет речь, ведь машина в са хранятся в форматах DFF, TXD
beatsspam
UNец
 
Сообщения: 3
Зарегистрирован: 08 мар 2016, 20:27

Re: GTA SA Vehicle Mechanic

Сообщение Cr0c 08 мар 2016, 21:02

beatsspam писал(а):Интересный скрипт, но не могу понять о каком FBX идет речь, ведь машина в са хранятся в форматах DFF, TXD

Видимо, конвертировать надо, чтобы юнити приняла.
Аватара пользователя
Cr0c
Адепт
 
Сообщения: 3035
Зарегистрирован: 19 июн 2015, 13:50
Skype: cr0c81

Re: GTA SA Vehicle Mechanic

Сообщение beatsspam 08 мар 2016, 21:55

узнать бы еще чем :-?
beatsspam
UNец
 
Сообщения: 3
Зарегистрирован: 08 мар 2016, 20:27

Re: GTA SA Vehicle Mechanic

Сообщение Cr0c 08 мар 2016, 23:11

ВОТ ТАК, может быть.
Аватара пользователя
Cr0c
Адепт
 
Сообщения: 3035
Зарегистрирован: 19 июн 2015, 13:50
Skype: cr0c81

Re: GTA SA Vehicle Mechanic

Сообщение beatsspam 13 мар 2016, 09:27

ты бы хоть комментарии почитал к тому видео прежде чем давать ссылку. Нет тем не менее там нет конвертации машин
beatsspam
UNец
 
Сообщения: 3
Зарегистрирован: 08 мар 2016, 20:27


Вернуться в Исходники (Копилка)

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 2