Exemplo n.º 1
0
        /// <summary>
        /// Generates a bullet hole decal.
        /// </summary>
        /// <param name="surface">The surface properties of the hit object.</param>
        /// <param name="hitInfo">The information about the projectile impact such as position and rotation.</param>
        public virtual void CreateBulletDecal(SurfaceIdentifier surface, RaycastHit hitInfo)
        {
            SurfaceType surfaceType = surface.GetSurfaceType(hitInfo.point, hitInfo.triangleIndex);

            if (surface && surfaceType)
            {
                if (surface.AllowDecals(hitInfo.triangleIndex) && m_MaxDecals > 0)
                {
                    Material material = surfaceType.GetRandomDecalMaterial();
                    if (material)
                    {
                        GameObject decal = new GameObject("BulletMark_Decal");
                        decal.transform.position = hitInfo.point;
                        decal.transform.rotation = Quaternion.FromToRotation(Vector3.back, hitInfo.normal);

                        decal.transform.Rotate(new Vector3(0, 0, Random.Range(0, 360)));

                        float scale = surfaceType.GetRandomDecalSize() / 5;
                        decal.transform.localScale = new Vector3(scale, scale, scale);

                        decal.transform.parent = hitInfo.transform;

                        DecalPresets decalPresets = new DecalPresets()
                        {
                            maxAngle     = 60,
                            pushDistance = 0.009f + RegisterDecal(decal, scale),
                            material     = material
                        };

                        Decal d = decal.AddComponent <Decal>();
                        d.Calculate(decalPresets, hitInfo.collider.gameObject);
                    }
                }

                GameObject particle = surfaceType.GetRandomImpactParticle();
                if (particle)
                {
                    Instantiate(particle, hitInfo.point, Quaternion.FromToRotation(Vector3.up, hitInfo.normal));
                }

                AudioClip clip = surfaceType.GetRandomImpactSound();
                if (clip)
                {
                    AudioManager.Instance.PlayClipAtPoint(clip, hitInfo.point, 1, 25, surfaceType.BulletImpactVolume);
                }
            }
        }