/// <summary>
 /// Initializes the destructible properties.
 /// </summary>
 /// <param name="damageAmount">The amount of damage to apply to the hit object.</param>
 /// <param name="impactForce">The amount of force to apply to the hit object.</param>
 /// <param name="impactForceFrames">The number of frames to add the force to.</param>
 /// <param name="impactLayers">The layers that the projectile can impact with.</param>
 /// <param name="impactStateName">The name of the state to activate upon impact.</param>
 /// <param name="impactStateDisableTimer">The number of seconds until the impact state is disabled.</param>
 /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
 public void InitializeDestructibleProperties(float damageAmount, float impactForce, int impactForceFrames, LayerMask impactLayers, string impactStateName, float impactStateDisableTimer, SurfaceImpact surfaceImpact)
 {
     m_Destroyed               = false;
     m_DamageAmount            = damageAmount;
     m_ImpactForce             = impactForce;
     m_ImpactForceFrames       = impactForceFrames;
     m_ImpactLayers            = impactLayers;
     m_ImpactStateName         = impactStateName;
     m_ImpactStateDisableTimer = impactStateDisableTimer;
     // The SurfaceImpact may be set directly on the destructible prefab.
     if (m_SurfaceImpact == null)
     {
         m_SurfaceImpact = surfaceImpact;
     }
     if (m_TrailRenderer != null)
     {
         m_TrailRenderer.Clear();
         m_TrailRenderer.enabled = true;
     }
     if (m_ParticleSystem != null)
     {
         m_ParticleSystem.Play();
     }
     if (m_Collider != null)
     {
         m_Collider.enabled = false;
     }
     // The object may be reused and was previously stuck to a character.
     if (m_StickyCharacterLocomotion != null)
     {
         m_StickyCharacterLocomotion.RemoveSubCollider(m_Collider);
         m_StickyCharacterLocomotion = null;
     }
 }
예제 #2
0
        /// <summary>
        /// Internal method which tries to spawn the effect based on the RaycastHit and SurfaceImpact.
        /// </summary>
        /// <param name="hit">The RaycastHit which caused the SurfaceEffect to spawn.</param>
        /// <param name="collider">The collider of the object that was hit.</param>
        /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
        /// <param name="gravityDirection">The normalized direction of the character's gravity.</param>
        /// <param name="timeScale">The timescale of the character.</param>
        /// <param name="originator">The object which spawned the effect.</param>
        /// <returns>True if the effect was spawned.</returns>
        private bool SpawnEffectInternal(RaycastHit hit, Collider collider, SurfaceImpact surfaceImpact, Vector3 gravityDirection, float timeScale, GameObject originator)
        {
            SurfaceType surfaceType   = null;
            var         spawnDecals   = false;
            var         surfaceEffect = GetSurfaceEffect(hit, collider, surfaceImpact, ref surfaceType, ref spawnDecals);

            if (surfaceEffect == null)
            {
                return(false);
            }

            surfaceEffect.Spawn(hit, gravityDirection, timeScale, originator, spawnDecals);

            return(true);
        }
예제 #3
0
        /// <summary>
        /// The magic cast has collided with another object.
        /// </summary>
        /// <param name="hit">The raycast that caused the impact.</param>
        /// <param name="surfaceImpact">The type of particle that collided with the object.</param>
        private void MagicCastCollision(RaycastHit hit, SurfaceImpact surfaceImpact)
        {
            if (m_FlameParticle != null || (m_FlameImpact != null && m_FlameImpact != surfaceImpact))
            {
                return;
            }

            // A fireball has collided with the crate. Start the flame.
            var flamePrefab = ObjectPool.Instantiate(m_FlamePrefab, transform.position, transform.rotation);

            m_FlameParticle                   = flamePrefab.GetComponent <ParticleSystem>();
            m_FlameParticleAudioSource        = flamePrefab.GetCachedComponent <AudioSource>();
            m_FlameParticleAudioSource.volume = 1;
            m_DamageTrigger.enabled           = true;

            // The crate should be destroyed by the flame.
            ReduceHealth();
        }
예제 #4
0
        /// <summary>
        /// Returns the main SurfaceEffect which is used by the specified SurfaceImpact and SurfaceType.
        /// </summary>
        /// <param name="surfaceImpact">The SurfaceImpact used to lookup the SurfaceEffect.</param>
        /// <param name="surfaceType">The SurfaceType used to lookup the SurfaceEffect.</param>
        /// <returns>The main SurfaceEffect which is used by the specified SurfaceImpact and SurfaceType. Can be null.</returns>
        private SurfaceEffect GetPrimarySurfaceEffect(SurfaceImpact surfaceImpact, SurfaceType surfaceType)
        {
            if (surfaceImpact == null)
            {
                return(null);
            }

            // Get the SurfaceImpact based off of the SurfaceType.
            var surfaceImpactMap = GetSurfaceImpactMap(surfaceType);

            if (surfaceImpactMap == null || surfaceImpactMap.Count == 0)
            {
                return(null);
            }

            SurfaceEffect surfaceEffect;

            surfaceImpactMap.TryGetValue(surfaceImpact, out surfaceEffect);
            return(surfaceEffect);
        }
예제 #5
0
        /// <summary>
        /// Internal method which tries to spawn the effect based on the RaycastHit and SurfaceImpact.
        /// </summary>
        /// <param name="hit">The RaycastHit which caused the SurfaceEffect to spawn.</param>
        /// <param name="collider">The collider of the object that was hit.</param>
        /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
        /// <param name="gravityDirection">The normalized direction of the character's gravity.</param>
        /// <param name="timeScale">The timescale of the character.</param>
        /// <param name="footprintDirection">The direction that the footprint decal should face.</param>
        /// <param name="flipFootprint">Should the footprint decal be flipped?</param>
        /// <param name="originator">The object which spawned the effect.</param>
        /// <returns>True if the effect was spawned.</returns>
        private bool SpawnEffectInternal(RaycastHit hit, Collider collider, SurfaceImpact surfaceImpact, Vector3 gravityDirection, float timeScale, GameObject originator, Vector3 footprintDirection, bool flipFootprint)
        {
            SurfaceType surfaceType   = null;
            var         spawnDecals   = false;
            var         surfaceEffect = GetSurfaceEffect(hit, collider, surfaceImpact, ref surfaceType, ref spawnDecals);

            if (surfaceType == null || surfaceEffect == null)
            {
                return(false);
            }

            // Not all surfaces allow footprints - revert to the regular spawn if the surface doesn't allow it.
            if (surfaceType.AllowFootprints)
            {
                surfaceEffect.SpawnFootprint(hit, gravityDirection, timeScale, originator, spawnDecals, footprintDirection, flipFootprint);
            }
            else
            {
                surfaceEffect.Spawn(hit, gravityDirection, timeScale, originator, spawnDecals);
            }

            return(true);
        }
예제 #6
0
        /// <summary>
        /// Initializes the object. This will be called from an object creating the projectile (such as a weapon).
        /// </summary>
        /// <param name="velocity">The velocity to apply.</param>
        /// <param name="torque">The torque to apply.</param>
        /// <param name="damageProcessor">Processes the damage dealt to a Damage Target.</param>
        /// <param name="damageAmount">The amount of damage to apply to the hit object.</param>
        /// <param name="impactForce">The amount of force to apply to the hit object.</param>
        /// <param name="impactForceFrames">The number of frames to add the force to.</param>
        /// <param name="impactLayers">The layers that the projectile can impact with.</param>
        /// <param name="impactStateName">The name of the state to activate upon impact.</param>
        /// <param name="impactStateDisableTimer">The number of seconds until the impact state is disabled.</param>
        /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
        /// <param name="originator">The object that instantiated the trajectory object.</param>
        public virtual void Initialize(Vector3 velocity, Vector3 torque, DamageProcessor damageProcessor, float damageAmount, float impactForce, int impactForceFrames, LayerMask impactLayers,
                                       string impactStateName, float impactStateDisableTimer, SurfaceImpact surfaceImpact, GameObject originator)
        {
            InitializeDestructibleProperties(damageProcessor, damageAmount, impactForce, impactForceFrames, impactLayers, impactStateName, impactStateDisableTimer, surfaceImpact);

            base.Initialize(velocity, torque, originator);
        }
예제 #7
0
 /// <summary>
 /// Returns the SurfaceEffect based on the RaycastHit and SurfaceImpact.
 /// </summary>
 /// <param name="hit">The RaycastHit which caused the SurfaceEffect to spawn.</param>
 /// <param name="collider">The collider of the object that was hit.</param>
 /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
 /// <param name="surfaceType">The SurfaceType used to get the SurfaceEffect.</param>
 /// <param name="spawnDecals">True if the SurfaceEffect can spawn decals.</param>
 /// <returns>The SurfaceEffect based on the RaycastHit and SurfaceImpact. Can be null.</returns>
 private SurfaceEffect GetSurfaceEffect(RaycastHit hit, Collider collider, SurfaceImpact surfaceImpact, ref SurfaceType surfaceType, ref bool spawnDecals)
 {
     surfaceType = GetSurfaceType(hit, collider);
     spawnDecals = ShouldSpawnDecals(collider);
     return(GetSurfaceEffect(surfaceImpact, ref surfaceType, ref spawnDecals));
 }
예제 #8
0
 /// <summary>
 /// Tries to spawn the effect based on the RaycastHit and SurfaceImpact.
 /// </summary>
 /// <param name="hit">The RaycastHit which caused the SurfaceEffect to spawn.</param>
 /// <param name="collider">The collider of the object that was hit.</param>
 /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
 /// <param name="gravityDirection">The normalized direction of the character's gravity.</param>
 /// <param name="timeScale">The timescale of the character.</param>
 /// <param name="originator">The object which spawned the effect.</param>
 /// <param name="footprintDirection">The direction that the footprint decal should face.</param>
 /// <param name="flipFootprint">Should the footprint decal be flipped?</param>
 /// <returns>True if the effect was spawned.</returns>
 public static bool SpawnEffect(RaycastHit hit, Collider collider, SurfaceImpact surfaceImpact, Vector3 gravityDirection, float timeScale, GameObject originator, Vector3 footprintDirection, bool flipFootprint)
 {
     return(Instance.SpawnEffectInternal(hit, collider, surfaceImpact, gravityDirection, timeScale, originator, footprintDirection, flipFootprint));
 }
예제 #9
0
 /// <summary>
 /// Tries to spawn the effect based on the RaycastHit and SurfaceImpact.
 /// </summary>
 /// <param name="hit">The RaycastHit which caused the SurfaceEffect to spawn.</param>
 /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
 /// <param name="gravityDirection">The normalized direction of the character's gravity.</param>
 /// <param name="timeScale">The timescale of the character.</param>
 /// <param name="originator">The object which spawned the effect.</param>
 /// <returns>True if the effect was spawned.</returns>
 public static bool SpawnEffect(RaycastHit hit, SurfaceImpact surfaceImpact, Vector3 gravityDirection, float timeScale, GameObject originator)
 {
     return(Instance.SpawnEffectInternal(hit, hit.collider, surfaceImpact, gravityDirection, timeScale, originator));
 }
예제 #10
0
        /// <summary>
        /// Returns the SurfaceEffect for the specified SurfaceImpact and SurfaceType.
        /// </summary>
        /// <param name="surfaceImpact">The SurfaceImpact used to lookup the SurfaceEffect.</param>
        /// <param name="surfaceType">The SurfaceType used to lookup the SurfaceEffect.</param>
        /// <param name="spawnDecals">True if the SurfaceEffect can spawn decals.</param>
        /// <returns>The SurfaceEffect for the specified SurfaceImpact and SurfaceType. Can be null.</returns>
        private SurfaceEffect GetSurfaceEffect(SurfaceImpact surfaceImpact, ref SurfaceType surfaceType, ref bool spawnDecals)
        {
            var usingFallbackImpact  = false;
            var usingFallbackSurface = false;

            // If there is no SurfaceImpact then use the fallback.
            if (surfaceImpact == null && m_FallbackSurfaceImpact != null)
            {
                surfaceImpact       = m_FallbackSurfaceImpact;
                usingFallbackImpact = true;
            }

            // The SurfaceImpact must exist.
            if (surfaceImpact == null)
            {
                return(null);
            }

            // If there is no SurfaceType then use the fallback.
            if (surfaceType == null && m_FallbackSurfaceType != null)
            {
                surfaceType          = m_FallbackSurfaceType;
                usingFallbackSurface = true;
            }

            // The SurfaceType must exist and be valid.
            if (surfaceType == null || surfaceType.ImpactEffects == null || surfaceType.ImpactEffects.Length == 0)
            {
                return(null);
            }

            var surfaceEffect = GetPrimarySurfaceEffect(surfaceImpact, surfaceType);

            // If the SurfaceEffect is null and the fallback surface isn't being used then the scene does not contain the ItemIdentifier. Use the fallback.
            if (surfaceEffect == null && !usingFallbackSurface)
            {
                surfaceType   = m_FallbackSurfaceType;
                surfaceEffect = GetPrimarySurfaceEffect(surfaceImpact, surfaceType);
            }

            // If the SurfaceEffect is null then the detected surface does not recognize the ItemIdentifier so try again with the SurfaceManager's fallback ItemIdentifier.
            if (surfaceEffect == null)
            {
                surfaceEffect = GetPrimarySurfaceEffect(m_FallbackSurfaceImpact, surfaceType);
                // If the SurfaceEffect is still null then nothing more can be done.
                if (surfaceEffect == null)
                {
                    return(null);
                }
            }

            // A SurfaceEffect was found! Determine if the decal can be spawned.
            if (spawnDecals && surfaceEffect.Decals.Length > 0)
            {
                if (usingFallbackSurface || usingFallbackImpact)
                {
                    spawnDecals = m_FallbackAllowDecals;
                }
            }
            else
            {
                spawnDecals = false;
            }

            return(surfaceEffect);
        }
예제 #11
0
        /// <summary>
        /// Initializes the object. This will be called from an object creating the projectile (such as a weapon).
        /// </summary>
        /// <param name="velocity">The velocity to apply.</param>
        /// <param name="torque">The torque to apply.</param>
        /// <param name="damageProcessor">Processes the damage dealt to a Damage Target.</param>
        /// <param name="damageAmount">The amount of damage to apply to the hit object.</param>
        /// <param name="impactForce">The amount of force to apply to the hit object.</param>
        /// <param name="impactForceFrames">The number of frames to add the force to.</param>
        /// <param name="impactLayers">The layers that the projectile can impact with.</param>
        /// <param name="impactStateName">The name of the state to activate upon impact.</param>
        /// <param name="impactStateDisableTimer">The number of seconds until the impact state is disabled.</param>
        /// <param name="surfaceImpact">A reference to the Surface Impact triggered when the object hits an object.</param>
        /// <param name="originator">The object that instantiated the trajectory object.</param>
        public override void Initialize(Vector3 velocity, Vector3 torque, DamageProcessor damageProcessor, float damageAmount, float impactForce, int impactForceFrames, LayerMask impactLayers,
                                        string impactStateName, float impactStateDisableTimer, SurfaceImpact surfaceImpact, GameObject originator)
        {
            // The projectile can deactivate after it comes in contact with another object or after a specified amount of time. Do the scheduling here to allow
            // it to activate after a set amount of time.
            if (m_Lifespan > 0)
            {
                m_ScheduledDeactivation = SchedulerBase.Schedule(m_Lifespan, Deactivate);
            }

            base.Initialize(velocity, torque, damageProcessor, damageAmount, impactForce, impactForceFrames, impactLayers, impactStateName, impactStateDisableTimer, surfaceImpact, originator);
        }