protected virtual void Update() { var mouseDown = Input.GetMouseButton(0); // Only update controls if playing if (Application.isPlaying == true) { linearVelocity += transform.right * Input.GetAxis("Horizontal") * LinearSpeed * Time.deltaTime; linearVelocity += transform.forward * Input.GetAxis("Vertical") * LinearSpeed * Time.deltaTime; if (mouseDown == true && lastMouseDown == true) { angularVelocity.y += Input.GetAxis("Mouse X") * AngularSpeed * Time.deltaTime; angularVelocity.x -= Input.GetAxis("Mouse Y") * AngularSpeed * Time.deltaTime; } linearVelocity = VA_Helper.Dampen3(linearVelocity, Vector3.zero, LinearDampening, Time.deltaTime, 0.1f); angularVelocity = VA_Helper.Dampen3(angularVelocity, Vector3.zero, AngularDampening, Time.deltaTime, 0.1f); } EulerAngles += angularVelocity * Time.deltaTime; EulerAngles.x = Mathf.Clamp(EulerAngles.x, -89.0f, 89.0f); transform.position += linearVelocity * Time.deltaTime; transform.rotation = Quaternion.Euler(EulerAngles); lastMouseDown = mouseDown; }
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); } } }