void FixedUpdate()
    {
        WebVRController controller = controllerManager.GetController(gameObject, hand);

        if (controller != null)
        {
            // Apply controller orientation and position.
            Matrix4x4  sitStand         = controller.sitStand;
            Quaternion sitStandRotation = Quaternion.LookRotation(
                sitStand.GetColumn(2),
                sitStand.GetColumn(1)
                );
            transform.rotation = sitStandRotation * controller.rotation;
            transform.position = sitStand.MultiplyPoint(controller.position);

            // Button interactions
            if (controller.GetButtonDown(WebVRInputAction.Trigger) ||
                controller.GetButtonDown(WebVRInputAction.Grip))
            {
                Pickup();
            }

            if (controller.GetButtonUp(WebVRInputAction.Trigger) ||
                controller.GetButtonUp(WebVRInputAction.Grip))
            {
                Drop();
            }
        }
    }
Пример #2
0
    void Update()
    {
        WebVRController controller = gameObject.GetComponent <WebVRController>();

        float normalizedTime = controller.GetButton("Trigger") ? 1 : controller.GetAxis("Grip");

        if (controller.GetButtonDown("Trigger"))
        {
            text.text = "trigger down";
        }
        if (controller.GetButtonDown("Grip"))
        {
            text.text = "grip down";
        }
        ;

        if (controller.GetButtonDown("Trigger") || controller.GetButtonDown("Grip"))
        {
            Pickup();
        }

        if (controller.GetButtonUp("Trigger") || controller.GetButtonUp("Grip"))
        {
            Drop();
        }

        // Use the controller button or axis position to manipulate the playback time for hand model.
        anim.Play("Take", -1, normalizedTime);
    }
Пример #3
0
    //public void Register_OnTriggerButton_UP_UnityAction(UnityAction ExtUnityAction) => onTriggerButtonUP.AddListener(ExtUnityAction);
    //public void DeRegister_OnTriggerButton_UP_UnityAction(UnityAction ExtUnityAction) => onTriggerButtonUP.RemoveListener(ExtUnityAction);



    //public void ObtainOnTriggerButton_Up_UnityEvent(UnityEvent ExtUnityEvent) => ExtUnityEvent = onTriggerButtonUP;
    //public void ObtainOnGripButton_Down_UnityEvent(UnityEvent ExtUnityEvent) => ExtUnityEvent = onGripButtonDown;
    //public void ObtainOnGripButton_Up_UnityEvent(UnityEvent ExtUnityEvent) => ExtUnityEvent = onGripButtonUP;


    public void OnUpdate(float realTime)
    {
        float normalizedTime = webVRController.GetButton("Trigger") ? 1 : webVRController.GetAxis("Grip");

#if !UNITY_EDITOR && UNITY_WEBGL
        bool isTriggerButtonDown = webVRController.GetButtonDown("Trigger");
        bool isTriggerButtonUP   = webVRController.GetButtonUp("Trigger");
        bool isGripButtonDown    = webVRController.GetButtonDown("Grip");
        bool isGripButtonUP      = webVRController.GetButtonUp("Grip");
#endif

#if UNITY_EDITOR || !UNITY_WEBGL
        //    gameObject.SetActive(true);
        bool isTriggerButtonDown = Input.GetKeyDown(KeyCode.G); // GetButtonDown("space");//UnityEngine.XR.
        bool isTriggerButtonUP   = Input.GetKeyDown(KeyCode.G); //webVRController.GetButtonUp("Trigger");
        bool isGripButtonDown    = Input.GetKeyDown(KeyCode.H); //webVRController.GetButtonDown("Grip");
        bool isGripButtonUP      = Input.GetKeyDown(KeyCode.H); //webVRController.GetButtonUp("Grip");
#endif


        thisAnimCont.Play("Take", -1, normalizedTime);


        if (isTriggerButtonDown)
        {
            StartCoroutine(SetActionAfterAnimation());
            // pointerInputObject.SetActive(true);

            onTriggerButtonDown.Invoke();
        }

        if (isTriggerButtonUP)
        {
            //  pointerInputObject.SetActive(false);
            StopCoroutine(SetActionAfterAnimation());

            onTriggerButtonUP.Invoke();
        }

        if (isGripButtonDown)
        {
            StartCoroutine(SetActionAfterAnimation());

            onGripButtonDown.Invoke();
            Pickup();
        }

        if (isGripButtonUP)
        {
            //  pointerInputObject.SetActive(false);
            StopCoroutine(SetActionAfterAnimation());

            onGripButtonUP.Invoke();
            Drop();
        }
    }
    void Update()
    {
        WebVRController controller = gameObject.GetComponent <WebVRController>();

        float normalizedTime = controller.GetButton("Trigger") ? 1 : controller.GetAxis("Grip");

        // Use the controller button or axis position to manipulate the playback time for hand model.
        anim.Play("Take", -1, normalizedTime);

        // Raycast from hand
        // Bit shift the index of the layer (8) to get a bit mask
        int layerMask = 1 << 8;

        // This would cast rays only against colliders in layer 8.
        // But instead we want to collide against everything except layer 8. The ~ operator does this, it inverts a bitmask.
        layerMask = ~layerMask;

        RaycastHit hit;
        bool       isHit = Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity, layerMask);

        if (isHit)
        {
            cursor.transform.localScale    = new Vector3(cursor.transform.localScale.x, cursor.transform.localScale.y, hit.distance);
            cursor.transform.localPosition = new Vector3(cursor.transform.localPosition.x, cursor.transform.localPosition.y, hit.distance / 2);
            cursorRend.material.color      = cursorOverColor;
        }
        else
        {
            cursor.transform.localScale    = new Vector3(cursor.transform.localScale.x, cursor.transform.localScale.y, cursorDrawDistance);
            cursor.transform.localPosition = new Vector3(cursor.transform.localPosition.x, cursor.transform.localPosition.y, cursorDrawDistance / 2);
            cursorRend.material.color      = cursorColor;
        }

        if (controller.GetButtonDown("Trigger") || controller.GetButtonDown("Grip"))
        {
        }

        if (controller.GetButtonUp("Trigger") || controller.GetButtonUp("Grip"))
        {
            if (isHit)
            {
                string image = hit.collider.gameObject.GetComponent <PanoIcon>().Image;
                RenderSettings.skybox = Resources.Load(image, typeof(Material)) as Material;
            }
        }
    }
Пример #5
0
 protected override bool GetClickUp()
 {
     return(controller.GetButtonUp(action));
 }