void Add_DrivingComponents(GameObject gameObject, string direction)
        {
            // Rigidbody
            Rigidbody rigidbody = gameObject.AddComponent <Rigidbody> ();

            rigidbody.mass = Wheel_MassProp.floatValue;
            // HingeJoint
            HingeJoint hingeJoint;

            hingeJoint               = gameObject.AddComponent <HingeJoint> ();
            hingeJoint.anchor        = Vector3.zero;
            hingeJoint.axis          = new Vector3(0.0f, 1.0f, 0.0f);
            hingeJoint.connectedBody = thisTransform.parent.gameObject.GetComponent <Rigidbody> ();
            // Drive_Wheel_CS
            PTS_Drive_Wheel_CS driveScript = gameObject.AddComponent <PTS_Drive_Wheel_CS> ();

            driveScript.Radius     = Wheel_RadiusProp.floatValue;
            driveScript.Drive_Flag = Drive_WheelProp.boolValue;
        }
Esempio n. 2
0
        void Create_Wheel(string direction, Vector3 position, int number)
        {
            // Create a new gameobject.
            GameObject gameObject = new GameObject("SupportWheel_" + direction + "_" + number);

            gameObject.transform.parent        = thisTransform;
            gameObject.transform.localPosition = position;
            if (direction == "L")
            {
                gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);
            }
            else
            {
                gameObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180.0f);
            }
            gameObject.layer = PTS_Layer_Settings_CS.Wheels_Layer;             // Wheel
            // Mesh
            MeshFilter meshFilter = gameObject.AddComponent <MeshFilter> ();

            meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh;
            MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer> ();

            Material[] materials = new Material [Wheel_Materials_NumProp.intValue];
            for (int i = 0; i < materials.Length; i++)
            {
                materials [i] = Wheel_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material;
            }
            meshRenderer.materials = materials;
            // SphereCollider
            SphereCollider sphereCollider = gameObject.AddComponent <SphereCollider> ();

            sphereCollider.radius   = Wheel_RadiusProp.floatValue;
            sphereCollider.center   = Vector3.zero;
            sphereCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial;
            // for Physics Wheel.
            if (Static_FlagProp.boolValue == false)
            {
                // Rigidbody
                Rigidbody rigidbody = gameObject.AddComponent <Rigidbody> ();
                rigidbody.mass = Wheel_MassProp.floatValue;
                // HingeJoint
                HingeJoint hingeJoint = gameObject.AddComponent <HingeJoint> ();
                hingeJoint.anchor        = Vector3.zero;
                hingeJoint.axis          = new Vector3(0.0f, 1.0f, 0.0f);
                hingeJoint.connectedBody = thisTransform.parent.gameObject.GetComponent <Rigidbody> ();
                // Drive_Wheel_CS
                PTS_Drive_Wheel_CS driveScript = gameObject.AddComponent <PTS_Drive_Wheel_CS> ();
                driveScript.Radius     = Wheel_RadiusProp.floatValue;
                driveScript.Drive_Flag = Drive_WheelProp.boolValue;
                // Wheel_Resize_CS
                if (Wheel_ResizeProp.boolValue)
                {
                    PTS_Wheel_Resize_CS resizeScript = gameObject.AddComponent <PTS_Wheel_Resize_CS> ();
                    resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue;
                    resizeScript.Return_Speed   = Return_SpeedProp.floatValue;
                }
                // Stabilizer_CS
                gameObject.AddComponent <PTS_Stabilizer_CS> ();
            }
            else                 // for Static Wheel
            {
                PTS_Static_Wheel_CS staticScript = gameObject.AddComponent <PTS_Static_Wheel_CS> ();
                staticScript.Radius_Offset = Radius_OffsetProp.floatValue;
            }
        }
Esempio n. 3
0
        void Create_Wheel(string direction, int number)
        {
            // Create gameobject & Set parent.
            GameObject gameObject = new GameObject("RoadWheel_" + direction + "_" + number);

            gameObject.transform.parent = thisTransform;
            // Set position.
            Vector3 pos;

            if (Set_IndividuallyProp.boolValue)
            {
                pos.x = Mathf.Sin(Mathf.Deg2Rad * (180.0f + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue)) * Sus_LengthProp.floatValue;
                pos.z = Mathf.Cos(Mathf.Deg2Rad * (180.0f + Sus_AnglesProp.GetArrayElementAtIndex(number - 1).floatValue)) * Sus_LengthProp.floatValue;
            }
            else
            {
                pos.x = Mathf.Sin(Mathf.Deg2Rad * (180.0f + Sus_AngleProp.floatValue)) * Sus_LengthProp.floatValue;
                pos.z = Mathf.Cos(Mathf.Deg2Rad * (180.0f + Sus_AngleProp.floatValue)) * Sus_LengthProp.floatValue;
            }
            pos.z -= SpacingProp.floatValue * (number - 1);
            pos.y  = Wheel_DistanceProp.floatValue / 2.0f;
            if (direction == "R")
            {
                pos.y *= -1.0f;
            }
            gameObject.transform.localPosition = pos;
            // Set rotation.
            if (direction == "L")               // Left
            {
                gameObject.transform.localRotation = Quaternion.Euler(Vector3.zero);
            }
            else                 // Right
            {
                gameObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180);
            }
            // Mesh
            if (Wheel_MeshProp.objectReferenceValue)
            {
                MeshFilter meshFilter = gameObject.AddComponent <MeshFilter> ();
                meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh;
                MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer> ();
                Material[]   materials    = new Material [Wheel_Materials_NumProp.intValue];
                for (int i = 0; i < materials.Length; i++)
                {
                    materials [i] = Wheel_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material;
                }
                meshRenderer.materials = materials;
            }
            // Rigidbody
            Rigidbody rigidbody = gameObject.AddComponent <Rigidbody> ();

            rigidbody.mass = Wheel_MassProp.floatValue;
            // HingeJoint
            HingeJoint hingeJoint = gameObject.AddComponent <HingeJoint> ();

            hingeJoint.anchor        = Vector3.zero;
            hingeJoint.axis          = new Vector3(0.0f, 1.0f, 0.0f);
            hingeJoint.connectedBody = thisTransform.Find("Suspension_" + direction + "_" + number).gameObject.GetComponent <Rigidbody> ();
            // SphereCollider
            SphereCollider sphereCollider = gameObject.AddComponent <SphereCollider> ();

            sphereCollider.radius   = Wheel_RadiusProp.floatValue;
            sphereCollider.center   = Vector3.zero;
            sphereCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial;
            // Drive_Wheel_CS
            PTS_Drive_Wheel_CS driveScript = gameObject.AddComponent <PTS_Drive_Wheel_CS> ();

            driveScript.Radius     = Wheel_RadiusProp.floatValue;
            driveScript.Drive_Flag = Drive_WheelProp.boolValue;
            // Wheel_Resize_CS
            if (Fit_ST_FlagProp.boolValue == false)               // for Physics Tracks
            {
                if (Wheel_ResizeProp.boolValue)
                {
                    PTS_Wheel_Resize_CS resizeScript = gameObject.AddComponent <PTS_Wheel_Resize_CS> ();
                    resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue;
                    resizeScript.Return_Speed   = Return_SpeedProp.floatValue;
                }
            }
            // Stabilizer_CS
            gameObject.AddComponent <PTS_Stabilizer_CS> ();
            // Set Layer
            gameObject.layer = PTS_Layer_Settings_CS.Wheels_Layer;             // Wheel
        }