示例#1
0
    public void AddCollisionComponent(EHBaseCollider2D ColliderComponent)
    {
        if (ColliderComponent == null)
        {
            Debug.LogWarning("A null collider was passed in to our physics manager. It has not been added...");
            return;
        }

        if (ColliderComponent.GetIsTriggerCollider())
        {
            if (!TriggerColliderSet.Add(ColliderComponent))
            {
                Debug.LogWarning("The trigger component that was passed in has already been added to our physics manager...");
            }

            return;
        }

        if (!ColliderComponentDictionary.ContainsKey(ColliderComponent.ColliderType))
        {
            Debug.LogWarning("Collider type was not added to dictionary. Please remember to add it in the Physics Manager Constructor");
            return;
        }

        if (!ColliderComponentDictionary[ColliderComponent.ColliderType].Add(ColliderComponent))
        {
            Debug.LogWarning("The Collider component has already been added to our physics manager");
            return;
        }
    }
示例#2
0
    public void RemoveCollisionComponent(EHBaseCollider2D ColliderComponent)
    {
        if (ColliderComponent == null)
        {
            Debug.LogWarning("A null collider was passed into our physics manager");
            return;
        }

        if (ColliderComponent.GetIsTriggerCollider())
        {
            if (!TriggerColliderSet.Remove(ColliderComponent))
            {
                Debug.LogWarning("The trigger you are attempting to remove was not found in our physics manager. Perhaps you have already removed it?");
            }

            return;
        }

        if (!ColliderComponentDictionary.ContainsKey(ColliderComponent.ColliderType))
        {
            Debug.LogWarning("Collider type was not added to dictionary. Please remember to add it in the Physics Manager Constructor");
            return;
        }

        if (!ColliderComponentDictionary[ColliderComponent.ColliderType].Remove(ColliderComponent))
        {
            Debug.LogWarning("This collider component was not found in our manager");
            return;
        }
    }
示例#3
0
 private void OnCharacterCollision(FHitData HitData)
 {
     if (HitData.HitDirection.x > 0)
     {
         ColliderWeAreOn = HitData.OtherCollider;
         if (!CharacterMovement.GetIsFacingLeft())
         {
             CharacterMovement.SetIsFacingLeft(true, true);
         }
     }
     else if (HitData.HitDirection.x < 0)
     {
         ColliderWeAreOn = HitData.OtherCollider;
         if (CharacterMovement.GetIsFacingLeft())
         {
             CharacterMovement.SetIsFacingLeft(false, true);
         }
     }
     else
     {
         return;
     }
     CachedWallDirection = Mathf.Sign(ColliderWeAreOn.transform.position.x - this.transform.position.x);
     CharacterAnim.SetBool(ANIM_WALL_HOLD, true);
 }
    private void ReverseHitData(ref FHitData HitData)
    {
        EHBaseCollider2D OriginalOwning = HitData.OwningCollider;

        HitData.OwningCollider = HitData.OtherCollider;
        HitData.OtherCollider  = OriginalOwning;
        HitData.HitDirection  *= -1f;
    }
示例#5
0
 private void OnCharacterCollisionEnd(FHitData HitData)
 {
     if (HitData.OtherCollider == ColliderWeAreOn)
     {
         ColliderWeAreOn = null;
         CharacterAnim.SetBool(ANIM_WALL_HOLD, false);
     }
 }
 protected bool MatchesOverlappingHitData(EHBaseCollider2D OtherCollider, ref FHitData HitData)
 {
     if (!OverlappingColliders.ContainsKey(OtherCollider))
     {
         return(false);
     }
     return(OverlappingColliders[OtherCollider].HitDirection != HitData.HitDirection);
 }
 protected void HitCollisionStay(EHBaseCollider2D OtherCollider, FHitData HitData)
 {
     if (OtherCollider != null)
     {
         OnCollision2DStay?.Invoke(HitData);
         ReverseHitData(ref HitData);
         OtherCollider.OnCollision2DStay?.Invoke(HitData);
     }
 }
示例#8
0
 public override float GetShortestDistanceFromPreviousPosition(EHBaseCollider2D OtherCollider)
 {
     switch (OtherCollider.GetColliderShape())
     {
     case EHGeometry.ShapeType.Rect2D:
         return(PreviousRectGeometry.GetShortestDistance(((EHBox2DCollider)OtherCollider).RectGeometry));
     }
     return(-1);
 }
示例#9
0
 protected override bool IsColliderOverlapping(EHBaseCollider2D OtherCollider)
 {
     switch (OtherCollider.GetColliderShape())
     {
     case EHGeometry.ShapeType.Rect2D:
         return(IsOverlappingRect2D(((EHBox2DCollider)OtherCollider).RectGeometry));
     }
     return(false);
 }
示例#10
0
    public override bool PushOutCollider(EHBaseCollider2D ColliderToPushOut)
    {
        EHBox2DCollider OtherRectCollier = (EHBox2DCollider)ColliderToPushOut;

        if (OtherRectCollier == null)
        {
            return(false);
        }

        if (RectGeometry.IsOverlappingRect(OtherRectCollier.PhysicsSweepGeometry))
        {
            FHitData HitData = new FHitData();
            HitData.OwningCollider = this;
            HitData.OtherCollider  = ColliderToPushOut;

            EHBounds2D ThisCurrentBounds   = RectGeometry.GetBounds();
            EHBounds2D OtherCurrentBounds  = OtherRectCollier.RectGeometry.GetBounds();
            EHBounds2D ThisPreviousBounds  = PreviousRectGeometry.GetBounds();
            EHBounds2D OtherPreviousBounds = OtherRectCollier.PreviousRectGeometry.GetBounds();

            Vector2 RightUpOffset    = ThisCurrentBounds.MaxBounds - OtherCurrentBounds.MinBounds;
            Vector2 LeftBottomOffset = ThisCurrentBounds.MinBounds - OtherCurrentBounds.MaxBounds;



            if (ThisPreviousBounds.MaxBounds.y < OtherPreviousBounds.MinBounds.y && RightUpOffset.y > 0 && (CollisionMask & (byte)ECollisionDirection.UP) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.up * RightUpOffset.y;
                HitData.HitDirection = Vector2.down;
            }
            else if (ThisPreviousBounds.MaxBounds.x < OtherPreviousBounds.MinBounds.x && RightUpOffset.x > 0 && (CollisionMask & (byte)ECollisionDirection.RIGHT) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.right * RightUpOffset.x;
                HitData.HitDirection = Vector2.left;
            }
            else if (ThisPreviousBounds.MinBounds.x > OtherPreviousBounds.MaxBounds.x && LeftBottomOffset.x < 0 && (CollisionMask & (byte)ECollisionDirection.LEFT) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.right * LeftBottomOffset.x;
                HitData.HitDirection = Vector2.right;
            }
            else if (ThisPreviousBounds.MinBounds.y > OtherPreviousBounds.MaxBounds.y && LeftBottomOffset.y < 0 && (CollisionMask & (byte)ECollisionDirection.DOWN) != 0)
            {
                ColliderToPushOut.transform.position += Vector3.up * LeftBottomOffset.y;
                HitData.HitDirection = Vector2.up;
            }

            if (!ContainOverlappingCollider(ColliderToPushOut) || MatchesOverlappingHitData(ColliderToPushOut, ref HitData))
            {
                AddColliderToHitSet(ColliderToPushOut, HitData);
            }

            HitCollisionStay(ColliderToPushOut, HitData);

            return(true);
        }
        return(false);
    }
示例#11
0
    protected virtual void OnDestroy()
    {
        EHBaseCollider2D BaseCollider = GetComponent <EHBaseCollider2D>();

        if (BaseCollider)
        {
            BaseCollider.OnCollision2DBegin -= OnEHCollisionEnter;
        }
    }
示例#12
0
 /// <summary>
 /// This should be called anytime we end a collision with another collider
 /// </summary>
 /// <param name="OtherCollider"></param>
 protected void RemoveColliderFromHitSet(EHBaseCollider2D OtherCollider, FHitData HitData)
 {
     if (OtherCollider != null && OverlappingColliders.Remove(OtherCollider))
     {
         OtherCollider.OverlappingColliders.Remove(this);
         OnCollision2DEnd?.Invoke(HitData);
         ReverseHitData(ref HitData);
         OtherCollider.OnCollision2DEnd?.Invoke(HitData);
     }
 }
示例#13
0
    private void Awake()
    {
        BaseGameOverseer.Instance.PhysicsManager.AddPhysicsComponent(this);
        EHBaseCollider2D AttachedCollider = GetComponent <EHBaseCollider2D>();

        if (AttachedCollider)
        {
            AttachedCollider.OnCollision2DStay += OnEHCollisionStay;
        }
    }
示例#14
0
    private void OnDestroy()
    {
        EHBaseCollider2D TriggerCollider = GetComponent <EHBaseCollider2D>();

        TriggerCollider.OnTrigger2DEnter -= OnPlayerEnterRoom;
        if (BaseGameOverseer.Instance)
        {
            BaseGameOverseer.Instance.CurrentlyLoadedRoom.RemoveDoorActor(this);
        }
    }
示例#15
0
    private void Awake()
    {
        EHBaseCollider2D TriggerCollider = GetComponent <EHBaseCollider2D>();

        if (!TriggerCollider.GetIsTriggerCollider())
        {
            Debug.LogWarning("The collider component that is attached to this door is set to IsTrigger. Trigger events will not launch");
        }

        TriggerCollider.OnTrigger2DEnter += OnPlayerEnterRoom;
    }
示例#16
0
    private void OnDestroy()
    {
        if (BaseGameOverseer.Instance && BaseGameOverseer.Instance.PhysicsManager != null)
        {
            BaseGameOverseer.Instance.PhysicsManager.RemovePhysicsComeponent(this);
        }

        EHBaseCollider2D AttachedCollider = GetComponent <EHBaseCollider2D>();

        if (AttachedCollider)
        {
            AttachedCollider.OnCollision2DStay -= OnEHCollisionStay;
        }
    }
示例#17
0
    /// <summary>
    /// Call this method a trigger overlap
    /// </summary>
    /// <param name="Collider2D"></param>
    private void OnTriggerOverlapEnd(EHBaseCollider2D Collider2D)
    {
        OverlappingColliders.Remove(Collider2D);
        Collider2D.OverlappingColliders.Remove(this);
        FTriggerData TriggerData = new FTriggerData();

        TriggerData.OwningCollider = this;
        TriggerData.OtherCollider  = Collider2D;
        OnTrigger2DExit?.Invoke(TriggerData);

        TriggerData.OwningCollider = Collider2D;
        TriggerData.OtherCollider  = this;
        Collider2D.OnTrigger2DExit?.Invoke(TriggerData);
    }
示例#18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Collider2D"></param>
 public void IsTriggerOverlappingCollider(EHBaseCollider2D Collider2D)
 {
     if (IsColliderOverlapping(Collider2D))
     {
         if (!ContainOverlappingCollider(Collider2D))
         {
             OnTriggerOverlapBegin(Collider2D);
         }
     }
     else if (ContainOverlappingCollider(Collider2D))
     {
         OnTriggerOverlapEnd(Collider2D);
     }
 }
示例#19
0
    /// <summary>
    /// Call this method when a trigger overlap has ended
    /// </summary>
    /// <param name="Collider2D"></param>
    private void OnTriggerOverlapBegin(EHBaseCollider2D Collider2D)
    {
        OverlappingColliders.Add(Collider2D, new FHitData());
        Collider2D.OverlappingColliders.Add(this, new FHitData());
        FTriggerData TriggerData = new FTriggerData();

        TriggerData.OwningCollider = this;
        TriggerData.OtherCollider  = Collider2D;
        OnTrigger2DEnter?.Invoke(TriggerData);

        TriggerData.OwningCollider = Collider2D;
        TriggerData.OtherCollider  = this;
        Collider2D.OnTrigger2DEnter?.Invoke(TriggerData);
    }
示例#20
0
    /// <summary>
    /// This should be called anytime we begin a collision with another collider
    /// </summary>
    /// <param name="OtherCollider"></param>
    protected void AddColliderToHitSet(EHBaseCollider2D OtherCollider, FHitData HitData)
    {
        if (OtherCollider != null && !OverlappingColliders.ContainsKey(OtherCollider))
        {
            OverlappingColliders.Add(OtherCollider, new FHitData());
            OtherCollider.OverlappingColliders.Add(this, new FHitData());
        }
        OverlappingColliders[OtherCollider] = HitData;
        OnCollision2DBegin?.Invoke(HitData);

        ReverseHitData(ref HitData);

        OtherCollider.OverlappingColliders[this] = HitData;
        OtherCollider.OnCollision2DBegin?.Invoke(HitData);
    }
示例#21
0
    /// <summary>
    /// Returns whether the physics collider that is passed in is overlapping with
    /// this collider
    /// </summary>
    /// <param name="OtherCollider"></param>
    /// <returns></returns>
    public bool IsPhysicsColliderOverlapping(EHBaseCollider2D OtherCollider)
    {
        if (SweepColliderOverlap(OtherCollider))
        {
            return(true);
        }

        if (ContainOverlappingCollider(OtherCollider))
        {
            FHitData HitData = new FHitData();
            HitData.OtherCollider  = OtherCollider;
            HitData.OwningCollider = this;
            RemoveColliderFromHitSet(OtherCollider, HitData);
        }
        return(false);
    }
示例#22
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);
    }
示例#23
0
    private void CheckPhysicsCollidersAgainstCategory()
    {
        foreach (EHBaseCollider2D PhysicsCollider in ColliderComponentDictionary[EHBaseCollider2D.EColliderType.PHYSICS])
        {
            if (PhysicsCollider.gameObject.activeInHierarchy)
            {
                CollisionNodeHeap.Clear();
                foreach (EHBaseCollider2D Static in ColliderComponentDictionary[EHBaseCollider2D.EColliderType.STATIC])
                {
                    if (Static.gameObject.activeInHierarchy)
                    {
                        if (PhysicsCollider.IsPhysicsColliderOverlapping(Static) && !Physics2D.GetIgnoreLayerCollision(PhysicsCollider.gameObject.layer, Static.gameObject.layer))
                        {
                            CollisionNodeHeap.Push(new CollisionNode(PhysicsCollider.GetShortestDistanceFromPreviousPosition(Static), Static));
                        }
                    }
                }

                foreach (EHBaseCollider2D Moveable in ColliderComponentDictionary[EHBaseCollider2D.EColliderType.MOVEABLE])
                {
                    if (Moveable.gameObject.activeInHierarchy && !Physics2D.GetIgnoreLayerCollision(PhysicsCollider.gameObject.layer, Moveable.gameObject.layer))
                    {
                        if (PhysicsCollider.IsPhysicsColliderOverlapping(Moveable))
                        {
                            CollisionNodeHeap.Push(new CollisionNode(PhysicsCollider.GetShortestDistanceFromPreviousPosition(Moveable), Moveable));
                        }
                    }
                }

                while (!CollisionNodeHeap.IsEmpty())
                {
                    EHBaseCollider2D IntersectedCollider = CollisionNodeHeap.Pop().Collider;
                    if (IntersectedCollider.PushOutCollider(PhysicsCollider))
                    {
                        PhysicsCollider.UpdateColliderBounds(false);
                    }
                }
            }
        }
        CollisionNodeHeap.Clear();
    }
示例#24
0
 /// <summary>
 /// Returns the shortest distance to the collider's previous position. Should only really be usedfor calculating closes collider to our
 /// physics based colliders
 /// </summary>
 /// <param name="OtherCollider"></param>
 /// <returns></returns>
 public abstract float GetShortestDistanceFromPreviousPosition(EHBaseCollider2D OtherCollider);
示例#25
0
 /// <summary>
 /// This method will push our a collider and place it in the appropriate position. Returns true if the collider was pushed out
 /// </summary>
 /// <param name="ColliderToPushOut"></param>
 /// <returns></returns>
 public abstract bool PushOutCollider(EHBaseCollider2D ColliderToPushOut);
示例#26
0
 /// <summary>
 /// Returns true if the collider that is passed in is overlapping with this collider. This will not push out the collider. You will have to call
 /// PushOutCollider() for that
 /// </summary>
 /// <param name="OtherCollider"></param>
 /// <returns></returns>
 protected abstract bool SweepColliderOverlap(EHBaseCollider2D OtherCollider);
示例#27
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="OtherCollider"></param>
 /// <returns></returns>
 protected abstract bool IsColliderOverlapping(EHBaseCollider2D OtherCollider);
示例#28
0
 public CollisionNode(float CollisionDistance, EHBaseCollider2D Collider)
 {
     this.CollisionDistance = CollisionDistance;
     this.Collider          = Collider;
 }
示例#29
0
 /// <summary>
 /// Returns true if the collider that is passed in was already colliding with this collider in the previous frame
 /// </summary>
 /// <param name="OtherCollider"></param>
 /// <returns></returns>
 protected bool ContainOverlappingCollider(EHBaseCollider2D OtherCollider)
 {
     return(OverlappingColliders.ContainsKey(OtherCollider));
 }
示例#30
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);
    }