public override void UpdateColliderBounds(bool bUpdatePreviousBounds)
    {
        if (bUpdatePreviousBounds)
        {
            PreviousRectGeometry = RectGeometry;
            if (ColliderType == EColliderType.PHYSICS)
            {
                PreviousRectGeometry.RectPosition += BUFFER;
                PreviousRectGeometry.RectSize     -= (2 * BUFFER);
            }
        }

        Vector2 RectSize      = ColliderSize * transform.localScale;
        Vector2 WorldPosition = transform.position;
        Vector2 RectPosition;

        if (bIsCharacterCollider)
        {
            RectPosition = ColliderOffset + WorldPosition - (Vector2.right * RectSize.x / 2);
        }
        else
        {
            RectPosition = ColliderOffset + WorldPosition - (RectSize / 2);
        }
        RectGeometry.RectSize     = RectSize;
        RectGeometry.RectPosition = RectPosition;

        if (ColliderType == EColliderType.PHYSICS)//Create a sweep bounds so that we do not phase through collisions when going at top speeds
        {
            EHBounds2D RectBounds     = RectGeometry.GetBounds();
            EHBounds2D PreviousBounds = PreviousRectGeometry.GetBounds();

            Vector2 MinBounds = new Vector2(Mathf.Min(RectBounds.MinBounds.x, PreviousBounds.MinBounds.x), Mathf.Min(RectBounds.MinBounds.y, PreviousBounds.MinBounds.y));
            Vector2 MaxBounds = new Vector2(Mathf.Max(RectBounds.MaxBounds.x, PreviousBounds.MaxBounds.x), Mathf.Max(RectBounds.MaxBounds.y, PreviousBounds.MaxBounds.y));

            PhysicsSweepGeometry.RectPosition = MinBounds;
            PhysicsSweepGeometry.RectSize     = MaxBounds - MinBounds;
        }
    }
Beispiel #2
0
    public static void DebugDrawRect(EHRect2D Rect, Color DebugColor, bool Fill = false)
    {
#if UNITY_EDITOR
        EHBounds2D Bounds    = Rect.GetBounds();
        Rect       UnityRect = new Rect(Bounds.MinBounds, Rect.RectSize);
        Color      FillColor = DebugColor;

        if (Fill)
        {
            FillColor.a *= .25f;
        }
        else
        {
            FillColor.a = 0;
        }
        UnityEditor.Handles.DrawSolidRectangleWithOutline(UnityRect, FillColor, DebugColor);
#endif
    }