private void Controller_PadTouched(object sender, ClickedEventArgs e)
    {
        Vector2       touchpad = new Vector2(device.GetAxis().x, device.GetAxis().y);
        TouchDataArgs args     = new TouchDataArgs();

        if (touchpad.y > 0.5f)
        {
            args.moveDirection = MovementDirection.Up;
        }

        else if (touchpad.y < -0.5f)
        {
            args.moveDirection = MovementDirection.Down;
        }

        if (touchpad.x > 0.5f)
        {
            args.moveDirection = MovementDirection.Right;
        }
        else if (touchpad.x < -0.5f)
        {
            args.moveDirection = MovementDirection.Left;
        }

        if (ViveDataReceived != null)
        {
            ViveDataReceived(this, args);
        }
    }
    private void Controller_TriggerClicked(object sender, ClickedEventArgs e)
    {
        TouchDataArgs args = new TouchDataArgs();

        args.TriggerDown = true;
        args.TriggerUp   = false;
        if (ViveDataReceived != null)
        {
            ViveDataReceived(this, args);
        }
    }
    private void ViveHandler_ViveDataReceived(object sender, TouchDataArgs args)
    {
        ViveTrackpad controller = sender as ViveTrackpad;

        UnityMainThreadDispatcher.Instance().Enqueue(() =>
        {
            if (args.TriggerDown)
            {
                SaveDataModule.Instance.WriteToTimeLine(controller.transform.name + " Trigger Down");
            }
            if (InputType == KeyboardInputType.GazeAndClick && controller.IsRightController())
            {
                if (args.TriggerDown)
                {
                    InputButtonDown     = true;
                    InputButtonHeldDown = true;
                    //InputButtonUp = false;
                }
                else
                {
                    //InputButtonDown = false;
                    //InputButtonHeldDown = false;
                    InputButtonUp = true;
                }
            }
            if (InputType == KeyboardInputType.Ray || InputType == KeyboardInputType.DrumStick)
            {
                if (args.TriggerDown)
                {
                    InputButtonDown     = true;
                    InputButtonHeldDown = true;
                    //InputButtonUp = false;
                }
                else
                {
                    //InputButtonDown = false;
                    //InputButtonHeldDown = false;
                    InputButtonUp = true;
                }
            }

            if (args.moveDirection != MovementDirection.None)
            {
            }
        });
    }
    private void Controller_Gripped(object sender, ClickedEventArgs e)
    {
        TouchDataArgs args = new TouchDataArgs();

        if (transform.name.Contains("left"))
        {
            args.leftGripped = true;
        }
        else if (transform.name.Contains("right"))
        {
            args.rightGripped = true;
        }
        if (ViveDataReceived != null)
        {
            ViveDataReceived(this, args);
        }
    }
    private void Pointer_PointerDataReceivedEvent(object sender, TouchDataArgs args)
    {
        UnityMainThreadDispatcher.Instance().Enqueue(() =>
        {
            if (InputType == KeyboardInputType.TouchPad)
            {
                action = args.action;
                x      = args.x;
                y      = args.y;
                top    = args.top;
                bottom = args.bottom;
                left   = args.left;
                right  = args.right;
                if (action == 0)
                {
                    prevX = x;
                    prevY = y;
                    //HandleTouchInput(action);
                }
                else if (action == 2)
                {
                    vec    = Camera.main.WorldToScreenPoint(pointer.transform.position);
                    oldVec = Camera.main.WorldToScreenPoint(pointer.transform.position);

                    width  = Math.Abs(right - left);
                    height = Math.Abs(bottom - top);

                    //Debug.Log("DiffX: " + (prevX - x) + "," + "DiffY: " + (prevY - y));
                    //Debug.Log("Width: " + width + ",Height: " + height);
                    touchMovementPercentageX = ((prevX - x) * Screen.height) / height * pointerSpeedMultiplier;
                    touchMovementPercentageY = ((prevY - y) * Screen.height) / height * pointerSpeedMultiplier;
                    //Debug.Log("PercentX: " + touchMovementPercentageX + "," + "PercentY: " + touchMovementPercentageY);

                    //float screenMovementX = Screen.height * touchMovementPercentageX;
                    //float screenMovementY = Screen.width * touchMovementPercentageY;

                    initialValX = 0;
                    initialValY = 0;
                    if ((prevX - x) < 0)
                    {
                        initialValX = -1;
                    }
                    else
                    {
                        initialValX = 1;
                    }
                    if ((prevY - y) < 0)
                    {
                        initialValY = -1;
                    }
                    else
                    {
                        initialValY = 1;
                    }
                    vec.x += -(touchMovementPercentageX / Time.deltaTime / 40 + initialValX);
                    vec.y += (touchMovementPercentageY / Time.deltaTime / 40 + initialValY);

                    lerpedVec = Vector3.Lerp(oldVec, vec, 1.0f - Mathf.Exp(-10 * Time.deltaTime));

                    position = Camera.main.ScreenToWorldPoint(lerpedVec);
                    //Vector3 worldVec = Camera.main.ScreenToWorldPoint(vec);

                    //Vector3 position = Vector3.Lerp(pointer.transform.position, worldVec, 1.0f - Mathf.Exp(-speed * Time.deltaTime));
                    position.z = Math.Abs(Camera.main.transform.position.z - transform.position.z) + pointerDistanceFromCamera;

                    pointer.transform.position = position;

                    prevX = x;
                    prevY = y;
                }
            }
        });
    }
Beispiel #6
0
    private void TouchDataHandler_OnMessageReceived(object sender, ClientEventArgs e)
    {
        Client      client  = e.Client;                                 //Get the Client
        AsyncServer server  = sender as AsyncServer;
        string      msg     = Encoding.ASCII.GetString(client.Message); //Get the message as a string
        bool        hasData = false;

        for (int i = 0; i < client.Message.Length; i++)
        {
            if (client.Message[i] != 0)
            {
                hasData = true;
            }
        }
        if (!hasData)
        {
            server.CloseConnection(client);
        }
        //Debug.Log("MSG: " + msg);

        if (msg.Contains(","))
        {
            string[] lines = msg.Split('\n');
            foreach (var line in lines)
            {
                //Debug.Log("Line: " + line);
                if (line.Contains(","))
                {
                    try
                    {
                        var      newline = line.Replace(",", "");
                        string[] values  = newline.Split(':');
                        //Debug.Log("v0:"+ values[0]+ ",v1:" + values[1]+ ",v2:" + values[2]);
                        int action = Int32.Parse(values[0].Trim());
                        int x      = Int32.Parse(values[1].Trim());
                        int y      = Int32.Parse(values[2].Trim());
                        int top    = Int32.Parse(values[3].Trim());
                        int bottom = Int32.Parse(values[4].Trim());
                        int left   = Int32.Parse(values[5].Trim());
                        int right  = Int32.Parse(values[6].Trim());

                        TouchDataArgs args = new TouchDataArgs
                        {
                            action = action,
                            x      = x,
                            y      = y,
                            top    = top,
                            bottom = bottom,
                            left   = left,
                            right  = right,
                        };

                        if (TouchDataReceivedEvent != null)
                        {
                            TouchDataReceivedEvent.Invoke(this, args);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.LogError(ex.Message);
                    }
                }
            }
        }
    }