Ejemplo n.º 1
0
    /// <summary>
    /// Attempts to perform a jump down from a one way platform
    /// </summary>
    /// <returns></returns>
    public bool AttemptDropDownJump()
    {
        if (CurrentMovementType != EMovementType.CROUCH)
        {
            return(false);
        }
        EHBounds2D ColliderBounds = AssociatedCollider.GetBounds();
        EHRect2D   CastBox        = new EHRect2D();

        CastBox.RectPosition = ColliderBounds.MinBounds + Vector2.down * .1f;
        CastBox.RectSize     = new Vector2(ColliderBounds.MaxBounds.x - ColliderBounds.MinBounds.x, .1f);
        bool bIsUnderOneWayPlatform = false;

        if (EHPhysicsManager2D.BoxCastAll2D(ref CastBox, EHBaseCollider2D.EColliderType.STATIC, out EHBaseCollider2D[] ColliderWeHitList, LayerMask.GetMask(ENVIRONMENT_LAYER)))
        {
            foreach (EHBaseCollider2D ColliderWeHit in ColliderWeHitList)
            {
                if (!(ColliderWeHit is EHOneSidedBoxCollider2D))
                {
                    return(false);
                }
                else
                {
                    bIsUnderOneWayPlatform = true;
                }
            }
        }
        return(bIsUnderOneWayPlatform);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Returns a list of all colliders that are intersected
    /// </summary>
    /// <param name="BoxToCast"></param>
    /// <param name="ColliderType"></param>
    /// <param name="HitColliderList"></param>
    /// <param name="LayerMask"></param>
    /// <returns></returns>
    public static bool BoxCastAll2D(ref EHRect2D BoxToCast, EHBaseCollider2D.EColliderType ColliderType, out EHBaseCollider2D[] HitColliderList, int LayerMask)
    {
        if (CachedInstance == null)
        {
            Debug.LogWarning("The game overseer has not been initialized");
            HitColliderList = null;
            return(false);
        }
        List <EHBaseCollider2D> BaseColliderList = new List <EHBaseCollider2D>();

        foreach (EHBaseCollider2D Collider2D in CachedInstance.ColliderComponentDictionary[ColliderType])
        {
            if (Collider2D.gameObject.activeInHierarchy && (LayerMask & 1 << Collider2D.gameObject.layer) != 0)
            {
                if (Collider2D.IsOverlappingRect2D(BoxToCast))
                {
                    BaseColliderList.Add(Collider2D);
                }
            }
        }

        HitColliderList = BaseColliderList.ToArray();
        if (BaseColliderList.Count > 0)
        {
            return(true);
        }

        return(false);
    }
Ejemplo n.º 3
0
    public static bool BoxCast2D(ref EHRect2D BoxToCast, EHBaseCollider2D.EColliderType ColliderType, out EHBaseCollider2D HitCollider, int LayerMask = 0)
    {
        if (CachedInstance == null)
        {
            Debug.LogWarning("Game Overseer not initialized");
            HitCollider = null;
            return(false);
        }
        if (!CachedInstance.ColliderComponentDictionary.ContainsKey(ColliderType))
        {
            HitCollider = null;
            return(false);
        }

        foreach (EHBaseCollider2D Collider in CachedInstance.ColliderComponentDictionary[ColliderType])
        {
            if (Collider.gameObject.activeInHierarchy && (LayerMask & 1 << Collider.gameObject.layer) != 0)
            {
                if (Collider.IsOverlappingRect2D(BoxToCast))
                {
                    HitCollider = Collider;
                    return(true);
                }
            }
        }
        HitCollider = null;
        return(false);
    }
Ejemplo n.º 4
0
 public override bool IsOverlappingRect2DSweep(EHRect2D Rect)
 {
     if (ColliderType == EColliderType.PHYSICS)
     {
         return(PhysicsSweepGeometry.IsOverlappingRect(Rect));
     }
     return(false);
 }
Ejemplo n.º 5
0
 public bool IsOverlappingRect(EHRect2D Other)
 {
     if (this.MinBounds.x >= Other.MaxBounds.x || Other.MinBounds.x >= this.MaxBounds.x)
     {
         return(false);
     }
     if (this.MinBounds.y >= Other.MaxBounds.y || Other.MinBounds.y >= this.MaxBounds.y)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 6
0
    /// <summary>
    /// Checks to see if you have enough room to stand and then will change the state to stand if valid
    /// </summary>
    /// <returns></returns>
    private bool AttemptStand()
    {
        EHRect2D CastBox = new EHRect2D();

        CastBox.RectPosition = AssociatedCollider.GetBounds().MinBounds;
        CastBox.RectSize     = AssociatedCollider.DefaultColliderSize;
        EHBaseCollider2D HitCollider;

        if (!EHPhysicsManager2D.BoxCast2D(ref CastBox, out HitCollider, LayerMask.GetMask(ENVIRONMENT_LAYER)))
        {
            SetMovementType(EMovementType.STANDING);
            return(true);
        }
        return(false);
    }
Ejemplo n.º 7
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
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Runs a box cast for every collider that is in our scene.
    ///
    /// NOTE: Keep in mind this will ignore colliders that are labled triggers
    /// </summary>
    /// <param name="BoxToCast"></param>
    /// <param name="HitCollider"></param>
    /// <param name="LayerMask"></param>
    /// <returns></returns>
    public static bool BoxCast2D(ref EHRect2D BoxToCast, out EHBaseCollider2D HitCollider, int LayerMask = 0)
    {
        if (CachedInstance == null)
        {
            Debug.LogWarning("Game Overseer not initialized");
            HitCollider = null;
            return(false);
        }

        foreach (KeyValuePair <EHBaseCollider2D.EColliderType, HashSet <EHBaseCollider2D> > ColliderSet in CachedInstance.ColliderComponentDictionary)
        {
            if (BoxCast2D(ref BoxToCast, ColliderSet.Key, out HitCollider, LayerMask))
            {
                return(true);
            }
        }
        HitCollider = null;
        return(false);
    }
Ejemplo n.º 9
0
    public float GetShortestDistance(EHRect2D OtherRect)
    {
        bool Left   = OtherRect.MaxBounds.x < MinBounds.x;
        bool Right  = MaxBounds.x < OtherRect.MinBounds.x;
        bool Bottom = OtherRect.MaxBounds.y < MinBounds.y;
        bool Top    = MaxBounds.y < OtherRect.MinBounds.y;

        if (Top && Left)
        {
            return(Vector2.Distance(new Vector2(MinBounds.x, MaxBounds.y), new Vector2(OtherRect.MaxBounds.x, OtherRect.MinBounds.y)));
        }
        else if (Left && Bottom)
        {
            return(Vector2.Distance(MinBounds, OtherRect.MaxBounds));
        }
        else if (Bottom && Right)
        {
            return(Vector2.Distance(new Vector2(MaxBounds.x, MinBounds.y), new Vector2(OtherRect.MinBounds.x, OtherRect.MaxBounds.y)));
        }
        else if (Right && Top)
        {
            return(Vector2.Distance(MaxBounds, OtherRect.MinBounds));
        }
        else if (Left)
        {
            return(OtherRect.MaxBounds.x - MinBounds.x);
        }
        else if (Right)
        {
            return(MaxBounds.x - OtherRect.MinBounds.x);
        }
        else if (Bottom)
        {
            return(MinBounds.y - OtherRect.MaxBounds.y);
        }
        else if (Top)
        {
            return(OtherRect.MinBounds.y - MaxBounds.y);
        }
        return(0);
    }
Ejemplo n.º 10
0
    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;
        }
    }
Ejemplo n.º 11
0
 protected override void Awake()
 {
     base.Awake();
     PreviousRectGeometry = RectGeometry;
     DefaultColliderSize  = ColliderSize;
 }
Ejemplo n.º 12
0
 public override bool IsOverlappingRect2D(EHRect2D Rect)
 {
     return(RectGeometry.IsOverlappingRect(Rect));
 }
Ejemplo n.º 13
0
 public static void DebugDrawRect(EHRect2D Rect)
 {
     DebugDrawRect(Rect, Color.red);
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Returns whether the Rect that is passed in intersects with the sweep of our collider.
 /// Sweep of our collider is the collision between the previous and current bounds
 /// </summary>
 /// <param name="Rect"></param>
 /// <returns></returns>
 public abstract bool IsOverlappingRect2DSweep(EHRect2D Rect);