Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);
        }
Exemple #4
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));
 }
Exemple #5
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);
        }