// Use this for initialization private void Start() { if (!VehicleAPI.IsValidIndividualLight(lightType)) { throw new Exception("Light sides need to have a valid value, revise your code."); } GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Capsule); //If you uncomment this wheels won't steer //Destroy(obj.GetComponent<CapsuleCollider>()); obj.name = string.Format("Blinker ({0})", lightType.ToString()); obj.transform.parent = parent; obj.transform.position = parent.position + Vector3.right * (IsLeftSide ? -1 : 1) * .2f; //obj.transform.localRotation = Quaternion.Euler(new Vector3(0, 30 * (IsLeftSide ? -1 : 1), 0)); obj.transform.localScale = Vector3.one * .2f; blinkerRenderer = obj.GetComponent <MeshRenderer>(); blinkerRenderer.material = Resources.Load <Material>("Materials/Blinker"); defaultIntensity = blinkerRenderer.material.GetFloat("_MKGlowPower"); blinkerSwitch = false; InvokeRepeating("Cycle", 0, repeatInterval); }
private static Vector3 GetLightOffsetFor(Vehicle vehicle, VehicleLight light) { string lightBoneName = GetBoneNameForLight(light); if (lightBoneName == null) { throw new ArgumentOutOfRangeException(nameof(light)); } Vector3 offset = Vector3.Zero; Vector3 boneWorldPos = vehicle.HasBone(lightBoneName) ? vehicle.GetBonePosition(lightBoneName) : Vector3.Zero; // if a light is broken it returns a position Vector3 near Vector3.Zero, if so get an approximate offset if (Vector3.DistanceSquared(boneWorldPos, Vector3.Zero) < 1.25f * 1.25f) { string lightName = light.ToString().ToLower(); // left or right Vector3 posOffset1 = vehicle.GetPositionOffset(lightName.Contains("left") ? vehicle.LeftPosition : vehicle.RightPosition); // front or rear Vector3 posOffset2 = vehicle.GetPositionOffset(lightName.Contains("headlight") ? vehicle.FrontPosition : vehicle.RearPosition); offset = new Vector3(posOffset1.X, posOffset2.Y, posOffset2.Z); } else { offset = vehicle.GetPositionOffset(boneWorldPos); } return(offset); }
private static Vector3 GetLightOffsetFor(Vehicle vehicle, VehicleLight light) { string lightBoneName = GetBoneNameForLight(light); if (lightBoneName == null) throw new ArgumentOutOfRangeException(nameof(light)); Vector3 offset = Vector3.Zero; Vector3 boneWorldPos = vehicle.HasBone(lightBoneName) ? vehicle.GetBonePosition(lightBoneName) : Vector3.Zero; // if a light is broken it returns a position Vector3 near Vector3.Zero, if so get an approximate offset if (Vector3.DistanceSquared(boneWorldPos, Vector3.Zero) < 1.25f * 1.25f) { string lightName = light.ToString().ToLower(); // left or right Vector3 posOffset1 = vehicle.GetPositionOffset(lightName.Contains("left") ? vehicle.LeftPosition : vehicle.RightPosition); // front or rear Vector3 posOffset2 = vehicle.GetPositionOffset(lightName.Contains("headlight") ? vehicle.FrontPosition : vehicle.RearPosition); offset = new Vector3(posOffset1.X, posOffset2.Y, posOffset2.Z); } else { offset = vehicle.GetPositionOffset(boneWorldPos); } return offset; }
internal static VehicleLight?GetVehicleLightParent(VehicleLight light) { if (light == VehicleLight.All || light == VehicleLight.Front || light == VehicleLight.Rear) { return(null); } string lightName = light.ToString(); return((VehicleLight)System.Enum.Parse(typeof(VehicleLight), IsFrontLight(light) ? lightName.Substring(0, 5) : lightName.Substring(0, 4))); }
internal static string GetLightName(VehicleLight light) { if (light == VehicleLight.All || light == VehicleLight.Front || light == VehicleLight.Rear) { throw new System.Exception("Light must be right or left, can't be general!"); } string lightName = light.ToString(); return(string.Format("{0}Light", (IsFrontLight(light) ? lightName.Substring(5) : lightName.Substring(4)).ToLower())); }