LHMTurnAroundMenuController.cs 1.57 KB
Newer Older
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
using UnityEngine;
using System.Collections;

public class LHMTurnAroundMenuController : MonoBehaviour {

    public float sensitivity = 100f;
    private float distance = -0.03f;

    private SteamVR_TrackedController trackedObjeckt;
    private SteamVR_Controller.Device device;
    private Transform pos;
    private Vector3 posoffset;
    private Vector2 actPadPos;
    private Vector2 lastPadPos;
    private float dif;
    private bool istouched;

    void Start()
    {
        trackedObjeckt = GetComponentInParent<SteamVR_TrackedController>();
        trackedObjeckt.PadTouched += Controller_PadTouched;
        trackedObjeckt.PadUntouched += Controller_PadUntouched;
        device = SteamVR_Controller.Input((int)trackedObjeckt.controllerIndex);
        pos = gameObject.transform.parent.FindChild("Model").transform;
        posoffset.Set(0f, distance, 0f);
        gameObject.transform.localPosition = posoffset;
    }

    void LateUpdate()
    {

        if (istouched)
        {
            actPadPos = device.GetAxis();
            dif = lastPadPos.x - actPadPos.x;
            gameObject.transform.RotateAround(pos.position + posoffset, pos.forward, dif * sensitivity);
37
            gameObject.transform.localPosition = posoffset;
Maurice Tayeb Andreas's avatar
Maurice Tayeb Andreas committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
            lastPadPos = actPadPos;
        }
    }

    private void Controller_PadUntouched(object sender, ClickedEventArgs e)
    {
        istouched = false;
    }

    private void Controller_PadTouched(object sender, ClickedEventArgs e)
    {
        lastPadPos = device.GetAxis();
        actPadPos = device.GetAxis();
        istouched = true;
    }
}