private void Start()
    {
        if (platformTopCollider != null && topCustomAction != null && topCustomAction.GetClass().IsSubclassOf(typeof(OnCollisionCustomAction)))
        {
            OnCollisionCustomAction customAction = platformTopCollider.AddComponent(topCustomAction.GetClass()) as OnCollisionCustomAction;
            customAction.InitializeData();
        }

        if (platformBottomCollider != null && bottomCustomAction != null && bottomCustomAction.GetClass().IsSubclassOf(typeof(OnCollisionCustomAction)))
        {
            OnCollisionCustomAction customAction = platformBottomCollider.AddComponent(bottomCustomAction.GetClass()) as OnCollisionCustomAction;
            customAction.InitializeData();
        }

        if (platformRightCollider != null && rightCustomAction != null && rightCustomAction.GetClass().IsSubclassOf(typeof(OnCollisionCustomAction)))
        {
            OnCollisionCustomAction customAction = platformRightCollider.AddComponent(rightCustomAction.GetClass()) as OnCollisionCustomAction;
            customAction.InitializeData();
        }

        if (platformLeftCollider != null && leftCustomAction != null && leftCustomAction.GetClass().IsSubclassOf(typeof(OnCollisionCustomAction)))
        {
            OnCollisionCustomAction customAction = platformLeftCollider.AddComponent(leftCustomAction.GetClass()) as OnCollisionCustomAction;
            customAction.InitializeData();
        }
    }
Example #2
0
    private void CheckCollision(RaycastHit2D hit, RayType rayType)
    {
        if (hit.collider != null)
        {
            OnCollisionCustomAction customAction = hit.collider.GetComponent <OnCollisionCustomAction>();
            float hitPointCoordinate             = 0;

            switch (hit.collider.name)
            {
            case "Top":
                if (rayType == RayType.SouthWestDown)
                {
                    hitPointCoordinate = hit.point.y + spriteHalfSizeY * spriteScaleY;
                    hitSouthWestDown   = true;
                }
                else if (rayType == RayType.SouthEastDown)
                {
                    hitPointCoordinate = hit.point.y + spriteHalfSizeY * spriteScaleY;
                    hitSouthEastDown   = true;
                }

                if ((hitSouthWestDown || hitSouthEastDown) && !downIsBeingClamped)
                {
                    engine.ClampYBelow(true, hitPointCoordinate, customAction);
                    downIsBeingClamped = true;
                }
                break;

            case "Bottom":
                if (rayType == RayType.NorthWestTop)
                {
                    hitPointCoordinate = hit.point.y - spriteHalfSizeY * spriteScaleY;
                    hitNorthWestTop    = true;
                }
                else if (rayType == RayType.NorthEastTop)
                {
                    hitPointCoordinate = hit.point.y - spriteHalfSizeY * spriteScaleY;
                    hitNorthEastTop    = true;
                }

                if ((hitNorthWestTop || hitNorthEastTop) && !topIsBeingClamped)
                {
                    engine.ClampYAbove(true, hitPointCoordinate, customAction);
                    topIsBeingClamped = true;
                }
                break;

            case "Left":
                if (rayType == RayType.SouthWestLeft)
                {
                    hitPointCoordinate = hit.point.x + spriteHalfSizeX * spriteScaleX;
                    hitSouthWestLeft   = true;
                }
                else if (rayType == RayType.NorthWestLeft)
                {
                    hitPointCoordinate = hit.point.x + spriteHalfSizeX * spriteScaleX;
                    hitNorthWestLeft   = true;
                }

                if ((hitSouthWestLeft || hitNorthWestLeft) && !leftIsBeingClamped)
                {
                    engine.ClampXBelow(true, hitPointCoordinate, customAction);
                    leftIsBeingClamped = true;
                }
                break;

            case "Right":
                if (rayType == RayType.SouthEastRight)
                {
                    hitPointCoordinate = hit.point.x - spriteHalfSizeX * spriteScaleX;
                    hitSouthEastRight  = true;
                }
                else if (rayType == RayType.NorthEastRight)
                {
                    hitPointCoordinate = hit.point.x - spriteHalfSizeX * spriteScaleX;
                    hitNorthEastRight  = true;
                }

                if ((hitNorthEastRight || hitSouthEastRight) && !rightIsBeingClamped)
                {
                    engine.ClampXAbove(true, hitPointCoordinate, customAction);
                    rightIsBeingClamped = true;
                }
                break;

            default:
                break;
            }
        }

        else
        {
            switch (rayType)
            {
            // Bottom
            case RayType.SouthWestDown:
                downIsBeingClamped = false;
                hitSouthWestDown   = false;
                break;

            case RayType.SouthEastDown:
                downIsBeingClamped = false;
                hitSouthEastDown   = false;
                break;

            // Top
            case RayType.NorthWestTop:
                topIsBeingClamped = false;
                hitNorthWestTop   = false;
                break;

            case RayType.NorthEastTop:
                topIsBeingClamped = false;
                hitNorthEastTop   = false;
                break;

            // Left
            case RayType.SouthWestLeft:
                leftIsBeingClamped = false;
                hitSouthWestLeft   = false;
                break;

            case RayType.NorthWestLeft:
                leftIsBeingClamped = false;
                hitNorthWestLeft   = false;
                break;

            // Right
            case RayType.SouthEastRight:
                rightIsBeingClamped = false;
                hitSouthEastRight   = false;
                break;

            case RayType.NorthEastRight:
                rightIsBeingClamped = false;
                hitNorthEastRight   = false;
                break;

            default:
                break;
            }
        }
    }
Example #3
0
 public void ClampYBelow(bool clampingYBelow, float clampValue = 0, OnCollisionCustomAction customAction = null)
 {
     clampYBelowPosition = clampingYBelow;
     clampYBelowValue    = clampValue;
     topCollisionAction  = customAction;
 }
Example #4
0
 public void ClampYAbove(bool clampingYAbove, float clampValue = 0, OnCollisionCustomAction customAction = null)
 {
     clampYAbovePosition   = clampingYAbove;
     clampYAboveValue      = clampValue;
     bottomCollisionAction = customAction;
 }