Exemplo n.º 1
0
    public Vector2 GetWallCenter(Facing.Direction a_direction, bool a_relative = false)
    {
        var   offset      = -Facing.DirectionToVector(a_direction) * WallSize / 2.0f;
        float attachPoint = 0.0f;

        switch (a_direction)
        {
        case Facing.Direction.East: attachPoint = Right - (a_relative ? transform.position.x : 0.0f); break;

        case Facing.Direction.North: attachPoint = Top - (a_relative ? transform.position.y : 0.0f); break;

        case Facing.Direction.South: attachPoint = Bottom - (a_relative ? transform.position.y : 0.0f); break;

        case Facing.Direction.West: attachPoint = Left - (a_relative ? transform.position.x : 0.0f); break;
        }
        if (!Facing.IsVertical(a_direction))
        {
            return(new Vector2(attachPoint + offset.x, 0.0f));
        }
        return(new Vector2(0.0f, attachPoint + offset.y));
    }
Exemplo n.º 2
0
    private Vector2 ClampDirection(Vector2 a_directionVec)
    {
        var clampedVec = a_directionVec.normalized;

        if (Mathf.Abs(clampedVec.magnitude) < Mathf.Epsilon)
        {
            return(clampedVec);
        }

        if (m_clampMode == ClampMode.Direction)
        {
            switch (m_clampDirection)
            {
            case Facing.Direction.East:
                if (clampedVec.x > 0)
                {
                    return(Vector2.right);
                }
                break;

            case Facing.Direction.North:
                if (clampedVec.y > 0)
                {
                    return(Vector2.up);
                }
                break;

            case Facing.Direction.Northeast:
                if (clampedVec.x > 0 && clampedVec.y > 0)
                {
                    return(Vector2.right + Vector2.up);
                }
                break;

            case Facing.Direction.Northwest:
                if (clampedVec.x < 0 && clampedVec.y > 0)
                {
                    return(Vector2.left + Vector2.up);
                }
                break;

            case Facing.Direction.South:
                if (clampedVec.y < 0)
                {
                    return(Vector2.down);
                }
                break;

            case Facing.Direction.Southeast:
                if (clampedVec.x > 0 && clampedVec.y < 0)
                {
                    return(Vector2.right + Vector2.down);
                }
                break;

            case Facing.Direction.Southwest:
                if (clampedVec.x < 0 && clampedVec.y < 0)
                {
                    return(Vector2.left + Vector2.down);
                }
                break;

            case Facing.Direction.West:
                if (clampedVec.x < 0)
                {
                    return(Vector2.left);
                }
                break;
            }

            return(Vector2.zero);
        }
        else if (m_clampMode == ClampMode.Horizontal)
        {
            if (clampedVec.x > 0)
            {
                return(Facing.DirectionToVector(Facing.Direction.East));
            }
            else if (clampedVec.x < 0)
            {
                return(Facing.DirectionToVector(Facing.Direction.West));
            }
            return(Vector2.zero);
        }
        else if (m_clampMode == ClampMode.Vertical)
        {
            if (clampedVec.y > 0)
            {
                return(Facing.DirectionToVector(Facing.Direction.North));
            }
            else if (clampedVec.y < 0)
            {
                return(Facing.DirectionToVector(Facing.Direction.South));
            }
            return(Vector2.zero);
        }
        else if (m_clampMode == ClampMode.Cardinal)
        {
            var dir = clampedVec.ToDirection(true);
            return(Facing.DirectionToVector(dir));
        }
        else if (m_clampMode == ClampMode.PrimaryIntercardinal)
        {
            var dir = clampedVec.ToDirection();
            return(Facing.DirectionToVector(dir));
        }
        return(clampedVec);
    }