Exemple #1
0
        static void Main(string[] args)
        {
            var carsControler = new CarControler();

            carsControler.Create(null);
            carsControler.Creats(null);
        }
Exemple #2
0
    //PhysicsControler phyControler;

    void Start()
    {
        r = GetComponent <References>();
        if (r != null)
        {
            LeftBtn       = r.Object[0];
            RightBtn      = r.Object[1];
            DriftBtn      = r.Object[3];
            AccelerateBtn = r.Object[4];
            if (LeftBtn != null)
            {
                EventTriggerListener LeftTrigger = LeftBtn.AddComponent <EventTriggerListener>();
                LeftTrigger.onDown = AdjustOnPointerDownCallBack;
                LeftTrigger.onUp   = AdjustOnPointerUpCallBack;
            }
            if (RightBtn != null)
            {
                EventTriggerListener RightTrigger = RightBtn.AddComponent <EventTriggerListener>();
                RightTrigger.onDown = AdjustOnPointerDownCallBack;
                RightTrigger.onUp   = AdjustOnPointerUpCallBack;
            }
            if (DriftBtn != null)
            {
                EventTriggerListener DriftTrigger = DriftBtn.AddComponent <EventTriggerListener>();
                DriftTrigger.onDown = DriftCarBtnDown;
                DriftTrigger.onUp   = DriftCarBtnUp;
            }
            if (AccelerateBtn != null)
            {
                EventTriggerListener AccerateTrigger = AccelerateBtn.AddComponent <EventTriggerListener>();
                AccerateTrigger.onDown = AccelerateBtnDown;
            }
            carControler = r.Object[2].GetComponent <CarControler>();
            //phyControler = r.Object[2].GetComponent<PhysicsControler>();
        }
    }
Exemple #3
0
    /// <summary>
    /// Create car prefab with the current car maker settings
    /// </summary>
    /// <returns></returns>
    private GameObject MakeCar()
    {
        ///get save path
        var path = EditorUtility.SaveFilePanelInProject(
            "Select new car location",
            "New Car",
            "prefab",
            "message");

        GameObject newCar = null;


        ///if car is null
        if (carObject == null)
        {
            Debug.LogError("Please Assign Car GameObject!");
        }
        else
        {
            ///init car maker Prefab GameObject
            newCar = new GameObject();
            newCar.transform.position = Vector3.zero;

            ///add rigidbody to root
            Rigidbody rb = newCar.AddComponent <Rigidbody>();
            rb.interpolation = RigidbodyInterpolation.Interpolate;

            ///calculate body mesh rotation
            Quaternion meshRot = Quaternion.Euler(Vector3.zero);
            meshRot = Quaternion.Euler(0, meshRotationY, 0);


            ///add car container
            GameObject carContainer = GameObject.Instantiate(carObject, Vector3.zero, meshRot, newCar.transform) as GameObject;

            ///get car body mesh
            GameObject carMesh = GetChildByName(carContainer, carBodyMesh.name);

            ///add collider to car body mesh
            Collider collider = carMesh.GetComponent <Collider>();
            if (collider != null)
            {
                MeshCollider meshCollider = carMesh.GetComponent <MeshCollider>();
                if (meshCollider != null)
                {
                    meshCollider.convex = true;
                }
            }
            else
            {
                carMesh.AddComponent <MeshCollider>().convex = true;
            }



            ///create container for wheels
            GameObject wheelsContainer = new GameObject();
            wheelsContainer.name                    = "wheelsContainer";
            wheelsContainer.transform.parent        = newCar.transform;
            wheelsContainer.transform.localPosition = Vector3.zero;
            wheelsContainer.transform.localRotation = meshRot;

            ///create wheels
            WheelCollider wheelColliderFrontLeft  = AddWheelCollider(wheelsContainer, wheelFrontLeft, "Front Left", true);
            WheelCollider wheelColliderFrontRight = AddWheelCollider(wheelsContainer, wheelFrontRight, "Front Right", true);
            WheelCollider wheelColliderBackLeft   = AddWheelCollider(wheelsContainer, wheelBackLeft, "Back Left", false);
            WheelCollider wheelColliderBackRight  = AddWheelCollider(wheelsContainer, wheelBackRight, "Back Right", false);


            ///Create the new car Prefab.
            GameObject newPrefab = PrefabUtility.SaveAsPrefabAssetAndConnect(newCar, path, InteractionMode.UserAction);

            ///set car root name
            newCar.name = newPrefab.name;

            ///add car CarControler
            CarControler carController = newCar.AddComponent <CarControler>();

            ///asign car settings
            carController.carSettings = carSettings;

            ///init axleInfos List
            carController.wheelAxleList = new List <WheelAxle>();

            ///create Front Wheels
            WheelAxle axelInfoFront = new WheelAxle();
            axelInfoFront.wheelColliderRight = wheelColliderFrontRight;
            axelInfoFront.wheelColliderLeft  = wheelColliderFrontLeft;
            axelInfoFront.wheelMeshLeft      = GetChildByName(carContainer, wheelFrontLeft.name);
            axelInfoFront.wheelMeshRight     = GetChildByName(carContainer, wheelFrontRight.name);
            axelInfoFront.motor    = true;
            axelInfoFront.steering = true;
            carController.wheelAxleList.Add(axelInfoFront);

            ///create Back Wheels
            WheelAxle axelInfoBack = new WheelAxle();
            axelInfoBack.wheelColliderRight = wheelColliderBackRight;
            axelInfoBack.wheelColliderLeft  = wheelColliderBackLeft;
            axelInfoBack.wheelMeshLeft      = GetChildByName(carContainer, wheelBackLeft.name);
            axelInfoBack.wheelMeshRight     = GetChildByName(carContainer, wheelBackRight.name);
            axelInfoBack.motor    = false;
            axelInfoBack.steering = false;
            carController.wheelAxleList.Add(axelInfoBack);
        }


        return(newCar);
    }