/// <summary> /// Gather collider information from 3D <see cref="BoxCollider"/> component. /// </summary> /// <param name="info">Collider information instance.</param> /// <param name="collider">Component which resides somewhere within tile.</param> private void GatherInfo_BoxCollider3D(ColliderInfo info, BoxCollider collider) { var tileToSystemMatrix = this.worldToSystem * collider.transform.localToWorldMatrix; info.IsTrigger = collider.isTrigger; info.Material = collider.sharedMaterial; info.Collider = collider; info.Bounds = SpaceToSpace(BoxBounds.FromBounds(collider.center, collider.size), tileToSystemMatrix); }
/// <summary> /// Gather hypothetical collider information from solid flag. /// </summary> /// <param name="info">Collider information instance.</param> private void GatherInfo_SolidFlag(ColliderInfo info) { info.IsTrigger = false; // Bounds of 2D colliders need to be consistent. Vector3 boundsSize = this.system.CellSize; if (info.Type == ColliderType.BoxCollider2D) { boundsSize.z = 1f; } info.Bounds = BoxBounds.FromBounds(this.system.LocalPositionFromTileIndex(info.Row, info.Column), boundsSize); }
/// <summary> /// Gather collider information from <see cref="BoxCollider2D"/> component. /// </summary> /// <param name="info">Collider information instance.</param> /// <param name="collider">Component which resides somewhere within tile.</param> private void GatherInfo_BoxCollider2D(ColliderInfo info, BoxCollider2D collider) { var tileToSystemMatrix = this.worldToSystem * collider.transform.localToWorldMatrix; // Bounds of 2D colliders need to be consistent. Vector3 boundsSize = collider.size; boundsSize.z = 1f; Vector3 center = collider.offset; info.IsTrigger = collider.isTrigger; info.Material = collider.sharedMaterial; info.Collider = collider; info.Bounds = SpaceToSpace(BoxBounds.FromBounds(center, boundsSize), tileToSystemMatrix); }