void Create_Physics_Wheel(string direction, Vector3 position) { GameObject wheelObject = Create_GameObject("IdlerWheel", direction, position); Add_Mesh(wheelObject); Add_SphereCollider(wheelObject); Add_DrivingComponents(wheelObject, direction); // Wheel_Resize_CS if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript; resizeScript = wheelObject.AddComponent <Wheel_Resize_CS> (); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } // Fix_Shaking_Rotation_CS Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; }
void Set_Physics_Wheel(GameObject wheelObject, string direction) { // Rigidbody Rigidbody rigidbody = wheelObject.AddComponent <Rigidbody>(); rigidbody.mass = Wheel_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint = wheelObject.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 Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS>(); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Wheel_Resize_CS if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript = wheelObject.AddComponent <Wheel_Resize_CS>(); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } // Fix_Shaking_Rotation_CS Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; }
void Create_TrackPiece(string direction, Vector3 position, float angleY, int number) { //Create gameobject & Set transform GameObject pieceObject = new GameObject("TrackBelt_" + direction + "_" + number); pieceObject.transform.parent = thisTransform; pieceObject.transform.localPosition = position; pieceObject.transform.localRotation = Quaternion.Euler(0.0f, angleY, -90.0f); // Mesh MeshFilter meshFilter = pieceObject.AddComponent <MeshFilter> (); MeshRenderer meshRenderer = pieceObject.AddComponent <MeshRenderer> (); if (Use_ShadowMeshProp.boolValue) { meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; } if (direction == "L") { if (Use_2ndPieceProp.boolValue && number % 2 == 0) { meshFilter.mesh = Track_L_2nd_MeshProp.objectReferenceValue as Mesh; } else { meshFilter.mesh = Track_L_MeshProp.objectReferenceValue as Mesh; } } else { if (Use_2ndPieceProp.boolValue && number % 2 == 0) { meshFilter.mesh = Track_R_2nd_MeshProp.objectReferenceValue as Mesh; } else { meshFilter.mesh = Track_R_MeshProp.objectReferenceValue as Mesh; } } if (Use_2ndPieceProp.boolValue && number % 2 == 0) { Material[] materials = new Material [Track_2nd_Materials_NumProp.intValue]; for (int i = 0; i < materials.Length; i++) { materials [i] = Track_2nd_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material; } meshRenderer.materials = materials; } else { Material[] materials = new Material [Track_Materials_NumProp.intValue]; for (int i = 0; i < materials.Length; i++) { materials [i] = Track_MaterialsProp.GetArrayElementAtIndex(i).objectReferenceValue as Material; } meshRenderer.materials = materials; } // Collider if (Use_BoxColliderProp.boolValue) { // Box Collider BoxCollider boxCollider = pieceObject.AddComponent <BoxCollider>(); boxCollider.center = Collider_InfoProp.boundsValue.center; boxCollider.size = Collider_InfoProp.boundsValue.size; boxCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial; } else { // CapsuleColliders CapsuleCollider horizontalCollider = pieceObject.AddComponent <CapsuleCollider>(); horizontalCollider.center = Collider_InfoProp.boundsValue.center; if (direction == "R") { horizontalCollider.center = new Vector3(-horizontalCollider.center.x, horizontalCollider.center.y, horizontalCollider.center.z); } horizontalCollider.direction = 0; // X-Axis horizontalCollider.radius = Collider_InfoProp.boundsValue.extents.y; horizontalCollider.height = Collider_InfoProp.boundsValue.size.x; horizontalCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial; CapsuleCollider verticalCollider = pieceObject.AddComponent <CapsuleCollider>(); verticalCollider.center = Collider_InfoProp.boundsValue.center; if (direction == "R") { verticalCollider.center = new Vector3(-verticalCollider.center.x, verticalCollider.center.y, verticalCollider.center.z); } verticalCollider.direction = 2; // Z-Axis verticalCollider.radius = Collider_InfoProp.boundsValue.extents.y; verticalCollider.height = Collider_InfoProp.boundsValue.size.z; verticalCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial; } // Stabilizer_CS Stabilizer_CS stabilizerScript = pieceObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = pieceObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = pieceObject.transform.localPosition.y; stabilizerScript.Initial_Angles = pieceObject.transform.localEulerAngles; // Damage_Control_02_Physics_Track_Piece_CS var damageScript = pieceObject.AddComponent <Damage_Control_03_Physics_Track_Piece_CS> (); if (direction == "L") // Left { damageScript.Track_Index = 0; } else // Right { damageScript.Track_Index = 1; } // Static_Track_Setting_CS if (Static_FlagProp.boolValue) { Static_Track_Setting_CS settingScript = pieceObject.AddComponent <Static_Track_Setting_CS> (); settingScript.Use_2ndPiece = Use_2ndPieceProp.boolValue; } // Set Layer pieceObject.layer = 0; }
void Set_Wheel(string direction, Vector3 position, int number, int parentNumber) { // Create RoadWheel GameObject GameObject wheelObject = new GameObject("RoadWheel_" + direction + "_" + number); wheelObject.transform.parent = thisTransform; wheelObject.transform.localPosition = position; if (direction == "L") { wheelObject.transform.localRotation = Quaternion.identity; } else { wheelObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180.0f); } // Mesh MeshFilter meshFilter = wheelObject.AddComponent <MeshFilter> (); meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh; MeshRenderer meshRenderer = wheelObject.AddComponent <MeshRenderer> (); meshRenderer.material = Wheel_MaterialProp.objectReferenceValue as Material; // Rigidbody Rigidbody rigidbody = wheelObject.AddComponent <Rigidbody> (); rigidbody.mass = Wheel_MassProp.floatValue; // SphereCollider SphereCollider sphereCollider = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Wheel_Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // HingeJoint HingeJoint hingeJoint; hingeJoint = wheelObject.AddComponent <HingeJoint> (); hingeJoint.anchor = Vector3.zero; hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); hingeJoint.connectedBody = thisTransform.Find("ChildArm_" + direction + "_" + parentNumber).gameObject.GetComponent <Rigidbody> (); // Drive_Wheel_CS Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS> (); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Fix_Shaking_Rotation_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; } // Wheel_Resize_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript; resizeScript = wheelObject.AddComponent <Wheel_Resize_CS> (); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } } // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; // Set Layer wheelObject.layer = Layer_Settings_CS.Wheels_Layer; }
void Create_Wheel(string direction, Vector3 position) { // Create 'Parent_of_Wheel' GameObject parentObject = new GameObject("Parent_of_Wheel_" + direction); parentObject.transform.parent = thisTransform.Find("Hub_" + direction); parentObject.transform.localPosition = position; parentObject.transform.localRotation = Quaternion.Euler(0, 0, 90); // Create Wheel GameObject wheelObject = new GameObject("SteeredWheel_" + direction); wheelObject.transform.parent = parentObject.transform; if (direction == "L") { wheelObject.transform.localPosition = new Vector3(0.0f, Wheel_DistanceProp.floatValue / 2.0f, 0.0f); wheelObject.transform.localRotation = Quaternion.Euler(0, 0, 0); } else { wheelObject.transform.localPosition = new Vector3(0.0f, -Wheel_DistanceProp.floatValue / 2.0f, 0.0f); wheelObject.transform.localRotation = Quaternion.Euler(0, 0, 180); } // Mesh MeshFilter meshFilter = wheelObject.AddComponent <MeshFilter> (); meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh; MeshRenderer meshRenderer = wheelObject.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 = wheelObject.AddComponent <Rigidbody> (); rigidbody.mass = Wheel_MassProp.floatValue; // SphereCollider SphereCollider sphereCollider = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Wheel_Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // HingeJoint HingeJoint hingeJoint; hingeJoint = wheelObject.AddComponent <HingeJoint> (); hingeJoint.connectedBody = parentObject.transform.parent.GetComponent <Rigidbody> (); hingeJoint.anchor = Vector3.zero; hingeJoint.axis = new Vector3(0.0f, 1.0f, 0.0f); // Drive_Wheel_CS Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS> (); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; // Set Layer wheelObject.layer = Layer_Settings_CS.Wheels_Layer; }
void Create_Wheel(string direction, int number) { // Create gameobject & Set parent. GameObject wheelObject = new GameObject("RoadWheel_" + direction + "_" + number); wheelObject.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; } wheelObject.transform.localPosition = pos; // Set rotation. if (direction == "L") // Left { wheelObject.transform.localRotation = Quaternion.Euler(Vector3.zero); } else // Right { wheelObject.transform.localRotation = Quaternion.Euler(0.0f, 0.0f, 180); } // Mesh if (Wheel_MeshProp.objectReferenceValue) { MeshFilter meshFilter = wheelObject.AddComponent <MeshFilter> (); meshFilter.mesh = Wheel_MeshProp.objectReferenceValue as Mesh; MeshRenderer meshRenderer = wheelObject.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 = wheelObject.AddComponent <Rigidbody> (); rigidbody.mass = Wheel_MassProp.floatValue; // HingeJoint HingeJoint hingeJoint = wheelObject.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 = wheelObject.AddComponent <SphereCollider> (); sphereCollider.radius = Wheel_RadiusProp.floatValue; sphereCollider.center = Vector3.zero; sphereCollider.material = Collider_MaterialProp.objectReferenceValue as PhysicMaterial; // Drive_Wheel_CS Drive_Wheel_CS driveScript = wheelObject.AddComponent <Drive_Wheel_CS> (); driveScript.This_Rigidbody = rigidbody; driveScript.Is_Left = (direction == "L"); driveScript.Parent_Script = thisTransform.GetComponent <Drive_Wheel_Parent_CS>(); // Fix_Shaking_Rotation_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { Fix_Shaking_Rotation_CS fixScript = wheelObject.AddComponent <Fix_Shaking_Rotation_CS>(); fixScript.Is_Left = (direction == "L"); fixScript.This_Transform = wheelObject.transform; } // Wheel_Resize_CS if (Fit_ST_FlagProp.boolValue == false) // for Physics Tracks { if (Wheel_ResizeProp.boolValue) { Wheel_Resize_CS resizeScript = wheelObject.AddComponent <Wheel_Resize_CS> (); resizeScript.ScaleDown_Size = ScaleDown_SizeProp.floatValue; resizeScript.Return_Speed = Return_SpeedProp.floatValue; } } // Stabilizer_CS Stabilizer_CS stabilizerScript = wheelObject.AddComponent <Stabilizer_CS>(); stabilizerScript.This_Transform = wheelObject.transform; stabilizerScript.Is_Left = (direction == "L"); stabilizerScript.Initial_Pos_Y = wheelObject.transform.localPosition.y; stabilizerScript.Initial_Angles = wheelObject.transform.localEulerAngles; // Set Layer wheelObject.layer = Layer_Settings_CS.Wheels_Layer; }