Beispiel #1
0
        private void InitBodyMimic(VRObjectMimic vrCamera, VRObjectMimic cameraRigMimic, int hapticLayer = NSManager.HAPTIC_LAYER)
        {
            Camera playerCameraToHideBodyFrom = vrCamera.ObjectToMimic.GetComponent <Camera>();

            ActiveBodyMimic = BodyMimic.Initialize(playerCameraToHideBodyFrom, cameraRigMimic, hapticLayer);
            HardlightSuit.Find().SetColliderState();
        }
        /// <summary>
        /// This function creates and initializes the Body Mimic
        /// </summary>
        /// <param name="vrCamera">The camera to hide the body from. Calls camera.HideLayer(int)</param>
        /// <param name="hapticObjectLayer">The layer that is removed from the provided camera's culling mask.</param>
        /// <returns>The created body mimic</returns>
        public static BodyMimic Initialize(Camera vrCamera, VRObjectMimic CameraRigMimic, int hapticObjectLayer = NSManager.HAPTIC_LAYER)
        {
            GameObject bodyMimicPrefab = Resources.Load <GameObject>("Body Mimic");

            //Instantiate the prefab of the body mimic.
            GameObject newMimic = Instantiate <GameObject>(bodyMimicPrefab);

            newMimic.name = "Body Mimic";

            BodyMimic mimic = null;

            if (newMimic != null)
            {
                if (vrCamera == null)
                {
                    Debug.LogWarning("Attempting to initialize body mimic with a null camera.\n\tDefaulting to Camera.main.gameOBject instead. This might not work\n");
                }

                GameObject cameraObject = vrCamera == null ? Camera.main.gameObject : vrCamera.gameObject;

                vrCamera = cameraObject.GetComponent <Camera>();

                //Set the BodyMimic's target to the VRObjectMimic
                mimic     = newMimic.GetComponent <BodyMimic>();
                mimic.hmd = vrCamera.GetComponent <WatchedByMimic>().WatchingMimic.gameObject;
                mimic.transform.SetParent(CameraRigMimic.transform);
            }
            if (vrCamera != null && mimic.HideBodyMimicFromView)
            {
                vrCamera.HideLayer(hapticObjectLayer);
            }

            return(mimic);
        }