コード例 #1
0
        public void mapDataStructureToAction(int index)
        {
            horizontal    = joystick[index].JOYSTICK_HORIZONTAL * sensitivity;
            vertical      = joystick[index].JOYSTICK_VERTICAL * sensitivity;
            actionVector3 = EasyWiFiUtilities.getControllerVector3(horizontal, vertical, joystickHorizontal, joystickVertical);

            switch (action)
            {
            case EasyWiFiConstants.ACTION_TYPE.Position:
                transform.position += actionVector3;
                break;

            case EasyWiFiConstants.ACTION_TYPE.Rotation:
                transform.Rotate(actionVector3, Space.World);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalPosition:
                transform.Translate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalRotation:
                transform.Rotate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalScale:
                transform.localScale += actionVector3;
                break;

            default:
                Debug.Log("Invalid Action");
                break;
            }
        }
        public void mapDataStructureToAction(int index)
        {
            sliderValue   = slider[index].SLIDER_VALUE * sensitivity;
            actionVector3 = EasyWiFiUtilities.getControllerVector3(sliderValue, 0f, sliderEffect, EasyWiFiConstants.AXIS.None);

            switch (action)
            {
            case EasyWiFiConstants.ACTION_TYPE.Position:
                transform.position += actionVector3;
                break;

            case EasyWiFiConstants.ACTION_TYPE.Rotation:
                transform.Rotate(actionVector3, Space.World);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalPosition:
                transform.Translate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalRotation:
                transform.Rotate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalScale:
                transform.localScale += actionVector3;
                break;

            default:
                Debug.Log("Invalid Action");
                break;
            }
        }
        public void mapDataStructureToAction(int index)
        {
            lastFrameNumTouches = numTouches;
            lastFrameZoomFactor = zoomFactor;
            lastFrameHorizontal = horizontal;
            lastFrameVertical   = vertical;

            numTouches = touchpad[index].TOUCH_COUNT;
            zoomFactor = touchpad[index].ZOOM_FACTOR * zoomSensitivity;
            horizontal = touchpad[index].TOUCH1_POSITION_HORIZONTAL;
            vertical   = touchpad[index].TOUCH1_POSITION_VERTICAL;

            //only if we were touching both last frame and this
            if (numTouches > 0 && lastFrameNumTouches > 0)
            {
                if (numTouches == 1)
                {
                    //panning
                    if (secondTouchType == EasyWiFiConstants.SECOND_TOUCH_TYPE.Tilt)
                    {
                        //panning in the camera context should be local position moves (x and y axis)
                        actionVector3 = EasyWiFiUtilities.getControllerVector3((horizontal - lastFrameHorizontal) * panSensitivity, (vertical - lastFrameVertical) * panSensitivity, EasyWiFiConstants.AXIS.XAxis, EasyWiFiConstants.AXIS.YAxis);
                        transform.Translate(actionVector3);
                    }
                    //tilting
                    else
                    {
                        //tilting in the camera context should be local rotation moves (y and x axis)
                        actionVector3 = EasyWiFiUtilities.getControllerVector3((horizontal - lastFrameHorizontal) * tiltSensitivity, (vertical - lastFrameVertical) * tiltSensitivity, EasyWiFiConstants.AXIS.YAxis, EasyWiFiConstants.AXIS.XAxis);
                        transform.Rotate(actionVector3);
                    }
                }
                else if (numTouches == 2)
                {
                    //zooming in the camera
                    actionVector3 = new Vector3(0f, 0f, zoomFactor - lastFrameZoomFactor);
                    transform.Translate(actionVector3);
                }
                else if (numTouches == 3)
                {
                    //panning
                    if (secondTouchType == EasyWiFiConstants.SECOND_TOUCH_TYPE.Pan)
                    {
                        //panning in the camera context should be local position moves (x and y axis)
                        actionVector3 = EasyWiFiUtilities.getControllerVector3((horizontal - lastFrameHorizontal) * panSensitivity, (vertical - lastFrameVertical) * panSensitivity, EasyWiFiConstants.AXIS.XAxis, EasyWiFiConstants.AXIS.YAxis);
                        transform.Translate(actionVector3);
                    }
                    //tilting
                    else
                    {
                        //tilting in the camera context should be local rotation moves (y and x axis)
                        actionVector3 = EasyWiFiUtilities.getControllerVector3((horizontal - lastFrameHorizontal) * tiltSensitivity, (vertical - lastFrameVertical) * tiltSensitivity, EasyWiFiConstants.AXIS.YAxis, EasyWiFiConstants.AXIS.XAxis);
                        transform.Rotate(actionVector3);
                    }
                }
            }
        }
        public void mapDataStructureToAction(int index)
        {
            //reset values
            horizontal = 0f;
            vertical   = 0f;

            //left/right
            if (dPad[index].DPAD_LEFT_PRESSED)
            {
                horizontal = -1f;
            }
            if (dPad[index].DPAD_RIGHT_PRESSED)
            {
                horizontal = 1f;
            }

            //up/down
            if (dPad[index].DPAD_DOWN_PRESSED)
            {
                vertical = -1f;
            }
            if (dPad[index].DPAD_UP_PRESSED)
            {
                vertical = 1f;
            }

            horizontal   *= sensitivity;
            vertical     *= sensitivity;
            actionVector3 = EasyWiFiUtilities.getControllerVector3(horizontal, vertical, dPadHorizontal, dPadVertical);

            switch (action)
            {
            case EasyWiFiConstants.ACTION_TYPE.Position:
                transform.position += actionVector3;
                break;

            case EasyWiFiConstants.ACTION_TYPE.Rotation:
                transform.Rotate(actionVector3, Space.World);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalPosition:
                transform.Translate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalRotation:
                transform.Rotate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalScale:
                transform.localScale += actionVector3;
                break;

            default:
                Debug.Log("Invalid Action");
                break;
            }
        }
        public void mapDataStructureToAction(int index)
        {
            //data
            accel.x = accelerometer[index].ACCELERATION_X;
            accel.y = accelerometer[index].ACCELERATION_Y;
            accel.z = accelerometer[index].ACCELERATION_Z;

            //accelerometers due to gravity can really only sense 2 axis (can't filter out gravity)
            //here we convert those 2 axis into horizontal and vertical and normalize
            horizontal = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.forward) / normalizeDegrees;
            vertical   = EasyWiFiUtilities.relativeAngleInAxis(Vector3.up, -accel, Vector3.right) / normalizeDegrees;

            horizontal *= -sensitivity;
            vertical   *= sensitivity;

            actionVector3 = EasyWiFiUtilities.getControllerVector3(horizontal, vertical, tiltHorizontal, tiltVertical);


            switch (action)
            {
            case EasyWiFiConstants.ACTION_TYPE.Position:
                transform.position += actionVector3;
                break;

            case EasyWiFiConstants.ACTION_TYPE.Rotation:
                transform.Rotate(actionVector3, Space.World);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalPosition:
                transform.Translate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalRotation:
                transform.Rotate(actionVector3);
                break;

            case EasyWiFiConstants.ACTION_TYPE.LocalScale:
                transform.localScale += actionVector3;
                break;

            default:
                Debug.Log("Invalid Action");
                break;
            }
        }
        public void mapDataStructureToAction(int index)
        {
            lastFrameHorizontal = horizontal;
            lastFrameVertical   = vertical;
            lastFrameIsTouching = isTouching;

            horizontal = touchpad[index].POSITION_HORIZONTAL * sensitivity;
            vertical   = touchpad[index].POSITION_VERTICAL * sensitivity;
            isTouching = touchpad[index].IS_TOUCHING;

            //only if we were touching both last frame and this
            if (isTouching && lastFrameIsTouching)
            {
                actionVector3 = EasyWiFiUtilities.getControllerVector3(horizontal - lastFrameHorizontal, vertical - lastFrameVertical, touchpadHorizontal, touchpadVertical);

                switch (action)
                {
                case EasyWiFiConstants.ACTION_TYPE.Position:
                    transform.position += actionVector3;
                    break;

                case EasyWiFiConstants.ACTION_TYPE.Rotation:
                    transform.Rotate(actionVector3, Space.World);
                    break;

                case EasyWiFiConstants.ACTION_TYPE.LocalPosition:
                    transform.Translate(actionVector3);
                    break;

                case EasyWiFiConstants.ACTION_TYPE.LocalRotation:
                    transform.Rotate(actionVector3);
                    break;

                case EasyWiFiConstants.ACTION_TYPE.LocalScale:
                    transform.localScale += actionVector3;
                    break;

                default:
                    Debug.Log("Invalid Action");
                    break;
                }
            }
        }