Esempio n. 1
0
    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);
            }
        }
    }
Esempio n. 2
0
    private void CalculateAxisAndPivot(List <VA_Triangle> tris, ref int axis, ref float pivot)
    {
        var min = tris[0].Min;
        var max = tris[0].Max;
        var mid = Vector3.zero;

        foreach (var tri in tris)
        {
            min  = Vector3.Min(min, tri.Min);
            max  = Vector3.Max(max, tri.Max);
            mid += tri.A + tri.B + tri.C;
        }

        var size = max - min;

        if (size.x > size.y && size.x > size.z)
        {
            axis  = 0;
            pivot = VA_Helper.Divide(mid.x, tris.Count * 3.0f);
        }
        else if (size.y > size.x && size.y > size.z)
        {
            axis  = 1;
            pivot = VA_Helper.Divide(mid.y, tris.Count * 3.0f);
        }
        else
        {
            axis  = 2;
            pivot = VA_Helper.Divide(mid.z, tris.Count * 3.0f);
        }
    }
Esempio n. 3
0
    // Called every frame
    protected virtual void Update()
    {
        // Make sure the camera exists
        Camera = VA_Helper.GetCamera(Camera);

        if (Camera != null && Prefabs != null)
        {
            // The required key is down?
            if (Input.GetKeyDown(Requires) == true)
            {
                // Find the ray for this screen position
                var ray      = Camera.ScreenPointToRay(Input.mousePosition);
                var rotation = Quaternion.LookRotation(ray.direction);

                // Loop through all prefabs and spawn them
                for (var i = Prefabs.Count - 1; i >= 0; i--)
                {
                    var prefab = Prefabs[i];

                    if (prefab != null)
                    {
                        var clone = (GameObject)Instantiate(prefab, ray.origin, rotation);

                        // Throw with velocity?
                        var cloneRigidbody = clone.GetComponent <Rigidbody>();

                        if (cloneRigidbody != null)
                        {
                            cloneRigidbody.velocity = clone.transform.forward * Speed;
                        }
                    }
                }
            }
        }
    }
Esempio n. 4
0
    public override void OnInspectorGUI()
    {
        EditorGUI.BeginChangeCheck();
        {
            Target  = (T)target;
            Targets = targets.Select(t => (T)t).ToArray();

            Separator();

            OnInspector();

            Separator();

            serializedObject.ApplyModifiedProperties();
        }
        if (EditorGUI.EndChangeCheck() == true)
        {
            GUI.changed = true; Repaint();

            foreach (var t in Targets)
            {
                VA_Helper.SetDirty(t);
            }
        }
    }
Esempio n. 5
0
    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;
    }
Esempio n. 6
0
    protected void DirtyEach(System.Action <T> update)
    {
        foreach (var t in Targets)
        {
            update(t);

            VA_Helper.SetDirty(t);
        }
    }
Esempio n. 7
0
    public void RebuildMatrix()
    {
        var position = transform.TransformPoint(Center);
        var rotation = transform.rotation;
        var scale    = transform.lossyScale;

        scale.x = scale.y = scale.z = Mathf.Max(Mathf.Max(scale.x, scale.y), scale.z);

        VA_Helper.MatrixTrs(position, rotation, scale, ref cachedMatrix);
        //return VA_Helper.TranslationMatrix(position) * VA_Helper.RotationMatrix(rotation) * VA_Helper.ScalingMatrix(scale);
    }
Esempio n. 8
0
    public virtual void OnSceneGUI()
    {
        Target = (T)target;

        OnScene();

        if (GUI.changed == true)
        {
            VA_Helper.SetDirty(target);
        }
    }
Esempio n. 9
0
    protected virtual void OnDrawGizmosSelected()
    {
        if (VA_Helper.Enabled(this) == true)
        {
            UpdateFields();
            RebuildMatrix();

            Gizmos.color  = Color.red;
            Gizmos.matrix = cachedMatrix;
            Gizmos.DrawWireCube(Vector3.zero, Vector3.one);
        }
    }
Esempio n. 10
0
    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);
        }
    }
Esempio n. 11
0
    protected virtual void OnDrawGizmosSelected()
    {
        if (VA_Helper.Enabled(this) == true)
        {
            UpdateFields();

            Gizmos.color  = Color.red;
            Gizmos.matrix = transform.localToWorldMatrix;

            if (IsBaked == true)
            {
                for (var i = tree.Triangles.Count - 1; i >= 0; i--)
                {
                    var triangle = tree.Triangles[i];

                    Gizmos.DrawLine(triangle.A, triangle.B);
                    Gizmos.DrawLine(triangle.B, triangle.C);
                    Gizmos.DrawLine(triangle.C, triangle.A);
                }
            }
            else
            {
                if (Mesh != null)
                {
                    var positions = Mesh.vertices;

                    for (var i = 0; i < Mesh.subMeshCount; i++)
                    {
                        switch (Mesh.GetTopology(i))
                        {
                        case MeshTopology.Triangles:
                        {
                            var indices = Mesh.GetTriangles(i);

                            for (var j = 0; j < indices.Length; j += 3)
                            {
                                var point1 = positions[indices[j + 0]];
                                var point2 = positions[indices[j + 1]];
                                var point3 = positions[indices[j + 2]];

                                Gizmos.DrawLine(point1, point2);
                                Gizmos.DrawLine(point2, point3);
                                Gizmos.DrawLine(point3, point1);
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }
    }
Esempio n. 12
0
    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;
        }
    }
Esempio n. 13
0
    protected virtual void OnDrawGizmosSelected()
    {
        if (VA_Helper.Enabled(this) == true)
        {
            // Draw red lines from this audio source to all shapes
            Gizmos.color = Color.red;

            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)
                    {
                        Gizmos.DrawLine(transform.position, shape.FinalPoint);
                    }
                }
            }

            // Draw green spheres for blend distances
            if (Blend == true)
            {
                for (var i = 0; i <= 50; i++)
                {
                    var frac = i * 0.02f;

                    Gizmos.color = new Color(0.0f, 1.0f, 0.0f, BlendCurve.Evaluate(frac));

                    Gizmos.DrawWireSphere(transform.position, Mathf.Lerp(BlendMinDistance, BlendMaxDistance, frac));
                }
            }

            // Draw blue spheres for volume distances
            if (Fade == true)
            {
                for (var i = 0; i <= 50; i++)
                {
                    var frac = i * 0.02f;

                    Gizmos.color = new Color(0.0f, 0.0f, 1.0f, BlendCurve.Evaluate(frac));

                    Gizmos.DrawWireSphere(transform.position, Mathf.Lerp(FadeMinDistance, FadeMaxDistance, frac));
                }
            }
        }
    }
Esempio n. 14
0
    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);
                }
            }
        }
    }
Esempio n. 15
0
    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);
                }
            }
        }
    }
Esempio n. 16
0
    public void RebuildMatrix()
    {
        var position = transform.TransformPoint(Center);
        var rotation = transform.rotation;
        var scale    = transform.lossyScale;

        switch (Direction)
        {
        case 0: rotation *= RotationX; break;

        case 1: rotation *= RotationY; break;

        case 2: rotation *= RotationZ; break;
        }

        scale.x = scale.y = scale.z = Mathf.Max(scale.x, scale.z);

        VA_Helper.MatrixTrs(position, rotation, scale, ref cachedMatrix);
        //matrix = VA_Helper.TranslationMatrix(position) * VA_Helper.RotationMatrix(rotation) * matrix * VA_Helper.ScalingMatrix(scale);
    }
Esempio n. 17
0
    protected void DrawDefault(string propertyPath, bool autoApply = true)
    {
        EditorGUI.BeginChangeCheck();
        {
            EditorGUILayout.BeginVertical(VA_Helper.NoError);
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty(propertyPath), true);
            }
            EditorGUILayout.EndVertical();
        }
        if (EditorGUI.EndChangeCheck() == true)
        {
            if (autoApply == true)
            {
                serializedObject.ApplyModifiedProperties();
            }

            for (var i = Targets.Length - 1; i >= 0; i--)
            {
                VA_Helper.SetDirty(Targets[i]);
            }
        }
    }
Esempio n. 18
0
    protected virtual void OnDrawGizmosSelected()
    {
        if (VA_Helper.Enabled(this) == true)
        {
            UpdateFields();
            RebuildMatrix();

            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);
            var point1     = Vector3.up * halfHeight;
            var point2     = Vector3.up * -halfHeight;

            Gizmos.color  = Color.red;
            Gizmos.matrix = cachedMatrix;
            Gizmos.DrawWireSphere(point1, Radius);
            Gizmos.DrawWireSphere(point2, Radius);
            Gizmos.DrawLine(point1 + Vector3.right * Radius, point2 + Vector3.right * Radius);
            Gizmos.DrawLine(point1 - Vector3.right * Radius, point2 - Vector3.right * Radius);
            Gizmos.DrawLine(point1 + Vector3.forward * Radius, point2 + Vector3.forward * Radius);
            Gizmos.DrawLine(point1 - Vector3.forward * Radius, point2 - Vector3.forward * Radius);
        }
    }
Esempio n. 19
0
    private Vector3 SnapLocalPoint(Vector3 localPoint)
    {
        var x = Mathf.Abs(localPoint.x);
        var y = Mathf.Abs(localPoint.y);
        var z = Mathf.Abs(localPoint.z);

        // X largest?
        if (x > y && x > z)
        {
            localPoint *= VA_Helper.Reciprocal(x * 2.0f);
        }
        // Y largest?
        else if (y > x && y > z)
        {
            localPoint *= VA_Helper.Reciprocal(y * 2.0f);
        }
        // Z largest?
        else
        {
            localPoint *= VA_Helper.Reciprocal(z * 2.0f);
        }

        return(localPoint);
    }
Esempio n. 20
0
    public void Regenerate()
    {
        // Create or clear mesh
        if (mesh == null)
        {
            mesh = new Mesh();

            mesh.name      = "Spiral";
            mesh.hideFlags = HideFlags.DontSave;
        }
        else
        {
            mesh.Clear();
        }

        // Apply mesh to filter
        if (cachedMeshFilter == null)
        {
            cachedMeshFilter = GetComponent <MeshFilter>();
        }

        cachedMeshFilter.sharedMesh = mesh;

        // Invalid segment count?
        if (InvalidSegmentCount == true)
        {
            return;
        }

        // Allocate arrays?
        var vertexCount = SegmentCount * 2 + 2;

        if (positions == null || positions.Length != vertexCount)
        {
            positions = new Vector3[vertexCount];
        }

        if (uvs == null || uvs.Length != vertexCount)
        {
            uvs = new Vector2[vertexCount];
        }

        // Generate indices?
        if (indices == null || indices.Length != SegmentCount * 6)
        {
            indices = new int[SegmentCount * 6];

            for (var i = 0; i < SegmentCount; i++)
            {
                indices[i * 6 + 0] = i * 2 + 0;
                indices[i * 6 + 1] = i * 2 + 1;
                indices[i * 6 + 2] = i * 2 + 2;
                indices[i * 6 + 3] = i * 2 + 3;
                indices[i * 6 + 4] = i * 2 + 2;
                indices[i * 6 + 5] = i * 2 + 1;
            }
        }

        var angle    = InitialAngle;
        var distance = InitialDistance;

        for (var i = 0; i <= SegmentCount; i++)
        {
            var vertex = i * 2;

            positions[vertex + 0] = VA_Helper.SinCos(angle * Mathf.Deg2Rad) * distance;
            positions[vertex + 1] = VA_Helper.SinCos(angle * Mathf.Deg2Rad) * (distance + SegmentThickness);

            uvs[vertex + 0] = Vector2.zero;
            uvs[vertex + 1] = Vector2.one;

            angle    += AngleStep;
            distance += DistanceStep;
        }

        // Update mesh
        mesh.vertices  = positions;
        mesh.triangles = indices;
        mesh.uv        = uvs;

        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
    }
Esempio n. 21
0
 protected virtual void OnDestroy()
 {
     VA_Helper.Destroy(mesh);
 }
Esempio n. 22
0
    protected bool Button(string text)
    {
        var rect = VA_Helper.Reserve();

        return(GUI.Button(rect, text));
    }
Esempio n. 23
0
    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;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
Esempio n. 24
0
    protected override void OnScene()
    {
        var matrix  = Target.transform.localToWorldMatrix;
        var inverse = Target.transform.worldToLocalMatrix;

        for (var i = 0; i < Target.Points.Count; i++)
        {
            var oldPoint = matrix.MultiplyPoint(Target.Points[i]);

            Handles.matrix = VA_Helper.TranslationMatrix(oldPoint) * VA_Helper.ScalingMatrix(0.8f) * VA_Helper.TranslationMatrix(oldPoint * -1.0f);

            var newPoint = Handles.PositionHandle(oldPoint, Quaternion.identity);

            if (oldPoint != newPoint)
            {
                Undo.RecordObject(Target, "Move Path Point");
                Target.Points[i] = inverse.MultiplyPoint(newPoint);

                EditorUtility.SetDirty(Target);
            }
        }

        Handles.color  = Color.red;
        Handles.matrix = Target.transform.localToWorldMatrix;

        for (var i = 1; i < Target.Points.Count; i++)
        {
            Handles.DrawLine(Target.Points[i - 1], Target.Points[i]);
        }

        Handles.BeginGUI();
        {
            for (var i = 0; i < Target.Points.Count; i++)
            {
                var point     = Target.Points[i];
                var pointName = "Point " + i;
                var scrPoint  = Camera.current.WorldToScreenPoint(matrix.MultiplyPoint(point));
                var rect      = new Rect(0.0f, 0.0f, 50.0f, 20.0f); rect.center = new Vector2(scrPoint.x, Screen.height - scrPoint.y - 35.0f);
                var rect1     = rect; rect.x += 1.0f;
                var rect2     = rect; rect.x -= 1.0f;
                var rect3     = rect; rect.y += 1.0f;
                var rect4     = rect; rect.y -= 1.0f;

                GUI.Label(rect1, pointName, EditorStyles.miniBoldLabel);
                GUI.Label(rect2, pointName, EditorStyles.miniBoldLabel);
                GUI.Label(rect3, pointName, EditorStyles.miniBoldLabel);
                GUI.Label(rect4, pointName, EditorStyles.miniBoldLabel);
                GUI.Label(rect, pointName, EditorStyles.whiteMiniLabel);
            }

            for (var i = 1; i < Target.Points.Count; i++)
            {
                var pointA   = Target.Points[i - 1];
                var pointB   = Target.Points[i];
                var midPoint = (pointA + pointB) * 0.5f;
                var scrPoint = Camera.current.WorldToScreenPoint(matrix.MultiplyPoint(midPoint));

                if (GUI.Button(new Rect(scrPoint.x - 5.0f, Screen.height - scrPoint.y - 45.0f, 20.0f, 20.0f), "+") == true)
                {
                    Undo.RecordObject(Target, "Split Path");
                    Target.Points.Insert(i, midPoint); GUI.changed = true;
                }
            }
        }
        Handles.EndGUI();
    }
Esempio n. 25
0
    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);
                    }
                }
            }
        }
    }
Esempio n. 26
0
    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);
            }
        }
    }