static TerrainUtility() { for (var i = 0; i < TerrainCastHitCache.Length; ++i) { TerrainCastHitCache[i] = new TerrainCastHit(default(RaycastHit2D)); } }
/// <summary> /// Returns whether the specified raycast hit can be collided with based on the source's /// collision info and the transform's terrain properties. /// </summary> /// <param name="hit">The specified raycast hit.</param> /// <returns></returns> private static bool TransformSelector(TerrainCastHit hit) { var platformTrigger = hit.Collider.GetComponent <PlatformTrigger>(); if (platformTrigger != null) { return(platformTrigger.IsSolid(hit)); } // Otherwise if there are any area triggers, the object is not solid if (hit.Collider.GetComponent <AreaTrigger>() != null) { return(false); } return(true); }
/// <summary> /// Notifies all platform triggers eligible to the specified transform about a collision. /// </summary> /// <param name="transform">The specified transform.</param> /// <param name="hit">The collision data to send.</param> /// <param name="notifySurfaceCollision">Whether to also notify the triggers of a surface collision.</param> /// <returns></returns> public static bool NotifyPlatformCollision(Transform transform, TerrainCastHit hit, bool notifySurfaceCollision = false, List <PlatformTrigger> platformTriggers = null) { if (transform == null || !hit) { return(false); } if (platformTriggers != null) { for (var i = 0; i < platformTriggers.Count; ++i) { var platformTrigger = platformTriggers[i]; platformTrigger.NotifyCollision(hit); if (notifySurfaceCollision) { platformTrigger.NotifySurfaceCollision(hit); } } return(true); } GetTriggers(transform, NotifyPlatformTriggerCache); if (NotifyPlatformTriggerCache.Count == 0) { return(false); } for (var i = 0; i < NotifyPlatformTriggerCache.Count; ++i) { var platformTrigger = NotifyPlatformTriggerCache[i]; platformTrigger.NotifyCollision(hit); if (notifySurfaceCollision) { platformTrigger.NotifySurfaceCollision(hit); } } return(true); }