コード例 #1
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);
    }
コード例 #2
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();
        }
    }
コード例 #3
0
    void Update()
    {
        float normalizedTime = controller.GetAxis("Grip");

        bool lastGrabbing = isGrabbing;

        isGrabbing = normalizedTime > 0.2f;
        //if (controller.GetButtonDown("Trigger") || controller.GetButtonDown("Grip"))
        //{
        //    isGrabbing = true;
        //}

        //if (controller.GetButtonUp("Trigger") || controller.GetButtonUp("Grip"))
        //{
        //    isGrabbing = false;
        //}

        // Handle state changes for buttons
        if (isGrabbing)
        {
            if (!currentRigidBody)
            {
                Pickup();
            }
            else
            {
                Vector3    currentPos = currentRigidBody.position;
                Quaternion currentRot = currentRigidBody.rotation;
                Vector3    tv         = (currentPos - lastTractorPos) / Time.deltaTime;
                lastTractorPos = currentPos;


                currentVelocity.Update(tv);

                // Update angular velocity
                Quaternion av  = currentRot * Quaternion.Inverse(lastTractorRot);
                Vector3    ave = av.eulerAngles;
                Vector3    avd = new Vector3(Mathf.DeltaAngle(0f, ave.x), Mathf.DeltaAngle(0f, ave.y), Mathf.DeltaAngle(0f, ave.z));
                lastTractorRot = currentRot;
                currentAngularVelocity.Update(avd / Time.deltaTime);
            }
        }
        else if (lastGrabbing)
        {
            Drop();
        }

        // Use the controller button or axis position to manipulate the playback time for hand model.
        anim.Play("Take", -1, normalizedTime);
    }
コード例 #4
0
    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;
            }
        }
    }