Пример #1
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);
        }
    }
Пример #2
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;
                        }
                    }
                }
            }
        }
    }
Пример #3
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));
                }
            }
        }
    }
Пример #4
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);
        }
    }
Пример #5
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);
            }
        }
    }