protected override void LateUpdate() { base.LateUpdate(); // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { if (Points.Count > 1) { var worldPoint = listenerPosition; var localPoint = transform.InverseTransformPoint(worldPoint); var closestDistanceSq = float.PositiveInfinity; var closestPoint = Vector3.zero; for (var i = 1; i < Points.Count; i++) { var closePoint = VA_Helper.ClosestPointToLineSegment(Points[i - 1], Points[i], localPoint); var closeDistanceSq = (closePoint - localPoint).sqrMagnitude; if (closeDistanceSq < closestDistanceSq) { closestDistanceSq = closeDistanceSq; closestPoint = closePoint; } } worldPoint = transform.TransformPoint(closestPoint); SetOuterPoint(worldPoint); } } }
public void SetOuterPoint(Vector3 newOuterPoint) { // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { OuterPointSet = true; OuterPoint = newOuterPoint; OuterPointDistance = Vector3.Distance(listenerPosition, newOuterPoint); } }
public void SetInnerPoint(Vector3 newInnerPoint, bool inside) { // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { InnerPointSet = true; InnerPoint = newInnerPoint; InnerPointDistance = Vector3.Distance(listenerPosition, newInnerPoint); InnerPointInside = inside; } }
protected override void LateUpdate() { base.LateUpdate(); // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { UpdateFields(); RebuildMatrix(); var worldPoint = listenerPosition; var localPoint = cachedMatrix.inverse.MultiplyPoint(worldPoint); var scale = transform.lossyScale; var squash = VA_Helper.Divide(scale.y, Mathf.Max(scale.x, scale.z)); var halfHeight = Mathf.Max(0.0f, Height * squash * 0.5f - Radius); if (IsHollow == true) { localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { if (LocalPointInCapsule(localPoint, halfHeight) == true) { SetInnerPoint(worldPoint, true); localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { localPoint = SnapLocalPoint(localPoint, halfHeight); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetInnerOuterPoint(worldPoint, false); } } } }
protected override void LateUpdate() { base.LateUpdate(); // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { UpdateFields(); RebuildMatrix(); var worldPoint = listenerPosition; var localPoint = cachedMatrix.inverse.MultiplyPoint(worldPoint); if (IsHollow == true) { localPoint = SnapLocalPoint(localPoint); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { if (LocalPointInBox(localPoint) == true) { SetInnerPoint(worldPoint, true); localPoint = SnapLocalPoint(localPoint); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetOuterPoint(worldPoint); } else { localPoint = ClipLocalPoint(localPoint); worldPoint = cachedMatrix.MultiplyPoint(localPoint); SetInnerOuterPoint(worldPoint, false); } } } }
protected virtual void LateUpdate() { // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { if (Position == true) { var closestDistance = float.PositiveInfinity; var closestShape = default(VA_Shape); var closestPoint = default(Vector3); // Find closest point to all shapes if (Shapes != null) { for (var i = Shapes.Count - 1; i >= 0; i--) { var shape = Shapes[i]; if (VA_Helper.Enabled(shape) == true && shape.FinalPointSet == true && shape.FinalPointDistance < closestDistance) { closestDistance = shape.FinalPointDistance; closestPoint = shape.FinalPoint; closestShape = shape; } } } // If the closest point is closer than the excluded point, then make the excluded point the closest if (ExcludedShapes != null) { for (var i = ExcludedShapes.Count - 1; i >= 0; i--) { var excludedShape = ExcludedShapes[i]; if (VA_Helper.Enabled(excludedShape) == true && excludedShape.IsHollow == false && excludedShape.InnerPointInside == true) { if (excludedShape.OuterPointSet == true && excludedShape.OuterPointDistance > closestDistance) { closestDistance = excludedShape.OuterPointDistance; closestPoint = excludedShape.OuterPoint; closestShape = excludedShape; break; } } } } if (closestShape != null) { if (PositionDampening <= 0.0f) { transform.position = closestPoint; } else { transform.position = VA_Helper.Dampen3(transform.position, closestPoint, PositionDampening, Time.deltaTime); } } else { closestPoint = transform.position; closestDistance = Vector3.Distance(closestPoint, listenerPosition); } } // Modify the blend? if (Blend == true) { var distance = Vector3.Distance(transform.position, listenerPosition); var distance01 = Mathf.InverseLerp(BlendMinDistance, BlendMaxDistance, distance); SetPanLevel(BlendCurve.Evaluate(distance01)); } // Modify the volume? if (Volume == true) { var finalVolume = BaseVolume; // Modify via zone? if (Zone != null) { finalVolume *= Zone.Volume; } // Modify via distance? if (Fade == true) { var distance = Vector3.Distance(transform.position, listenerPosition); var distance01 = Mathf.InverseLerp(FadeMinDistance, FadeMaxDistance, distance); finalVolume *= FadeCurve.Evaluate(distance01); } // Modify via occlusion? if (Occlude == true) { var direction = listenerPosition - transform.position; var targetAmount = 1.0f; if (OccludeGroups != null) { for (var i = OccludeGroups.Count - 1; i >= 0; i--) { var group = OccludeGroups[i]; switch (OccludeMethod) { case OccludeType.Raycast: { var hit = default(RaycastHit); if (Physics.Raycast(transform.position, direction, out hit, direction.magnitude, group.Layers) == true) { targetAmount *= GetOcclusionVolume(group, hit); } } break; case OccludeType.RaycastAll: { var hits = Physics.RaycastAll(transform.position, direction, direction.magnitude, group.Layers); for (var j = hits.Length - 1; j >= 0; j--) { targetAmount *= GetOcclusionVolume(group, hits[j]); } } break; } } } OccludeAmount = VA_Helper.Dampen(OccludeAmount, targetAmount, OccludeDampening, Time.deltaTime, 0.1f); finalVolume *= OccludeAmount; } SetVolume(finalVolume); } } }
protected virtual void Update() { // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { // Calculate the target volume var targetVolume = 0.0f; if (Vector3.Distance(listenerPosition, transform.position) <= Radius) { targetVolume = 1.0f; } // Dampen volume to the target value Volume = VA_Helper.Dampen(Volume, targetVolume, VolumeDampening, Time.deltaTime, 0.1f); // Loop through all audio sources if (AudioSources != null) { for (var i = AudioSources.Count - 1; i >= 0; i--) { var audioSource = AudioSources[i]; if (audioSource != null) { // Apply the zone so this volume can be set audioSource.Zone = this; // Enable volumes? if (Volume > 0.0f) { if (audioSource.gameObject.activeSelf == false) { audioSource.gameObject.SetActive(true); } if (audioSource.enabled == false) { audioSource.enabled = true; } } else { if (DeactivateGameObjects == true) { if (audioSource.gameObject.activeSelf == true) { audioSource.gameObject.SetActive(false); } } else { if (audioSource.enabled == true) { audioSource.enabled = false; } } } } } } } }
protected override void LateUpdate() { base.LateUpdate(); // Update mesh? if (meshUpdateCooldown > MeshUpdateInterval) { meshUpdateCooldown = MeshUpdateInterval; } if (MeshUpdateInterval >= 0.0f) { meshUpdateCooldown -= Time.deltaTime; if (meshUpdateCooldown <= 0.0f) { meshUpdateCooldown = MeshUpdateInterval; if (IsBaked == true) { if (tree != null) { tree.Update(Mesh); } } else { if (linear != null) { linear.Update(Mesh); } } } } // Make sure the listener exists var listenerPosition = default(Vector3); if (VA_Helper.GetListenerPosition(ref listenerPosition) == true) { UpdateFields(); var worldPoint = listenerPosition; var localPoint = transform.InverseTransformPoint(worldPoint); if (Mesh != null) { if (IsHollow == true) { localPoint = SnapLocalPoint(localPoint); worldPoint = transform.TransformPoint(localPoint); SetOuterPoint(worldPoint); } else { if (PointInMesh(localPoint, worldPoint) == true) { SetInnerPoint(worldPoint, true); localPoint = SnapLocalPoint(localPoint); worldPoint = transform.TransformPoint(localPoint); SetOuterPoint(worldPoint); } else { localPoint = SnapLocalPoint(localPoint); worldPoint = transform.TransformPoint(localPoint); SetInnerOuterPoint(worldPoint, false); } } } } }