Example #1
0
    void ComputeJoystickAnchor(JoystickAnchor anchor)
    {
        float touch = 0;

        if (!restrictArea)
        {
            touch = touchSize;
        }
        // Anchor position
        switch (anchor)
        {
        case JoystickAnchor.UpperLeft:
            anchorPosition = new Vector2(zoneRadius + touch, zoneRadius + touch);
            break;

        case JoystickAnchor.UpperCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2, zoneRadius + touch);
            break;

        case JoystickAnchor.UpperRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - touch, zoneRadius + touch);
            break;


        case JoystickAnchor.MiddleLeft:
            anchorPosition = new Vector2(zoneRadius + touch, VirtualScreen.height / 2);
            break;

        case JoystickAnchor.MiddleCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2, VirtualScreen.height / 2);
            break;

        case JoystickAnchor.MiddleRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - touch, VirtualScreen.height / 2);
            break;

        case JoystickAnchor.LowerLeft:
            anchorPosition = new Vector2(zoneRadius + touch, VirtualScreen.height - zoneRadius - touch);
            break;

        case JoystickAnchor.LowerCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2, VirtualScreen.height - zoneRadius - touch);
            break;

        case JoystickAnchor.LowerRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - touch, VirtualScreen.height - zoneRadius - touch);
            break;

        case JoystickAnchor.None:
            anchorPosition = Vector2.zero;
            break;
        }

        //joystick rect
        areaRect = new Rect(anchorPosition.x + joystickCenter.x - zoneRadius, anchorPosition.y + joystickCenter.y - zoneRadius, zoneRadius * 2, zoneRadius * 2);
        deadRect = new Rect(anchorPosition.x + joystickCenter.x - deadZone, anchorPosition.y + joystickCenter.y - deadZone, deadZone * 2, deadZone * 2);
    }
Example #2
0
    private void ComputeJoystickAnchor(JoystickAnchor anchor)
    {
        float num = 0f;

        if (!restrictArea)
        {
            num = touchSize;
        }
        switch (anchor)
        {
        case JoystickAnchor.UpperLeft:
            anchorPosition = new Vector2(zoneRadius + num, zoneRadius + num);
            break;

        case JoystickAnchor.UpperCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2f, zoneRadius + num);
            break;

        case JoystickAnchor.UpperRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - num, zoneRadius + num);
            break;

        case JoystickAnchor.MiddleLeft:
            anchorPosition = new Vector2(zoneRadius + num, VirtualScreen.height / 2f);
            break;

        case JoystickAnchor.MiddleCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2f, VirtualScreen.height / 2f);
            break;

        case JoystickAnchor.MiddleRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - num, VirtualScreen.height / 2f);
            break;

        case JoystickAnchor.LowerLeft:
            anchorPosition = new Vector2(zoneRadius + num, VirtualScreen.height - zoneRadius - num);
            break;

        case JoystickAnchor.LowerCenter:
            anchorPosition = new Vector2(VirtualScreen.width / 2f, VirtualScreen.height - zoneRadius - num);
            break;

        case JoystickAnchor.LowerRight:
            anchorPosition = new Vector2(VirtualScreen.width - zoneRadius - num, VirtualScreen.height - zoneRadius - num);
            break;

        case JoystickAnchor.None:
            anchorPosition = Vector2.zero;
            break;
        }
        areaRect = new Rect(anchorPosition.x + joystickCenter.x - zoneRadius, anchorPosition.y + joystickCenter.y - zoneRadius, zoneRadius * 2f, zoneRadius * 2f);
        deadRect = new Rect(anchorPosition.x + joystickCenter.x - deadZone, anchorPosition.y + joystickCenter.y - deadZone, deadZone * 2f, deadZone * 2f);
    }
Example #3
0
    void ComputeJoystickAnchor(JoystickAnchor anchor)
    {
        float touch=0;
        if (!restrictArea){
            touch = touchSize;
        }
        // Anchor position
        switch (anchor){
            case JoystickAnchor.UpperLeft:
                anchorPosition = new Vector2( zoneRadius+touch, zoneRadius+touch);
                break;
            case JoystickAnchor.UpperCenter:
                anchorPosition = new Vector2( VirtualScreen.width/2, zoneRadius+touch);
                break;
            case JoystickAnchor.UpperRight:
                anchorPosition = new Vector2( VirtualScreen.width-zoneRadius-touch,zoneRadius+touch);
                break;

            case JoystickAnchor.MiddleLeft:
                anchorPosition = new Vector2( zoneRadius+touch, VirtualScreen.height/2);
                break;
            case JoystickAnchor.MiddleCenter:
                anchorPosition = new Vector2( VirtualScreen.width/2, VirtualScreen.height/2);
                break;
            case JoystickAnchor.MiddleRight:
                anchorPosition = new Vector2( VirtualScreen.width-zoneRadius-touch,VirtualScreen.height/2);
                break;

            case JoystickAnchor.LowerLeft:
                anchorPosition = new Vector2( zoneRadius+touch, VirtualScreen.height-zoneRadius-touch);
                break;
            case JoystickAnchor.LowerCenter:
                anchorPosition = new Vector2( VirtualScreen.width/2, VirtualScreen.height-zoneRadius-touch);
                break;
            case JoystickAnchor.LowerRight:
                anchorPosition = new Vector2( VirtualScreen.width-zoneRadius-touch,VirtualScreen.height-zoneRadius-touch);
                break;

            case JoystickAnchor.None:
                anchorPosition = Vector2.zero;
                break;
        }

        //joystick rect
        areaRect = new Rect(anchorPosition.x + joystickCenter.x -zoneRadius , anchorPosition.y+joystickCenter.y-zoneRadius,zoneRadius*2,zoneRadius*2);
        deadRect = new Rect(anchorPosition.x +  joystickCenter.x -deadZone,anchorPosition.y + joystickCenter.y-deadZone,deadZone*2,deadZone*2);
    }
    private void ComputeJoystickAnchor(JoystickAnchor anchor)
    {
        float touchSize = 0f;
        if (!this.restrictArea)
        {
            touchSize = this.touchSize;
        }
        switch (anchor)
        {
            case JoystickAnchor.None:
                this.anchorPosition = Vector2.zero;
                break;

            case JoystickAnchor.UpperLeft:
                this.anchorPosition = new Vector2(this.zoneRadius + touchSize, this.zoneRadius + touchSize);
                break;

            case JoystickAnchor.UpperCenter:
                this.anchorPosition = new Vector2(VirtualScreen.width / 2f, this.zoneRadius + touchSize);
                break;

            case JoystickAnchor.UpperRight:
                this.anchorPosition = new Vector2((VirtualScreen.width - this.zoneRadius) - touchSize, this.zoneRadius + touchSize);
                break;

            case JoystickAnchor.MiddleLeft:
                this.anchorPosition = new Vector2(this.zoneRadius + touchSize, VirtualScreen.height / 2f);
                break;

            case JoystickAnchor.MiddleCenter:
                this.anchorPosition = new Vector2(VirtualScreen.width / 2f, VirtualScreen.height / 2f);
                break;

            case JoystickAnchor.MiddleRight:
                this.anchorPosition = new Vector2((VirtualScreen.width - this.zoneRadius) - touchSize, VirtualScreen.height / 2f);
                break;

            case JoystickAnchor.LowerLeft:
                this.anchorPosition = new Vector2(this.zoneRadius + touchSize, (VirtualScreen.height - this.zoneRadius) - touchSize);
                break;

            case JoystickAnchor.LowerCenter:
                this.anchorPosition = new Vector2(VirtualScreen.width / 2f, (VirtualScreen.height - this.zoneRadius) - touchSize);
                break;

            case JoystickAnchor.LowerRight:
                this.anchorPosition = new Vector2((VirtualScreen.width - this.zoneRadius) - touchSize, (VirtualScreen.height - this.zoneRadius) - touchSize);
                break;
        }
        this.areaRect = new Rect((this.anchorPosition.x + this.joystickCenter.x) - this.zoneRadius, (this.anchorPosition.y + this.joystickCenter.y) - this.zoneRadius, this.zoneRadius * 2f, this.zoneRadius * 2f);
        this.deadRect = new Rect((this.anchorPosition.x + this.joystickCenter.x) - this.deadZone, (this.anchorPosition.y + this.joystickCenter.y) - this.deadZone, this.deadZone * 2f, this.deadZone * 2f);
    }