Ejemplo n.º 1
0
        /// <summary>
        /// Assign the static variables.
        /// </summary>
        private void OnEnable()
        {
            s_Instance = this;
#if UNITY_EDITOR || DLL_RELEASE
            m_Initialized = true;
#endif
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The destructable object has collided itself. Add any effects.
        /// </summary>
        /// <param name="collisionTransform">The collision object that the destructable collided with. Can be null.</param>
        /// <param name="collisionPoint">The point of destruction.</param>
        /// <param name="collisionNormal">The normal at the destruction point.</param>
        private void AddCollisionEffects(Transform collisionTransform, Vector3 collisionPoint, Vector3 collisionNormal)
        {
            var hitRotation = Quaternion.LookRotation(collisionNormal);

            Object retrievedObject = null;

            // Don't add the decal if the hit layer doesnt allow decals (such as other characters).
            if ((collisionTransform == null || DecalManager.CanAddDecal(collisionTransform.gameObject.layer)))
            {
                GameObject decal;
                if (collisionTransform != null && ObjectManager.ObjectForItem(collisionTransform.tag, m_ParentItemType, ObjectManager.ObjectCategory.Decal, ref retrievedObject))
                {
                    decal = retrievedObject as GameObject;
                }
                else
                {
                    decal = m_DefaultDecal;
                }
                if (decal != null)
                {
                    // Apply a decal to the hit point. Offset the decal by a small amount so it doesn't interset with the object hit.
                    DecalManager.Add(decal, collisionPoint + collisionNormal * 0.02f, decal.transform.rotation * hitRotation, (collisionTransform == null ? null : collisionTransform));
                }
            }

            // Spawn dust particle effect.
            GameObject dust;

            if (collisionTransform != null && ObjectManager.ObjectForItem(collisionTransform.tag, m_ParentItemType, ObjectManager.ObjectCategory.Dust, ref retrievedObject))
            {
                dust = retrievedObject as GameObject;
            }
            else
            {
                dust = m_DefaultDust;
            }
            if (dust != null)
            {
                ObjectPool.Instantiate(dust, collisionPoint, dust.transform.rotation * hitRotation);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Remove the decal from the DecalManager.
 /// </summary>
 private void RemoveDecal()
 {
     DecalManager.Remove(m_Renderer);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// The hitscan has hit an object, add any hitscan effects.
        /// </summary>
        /// <param name="hitTransform">The transform that was hit.</param>
        /// <param name="hitPoint">The hit point.</param>
        /// <param name="hitNormal">The normal of the transform at the hit point.</param>
        private void AddHitscanEffects(Transform hitTransform, Vector3 hitPoint, Vector3 hitNormal)
        {
            var hitRotation = Quaternion.LookRotation(hitNormal);

            Object retrievedObject = null;

            // Don't add the decal if the hit layer doesnt allow decals (such as other characters).
            if (DecalManager.CanAddDecal(hitTransform.gameObject.layer))
            {
                GameObject decal;
                if (ObjectManager.ObjectForItem(hitTransform.tag, m_ConsumableItemType, ObjectManager.ObjectCategory.Decal, ref retrievedObject))
                {
                    decal = retrievedObject as GameObject;
                }
                else
                {
                    decal = m_DefaultHitscanDecal;
                }
                if (decal != null)
                {
                    // Apply a decal to the hit point. Offset the decal by a small amount so it doesn't interset with the object hit.
                    DecalManager.Add(decal, hitPoint + hitNormal * 0.02f, decal.transform.rotation * hitRotation, hitTransform);
                }
            }

            // Spawn a dust particle effect at the hit point.
            GameObject dust;

            if (ObjectManager.ObjectForItem(hitTransform.tag, m_ConsumableItemType, ObjectManager.ObjectCategory.Dust, ref retrievedObject))
            {
                dust = retrievedObject as GameObject;
            }
            else
            {
                dust = m_DefaultHitscanDust;
            }
            if (dust != null)
            {
                ObjectPool.Instantiate(dust, hitPoint, dust.transform.rotation * hitRotation);
            }

            // Spawn a spark particle effect at the hit point.
            GameObject spark;

            if (ObjectManager.ObjectForItem(hitTransform.tag, m_ConsumableItemType, ObjectManager.ObjectCategory.Spark, ref retrievedObject))
            {
                spark = retrievedObject as GameObject;
            }
            else
            {
                spark = m_DefaultHitscanDust;
            }
            if (spark != null)
            {
                ObjectPool.Instantiate(spark, hitPoint, spark.transform.rotation * hitRotation);
            }

            // Play a sound at the hit point.
            AudioClip audioClip;

            if (ObjectManager.ObjectForItem(hitTransform.tag, m_ConsumableItemType, ObjectManager.ObjectCategory.Audio, ref retrievedObject))
            {
                audioClip = retrievedObject as AudioClip;
            }
            else
            {
                audioClip = m_DefaultHitscanImpactSound;
            }
            if (audioClip != null)
            {
                AudioSource.PlayClipAtPoint(audioClip, hitPoint);
            }

            // Spawn a tracer which moves to the hit point.
            if (m_Tracer != null)
            {
                AddHitscanTracer(hitPoint);
            }
        }