Beispiel #1
0
 internal static PolyPosition Create(PositionDef position)
 {
     return(new PolyPosition {
         Name = position.Position.Value,
         Location = position.Location,
         Coords = position.Coords,
         IsDummy = position.IsDummy,
     });
 }
Beispiel #2
0
    //button positions can be set in this method
    private static Vector2 SetPosition(PositionDef position, float width, float height)
    {
        Vector2 finalPosition;

        switch (position)
        {
        case PositionDef.topLeft:
            finalPosition = new Vector2(BUTTON_GAP, BUTTON_GAP);
            break;

        case PositionDef.topMiddle:
            finalPosition = new Vector2(WIDTH / 2 - width / 2, BUTTON_GAP);
            break;

        case PositionDef.topRight:
            finalPosition = new Vector2(WIDTH - width - BUTTON_GAP, BUTTON_GAP);
            break;

        case PositionDef.bottomLeft:
            finalPosition = new Vector2(BUTTON_GAP, HEIGHT - height - BUTTON_GAP);
            break;

        case PositionDef.bottomMiddle:
            finalPosition = new Vector2(WIDTH / 2 - width / 2, HEIGHT - height - BUTTON_GAP);
            break;

        case PositionDef.bottomRight:
            finalPosition = new Vector2(WIDTH - width - BUTTON_GAP, HEIGHT - height - BUTTON_GAP);
            break;

        case PositionDef.left:
            finalPosition = new Vector2(BUTTON_GAP, HEIGHT / 2 - height / 2);
            break;

        case PositionDef.right:
            finalPosition = new Vector2(WIDTH - width - BUTTON_GAP, HEIGHT / 2 - height / 2);
            break;

        case PositionDef.middle:
            finalPosition = new Vector2(WIDTH / 2 - width / 2, HEIGHT / 2 - height / 2);
            break;

        default:
            finalPosition = new Vector2(WIDTH / 2 - width / 2, HEIGHT / 2 - height / 2);
            Debug.LogError("Undefined position, assigned to middle.");
            break;
        }

        return(finalPosition);
    }
Beispiel #3
0
        //specify size manually, choose position from the list
        public GUIParams(PositionDef position, float guiWidth, float guiHeight, string guiText)
        {
            text = guiText;

            width  = guiWidth;
            height = guiHeight;

            Vector2 buttonPos = SetPosition(position, width, height);

            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width / 6;
        }
Beispiel #4
0
        //choose size and position from the list
        public GUIParams(PositionDef position, SizeDef size, string guiText)
        {
            text = guiText;

            Vector2 buttonSize = SetSize(size);

            width  = buttonSize.x;
            height = buttonSize.y;

            Vector2 buttonPos = SetPosition(position, width, height);

            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width / 6;
        }
Beispiel #5
0
        //choose position from the list, default size
        public GUIParams(PositionDef position, string guiText)
        {
            text = guiText;

            //size defaults to medium
            Vector2 buttonSize = SetSize(SizeDef.medium);

            width  = buttonSize.x;
            height = buttonSize.y;

            Vector2 buttonPos = SetPosition(position, width, height);

            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width / 6;
        }
Beispiel #6
0
    //call this funtion in the beginning of OnGUI
    public static void BeginGUI(PositionDef elementsPosition = PositionDef.middle)
    {
        stack.Add (GUI.matrix);
        Matrix4x4 m = new Matrix4x4 ();
        float w = (float)Screen.width;
        float h = (float)Screen.height;
        float aspect = w / h;
        float scale = 1f;
        Vector3 offset = Vector3.zero;

        if(aspect < (WIDTH/HEIGHT))
        {
            //screen is taller
            switch(elementsPosition)
            {
                case PositionDef.topLeft:
                    scale = (Screen.width/WIDTH);
                    break;
                case PositionDef.topMiddle:
                    scale = (Screen.width/WIDTH);
                    break;
                case PositionDef.topRight:
                    scale = (Screen.width/WIDTH);
                    break;
                case PositionDef.bottomLeft:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale));
                    break;
                case PositionDef.bottomMiddle:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale));
                    break;
                case PositionDef.bottomRight:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale));
                    break;
                case PositionDef.left:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                    break;
                case PositionDef.right:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                    break;
                case PositionDef.middle:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                    break;
                default:
                    scale = (Screen.width/WIDTH);
                    offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                    break;
            }
        }
        else
        {
            //screen is wider
            switch(elementsPosition)
            {
                case PositionDef.topLeft:
                    scale = (Screen.height / HEIGHT);
                    break;
                case PositionDef.topMiddle:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                    break;
                case PositionDef.topRight:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale));
                    break;
                case PositionDef.bottomLeft:
                    scale = (Screen.height / HEIGHT);
                    break;
                case PositionDef.bottomMiddle:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                    break;
                case PositionDef.bottomRight:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale));
                    break;
                case PositionDef.left:
                    scale = (Screen.height / HEIGHT);
                    break;
                case PositionDef.right:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale));
                    break;
                case PositionDef.middle:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                    break;
                default:
                    scale = (Screen.height / HEIGHT);
                    offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                    break;
            }
        }

        m.SetTRS(offset, Quaternion.identity, Vector3.one * scale);
        GUI.matrix *= m;
    }
Beispiel #7
0
        //choose size and position from the list
        public GUIParams(PositionDef position, SizeDef size, string guiText)
        {
            text = guiText;

            Vector2 buttonSize = SetSize(size);
            width = buttonSize.x;
            height = buttonSize.y;

            Vector2 buttonPos = SetPosition(position, width, height);
            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width/6;
        }
Beispiel #8
0
        //choose position from the list, default size
        public GUIParams(PositionDef position, string guiText)
        {
            text = guiText;

            //size defaults to medium
            Vector2 buttonSize = SetSize(SizeDef.medium);
            width = buttonSize.x;
            height = buttonSize.y;

            Vector2 buttonPos = SetPosition(position, width, height);
            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width/6;
        }
Beispiel #9
0
        //specify size manually, choose position from the list
        public GUIParams(PositionDef position, float guiWidth, float guiHeight, string guiText)
        {
            text = guiText;

            width = guiWidth;
            height = guiHeight;

            Vector2 buttonPos = SetPosition(position, width, height);
            x = buttonPos.x;
            y = buttonPos.y;

            fontSize = width/6;
        }
Beispiel #10
0
    //button positions can be set in this method
    private static Vector2 SetPosition(PositionDef position, float width, float height)
    {
        Vector2 finalPosition;

            switch (position)
            {
                case PositionDef.topLeft:
                    finalPosition = new Vector2(BUTTON_GAP, BUTTON_GAP);
                    break;

                case PositionDef.topMiddle:
                    finalPosition = new Vector2(WIDTH/2-width/2, BUTTON_GAP);
                    break;

                case PositionDef.topRight:
                    finalPosition = new Vector2(WIDTH-width-BUTTON_GAP, BUTTON_GAP);
                    break;

                case PositionDef.bottomLeft:
                    finalPosition = new Vector2(BUTTON_GAP, HEIGHT-height-BUTTON_GAP);
                    break;

                case PositionDef.bottomMiddle:
                    finalPosition = new Vector2(WIDTH/2-width/2, HEIGHT-height-BUTTON_GAP);
                    break;

                case PositionDef.bottomRight:
                    finalPosition = new Vector2(WIDTH-width-BUTTON_GAP, HEIGHT-height-BUTTON_GAP);
                    break;

                case PositionDef.left:
                    finalPosition = new Vector2(BUTTON_GAP, HEIGHT/2-height/2);
                    break;

                case PositionDef.right:
                    finalPosition = new Vector2(WIDTH-width-BUTTON_GAP, HEIGHT/2-height/2);
                    break;

                case PositionDef.middle:
                    finalPosition = new Vector2(WIDTH/2-width/2, HEIGHT/2-height/2);
                    break;

                default:
                    finalPosition = new Vector2(WIDTH/2-width/2, HEIGHT/2-height/2);
                    Debug.LogError("Undefined position, assigned to middle.");
                    break;
            }

        return finalPosition;
    }
Beispiel #11
0
    //call this funtion in the beginning of OnGUI
    static public void BeginGUI(PositionDef elementsPosition = PositionDef.middle)
    {
        stack.Add(GUI.matrix);
        Matrix4x4 m      = new Matrix4x4();
        float     w      = (float)Screen.width;
        float     h      = (float)Screen.height;
        float     aspect = w / h;
        float     scale  = 1f;
        Vector3   offset = Vector3.zero;

        if (aspect < (WIDTH / HEIGHT))
        {
            //screen is taller
            switch (elementsPosition)
            {
            case PositionDef.topLeft:
                scale = (Screen.width / WIDTH);
                break;

            case PositionDef.topMiddle:
                scale = (Screen.width / WIDTH);
                break;

            case PositionDef.topRight:
                scale = (Screen.width / WIDTH);
                break;

            case PositionDef.bottomLeft:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale));
                break;

            case PositionDef.bottomMiddle:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale));
                break;

            case PositionDef.bottomRight:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale));
                break;

            case PositionDef.left:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                break;

            case PositionDef.right:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                break;

            case PositionDef.middle:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                break;

            default:
                scale     = (Screen.width / WIDTH);
                offset.y += (Screen.height - (HEIGHT * scale)) * 0.5f;
                break;
            }
        }
        else
        {
            //screen is wider
            switch (elementsPosition)
            {
            case PositionDef.topLeft:
                scale = (Screen.height / HEIGHT);
                break;

            case PositionDef.topMiddle:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                break;

            case PositionDef.topRight:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale));
                break;

            case PositionDef.bottomLeft:
                scale = (Screen.height / HEIGHT);
                break;

            case PositionDef.bottomMiddle:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                break;

            case PositionDef.bottomRight:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale));
                break;

            case PositionDef.left:
                scale = (Screen.height / HEIGHT);
                break;

            case PositionDef.right:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale));
                break;

            case PositionDef.middle:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                break;

            default:
                scale     = (Screen.height / HEIGHT);
                offset.x += (Screen.width - (WIDTH * scale)) * 0.5f;
                break;
            }
        }

        m.SetTRS(offset, Quaternion.identity, Vector3.one * scale);
        GUI.matrix *= m;
    }