示例#1
0
        public void ChangeHandsModel(int childIndex, bool save = false)
        {
            // Deactivate any previous models
            if (LeftHandGFXHolder.childCount > _selectedHandGFX)
            {
                LeftHandGFXHolder.GetChild(_selectedHandGFX).gameObject.SetActive(false);
                RightHandGFXHolder.GetChild(_selectedHandGFX).gameObject.SetActive(false);
            }

            // Loop back to beginning if we went over
            _selectedHandGFX = childIndex;
            if (_selectedHandGFX > LeftHandGFXHolder.childCount - 1)
            {
                _selectedHandGFX = 0;
            }

            // Activate New
            GameObject leftHand  = LeftHandGFXHolder.GetChild(_selectedHandGFX).gameObject;
            GameObject rightHand = RightHandGFXHolder.GetChild(_selectedHandGFX).gameObject;

            leftHand.SetActive(true);
            rightHand.SetActive(true);

            // Update any animators
            HandController leftControl  = LeftHandGFXHolder.parent.GetComponent <HandController>();
            HandController rightControl = RightHandGFXHolder.parent.GetComponent <HandController>();

            if (leftControl && rightControl)
            {
                leftControl.HandAnimator  = leftHand.GetComponentInChildren <Animator>();
                rightControl.HandAnimator = rightHand.GetComponentInChildren <Animator>();
            }

            // Enable / Disable IK Character. For demo purposes only
            if (IKBody != null)
            {
                IKBody.gameObject.SetActive(leftHand.transform.name.Contains("IK"));
            }

            // Change UI Pointer position depending on if we're using Oculus Hands or Oculus Controller Model
            // This is for the demo. Typically this would be fixed to a bone or transform
            // Oculus Touch Controller is positioned near the front
            if (leftHand.transform.name.StartsWith("OculusTouchForQuestAndRift") && uiPoint != null)
            {
                uiPoint.transform.localPosition    = new Vector3(0, 0, 0.0462f);
                uiPoint.transform.localEulerAngles = new Vector3(0, -4.5f, 0);
            }
            // Hand Model
            else if (_selectedHandGFX != 0 && uiPoint != null)
            {
                uiPoint.transform.localPosition    = new Vector3(0.045f, 0.07f, 0.12f);
                uiPoint.transform.localEulerAngles = new Vector3(-9.125f, 4.65f, 0);
            }

            if (save)
            {
                PlayerPrefs.SetInt("HandSelection", _selectedHandGFX);
            }
        }
示例#2
0
        public void AssignPlayerObjects()
        {
            GameObject player = GameObject.FindGameObjectWithTag("Player");

            PlayerHeadTransform = getChildTransformByName(player.transform, "CenterEyeAnchor");

            // Using an explicit Transform name to make sure we grab the right one in the scene
            PlayerLeftHandTransform = GameObject.Find("ModelsLeft").transform;
            LeftHandController      = PlayerLeftHandTransform.parent.GetComponentInChildren <HandController>();

            PlayerRightHandTransform = GameObject.Find("ModelsRight").transform;
            RightHandController      = PlayerRightHandTransform.parent.GetComponentInChildren <HandController>();
        }
示例#3
0
        public void ChangeHandsModel(int childIndex, bool save = false)
        {
            // Deactivate any previous models
            if (activatedLeftModel != null)
            {
                activatedLeftModel.gameObject.SetActive(false);
            }
            if (activatedRightModel != null)
            {
                activatedRightModel.gameObject.SetActive(false);
            }

            // Activate new Model


            // Loop back to beginning if we went over
            _selectedHandGFX = childIndex;
            if (_selectedHandGFX > leftHandModels.Count - 1)
            {
                _selectedHandGFX = 0;
            }

            // Activate New
            activatedLeftModel  = leftHandModels[_selectedHandGFX];
            activatedRightModel = rightHandModels[_selectedHandGFX];

            activatedLeftModel.gameObject.SetActive(true);
            activatedRightModel.gameObject.SetActive(true);

            // Update any animators
            HandController leftControl  = LeftHandGFXHolder.parent.GetComponent <HandController>();
            HandController rightControl = RightHandGFXHolder.parent.GetComponent <HandController>();

            // Physical hands have their own animator controler
            bool isPhysicalHand = activatedLeftModel.name.ToLower().Contains("physical");

            if (isPhysicalHand)
            {
                leftControl.HandAnimator  = null;
                rightControl.HandAnimator = null;
            }
            else if (leftControl && rightControl)
            {
                leftControl.HandAnimator  = activatedLeftModel.GetComponentInChildren <Animator>(true);
                rightControl.HandAnimator = activatedRightModel.GetComponentInChildren <Animator>(true);
            }

            // Enable / Disable IK Character. For demo purposes only
            if (IKBody != null)
            {
                IKBody.gameObject.SetActive(activatedLeftModel.transform.name.Contains("IK"));
            }

            // Change UI Pointer position depending on if we're using Oculus Hands or Oculus Controller Model
            // This is for the demo. Typically this would be fixed to a bone or transform
            // Oculus Touch Controller is positioned near the front
            if ((activatedLeftModel.transform.name.StartsWith("OculusTouchForQuestAndRift") || activatedLeftModel.transform.name.StartsWith("ControllerReferences")) && uiPoint != null)
            {
                uiPoint.transform.localPosition    = new Vector3(0, 0, 0.0462f);
                uiPoint.transform.localEulerAngles = new Vector3(0, 0f, 0);
            }
            // Hand Model
            else if (_selectedHandGFX != 0 && uiPoint != null)
            {
                uiPoint.transform.localPosition    = new Vector3(0.0392f, 0.0033f, 0.0988f);
                uiPoint.transform.localEulerAngles = new Vector3(0, 0, 0);
            }

            if (save)
            {
                PlayerPrefs.SetInt("HandSelection", _selectedHandGFX);
            }
        }