Пример #1
0
    IEnumerator Start()
    {
        MaxRenderScale = SteamVR_Camera.sceneResolutionScale;
        MinRenderScale = SteamVR_Camera.sceneResolutionScale * 0.1f;
        //if (PlayerPrefs.GetInt("dynamic_resolution", 0) == 1) {
        StartCoroutine(FPS());
        //}
        yield return(new WaitForSeconds(1f));

        while (RightHand.transform.localPosition == Vector3.zero)
        {
            yield return(null);
        }

        if (VRInputBridge.instance.aimScript_ref.primaryHand == HandSide.Left)
        {
            LHandSphere.SetActive(false);
            RHandSphere.SetActive(true);
        }
        else
        {
            LHandSphere.SetActive(true);
            RHandSphere.SetActive(false);
        }

        if (VRInputBridge.instance.aimScript_ref.gun_script.HasGunComponent(GunAspect.FIRING))
        {
            muzzlepos    = VRInputBridge.instance.aimScript_ref.gun_instance.GetComponent <FiringComponent>().point_muzzle;
            canFrontGrab = muzzlepos.localPosition.z > 0.3f;
        }
        else
        {
            canFrontGrab = false;
        }

        if (ImGuiUnity.instance != null)
        {
            ImGuiUnity.instance.vrHandObject   = RightHand;
            ImGuiUnity.instance.vrCameraObject = Head;
        }


        if (VRInputBridge.instance.aimScript_ref.gun_script.HasGunComponent(GunAspect.TRIGGER_VISUAL))
        {
            Renderer triggerRenderer = VRInputBridge.instance.aimScript_ref.gun_script.GetComponent <TriggerVisualComponent>().trigger.GetComponent <MeshRenderer>();
            if (triggerRenderer == null)
            {
                triggerRenderer = VRInputBridge.instance.aimScript_ref.gun_script.GetComponentInChildren <TriggerVisualComponent>().trigger.GetComponent <MeshRenderer>();
            }
            if (triggerRenderer != null)
            {
                localTriggerCenter = triggerRenderer.transform.parent.InverseTransformPoint(triggerRenderer.bounds.center);
                if (RightHand.transform.GetChild(0).Find("trigger").GetChild(0) != null)
                {
                    controllerTriggerCenter = RightHand.transform.GetChild(0).Find("trigger").GetChild(0).localPosition;
                }
                relativeTriggerOffset = (localTriggerCenter - controllerTriggerCenter) - (Vector3.forward * 0.035f);
                readyInit             = true;
            }
        }

        meleeWeapon = VRInputBridge.instance.aimScript_ref.gun_script.gameObject.GetComponentInChildren <MeleeWeaponInfo>();
        if (meleeWeapon != null)
        {
            MeleeWeaponInfo info = meleeWeapon;
            localTriggerCenter = VRInputBridge.instance.aimScript_ref.gun_script.transform.InverseTransformPoint(info.MainGrip.position);
            meleeWeapon.MainGrip.GetComponentInParent <Animator>().SetBool("VRPose", true);
            controllerTriggerCenter = RightMeleeGrip.transform.localPosition;
            relativeTriggerOffset   = (localTriggerCenter - controllerTriggerCenter);
            readyInit = true;
        }

        /*Renderer[] gunRenderers = VRInputBridge.instance.aimScript_ref.gun_script.GetComponentsInChildren<Renderer>();
         *
         * bool WasGunShader = gunRenderers[0].material.shader.name.ToLower().Contains("gunshader");
         *
         * if (WasGunShader) {
         *  float oldDeet = gunRenderers[0].material.GetFloat(0);
         *  float oldScale = gunRenderers[0].material.GetFloat(1);
         *  float oldMetallic = gunRenderers[0].material.GetFloat(2);
         *  float oldSmoothness = gunRenderers[0].material.GetFloat(3);
         *
         *  gunMat.SetFloat(0, oldDeet);
         *  gunMat.SetFloat(1, oldScale);
         *  gunMat.SetFloat(2, oldMetallic);
         *  gunMat.SetFloat(3, oldSmoothness);
         *
         *  if(gunRenderers[0].material.mainTexture != null) {
         *      gunMat.SetTexture(0, gunRenderers[0].material.mainTexture);
         *  }
         *
         *  foreach (Renderer rend in gunRenderers) {
         *      rend.material = gunMat;
         *  }
         * }
         * else {
         *  float oldMetallic = gunRenderers[0].material.GetFloat(0);
         *  float oldSmoothness = gunRenderers[0].material.GetFloat(1);
         *
         *  gunMat.SetFloat(0, oldMetallic);
         *  gunMat.SetFloat(1, oldSmoothness);
         *
         *  if (gunRenderers[0].material.mainTexture != null) {
         *      gunMat.SetTexture(0, gunRenderers[0].material.mainTexture);
         *  }
         *
         *  foreach (Renderer rend in gunRenderers) {
         *      rend.material = gunMat;
         *  }
         * }*/
    }
Пример #2
0
    void Update()
    {
        Debug.DrawLine(RightHand.transform.position, RightHand.transform.position - (RightHand.transform.rotation * relativeTriggerOffset), Color.red);
        if (TallestHead < Head.transform.localPosition.y)
        {
            TallestHead = Head.transform.localPosition.y + 0.1f;
        }

        if (canFrontGrab)
        {
            if (LHandSphere.activeSelf)
            {
                if (Vector3.Distance(Vector3.Lerp(RightHand.transform.position, muzzlepos.position, 0.65f), LHandSphere.transform.position) < 0.1f)
                {
                    isFrontGrabbing = ActionPress(HandSide.Left);
                }

                if (isFrontGrabbing)
                {
                    LHandSphere.GetComponent <Renderer>().enabled = false;
                    isFrontGrabbing = ActionPress(HandSide.Left);
                }
                if (ActionPressUp(HandSide.Left))
                {
                    LHandSphere.GetComponent <Renderer>().enabled = true;
                }
            }

            if (RHandSphere.activeSelf)
            {
                if (Vector3.Distance(Vector3.Lerp(LeftHand.transform.position, muzzlepos.position, 0.65f), RHandSphere.transform.position) < 0.1f)
                {
                    isFrontGrabbing = ActionPress(HandSide.Right);
                }

                if (isFrontGrabbing)
                {
                    RHandSphere.GetComponent <Renderer>().enabled = false;
                    isFrontGrabbing = ActionPress(HandSide.Right);
                }
                if (ActionPressUp(HandSide.Right))
                {
                    RHandSphere.GetComponent <Renderer>().enabled = true;
                }
            }
        }

        InventoryPos.transform.localPosition = (new Vector3(Head.transform.localPosition.x - (transform.InverseTransformDirection(Head.transform.forward).x * 0.15f), Head.transform.localPosition.y, Head.transform.localPosition.z - (transform.InverseTransformDirection(Head.transform.forward).z * 0.15f)) * Head.transform.localScale.x) - (Vector3.up * TallestHead / 3f);
        InventoryPos.transform.rotation      = transform.rotation;

        //if (ChangeHandedness.GetStateDown(SteamVR_Input_Sources.Any)) {
        //    PlayerPrefs.SetInt("left_handed", PlayerPrefs.GetInt("left_handed") == 1?0:1);
        //}

        if (PlayerPrefs.GetInt("left_handed", 0) == 1)
        {
            VRInputBridge.instance.aimScript_ref.primaryHand   = HandSide.Left;
            VRInputBridge.instance.aimScript_ref.secondaryHand = HandSide.Right;
            LHandSphere.SetActive(false);
            RHandSphere.SetActive(true);
        }
        else
        {
            VRInputBridge.instance.aimScript_ref.primaryHand   = HandSide.Right;
            VRInputBridge.instance.aimScript_ref.secondaryHand = HandSide.Left;
            LHandSphere.SetActive(true);
            RHandSphere.SetActive(false);
        }

        //InventoryPos.transform.LookAt(Head.transform.forward - new Vector3(0, Head.transform.forward.y, 0));
        //InventoryPos.transform.position += InventoryPos.transform.forward * 0.5f;
    }