Пример #1
0
    private float ParseHorizontalPositionFromStringForPanel(string positionString, CanvasPanel panel)
    {
        float hpos = 0;

        switch (positionString)
        {
        case "offleft":
            hpos = -(panel.GetSize().x / unitSize.x);
            break;

        case "left":
            hpos = 0;
            break;

        case "center":
            hpos = (grid.x - (panel.GetSize().x / unitSize.x)) * .5f;
            break;

        case "right":
            hpos = grid.x - (panel.GetSize().x / unitSize.x);
            break;

        case "offright":
            hpos = grid.x;
            break;
        }
        return(hpos);
    }
Пример #2
0
    private float ParseVerticalPositionFromStringForPanel(string positionString, CanvasPanel panel)
    {
        float vpos = 0;

        switch (positionString)
        {
        case "offtop":
            vpos = grid.y;
            break;

        case "top":
            vpos = grid.y - (panel.GetSize().y / unitSize.y);
            break;

        case "center":
            vpos = (grid.y - (panel.GetSize().y / unitSize.y)) * .5f;
            break;

        case "bottom":
            vpos = 0;
            break;

        case "offbottom":
            vpos = -(panel.GetSize().y / unitSize.y);
            break;
        }
        return(vpos);
    }
Пример #3
0
    private Vector2 ParsePositionFromStringForPanel(string positionString, CanvasPanel panel)
    {
        Vector2 position = Vector2.zero;

        string [] temp = positionString.Split(' ');
        try {
            float x = float.Parse(temp [0]);
            float y = float.Parse(temp [1]);
            position.x = x;
            position.y = grid.y - y - (panel.GetSize().y / unitSize.y);
        } catch (FormatException) {
            switch (temp [0])
            {
            case "offleft":
            case "left":
            case "center":
            case "right":
            case "offright":
                position.x = ParseHorizontalPositionFromStringForPanel(temp [0], panel);
                break;

            case "offtop":
            case "top":
            case "bottom":
            case "offbottom":
                position.y = ParseVerticalPositionFromStringForPanel(temp [0], panel);
                break;
            }
            if (temp.Length > 1)
            {
                position.y = ParseVerticalPositionFromStringForPanel(temp [1], panel);
            }
            else if (temp.Length == 1)
            {
                if (temp [0] == "center")
                {
                    position.y = ParseVerticalPositionFromStringForPanel(temp [0], panel);
                }
            }
        }
        position.x /= grid.x;
        position.y /= grid.y;
        return(position);
    }