Example #1
0
        /// <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);
        }
Example #2
0
        void Start()
        {
            if (Controller != null && Tracker != null)
            {
                //VRObjectMimic controllerMimic = VRMimic.Instance.FindMimicOfObject(Controller);
                VRObjectMimic controllerMimic = VRMimic.Instance.AddTrackedObject(Controller, controllerMimicType);

                if (controllerMimic == null)
                {
                    //Setup controller tracker
                }
                else
                {
                    controllerMimic.Init(Controller);
                }

                VRObjectMimic mimic = VRMimic.Instance.AddTrackedObject(Tracker);
                if (mimic == null)
                {
                }
                else
                {
                    mimic.Init(Tracker);
                }

                ArmMimic newArm = VRMimic.Instance.ActiveBodyMimic.CreateArm(MySide, mimic, controllerMimic);
                Debug.Log("Created new arm.\n\t[Click to select it]", newArm);
            }
        }
Example #3
0
        private VRObjectMimic InitVRCamera(GameObject vrCamera = null)
        {
            GameObject go = new GameObject();

            go.transform.SetParent(transform);
            go.name   = "[" + vrCamera.name + "] Mimic";
            _vrCamera = go.AddComponent <VRObjectMimic>();
            _vrCamera.Init(vrCamera);
            _vrCamera.MimickedObjectType = VRObjectMimic.TypeOfMimickedObject.Camera;
            return(_vrCamera);
        }
Example #4
0
        public ArmMimic CreateArm(ArmMimic.ArmSide WhichSide, VRObjectMimic Tracker, VRObjectMimic Controller)
        {
            //Create an Arm Prefab
            ArmMimic newArm = GameObject.Instantiate <GameObject>(Resources.Load <GameObject>("Arm Mimic Prefab")).GetComponent <ArmMimic>();

            newArm.transform.SetParent(transform);

            //Initialize the arm prefab (handing in the side and connector points)
            newArm.Initialize(WhichSide, GetShoulder(WhichSide), Tracker, Controller);

            //Keep track of this as our Left/Right arm?
            AttachArmToOurBody(WhichSide, newArm);
            return(newArm);
        }
Example #5
0
        private VRObjectMimic InitCameraRig(GameObject vrCamera = null)
        {
            if (vrCamera.transform.parent != null)
            {
                GameObject go = new GameObject();
                go.transform.SetParent(transform);
                go.name = "[Camera Rig Mimic]";

                CameraRig = go.AddComponent <VRObjectMimic>();
                CameraRig.Init(vrCamera.transform.parent.gameObject);
                CameraRig.ObjectToMimic      = vrCamera.transform.parent.gameObject;
                CameraRig.MimickedObjectType = VRObjectMimic.TypeOfMimickedObject.CameraRig;
                return(CameraRig);
            }
            Debug.LogError("Failed to initialize Camera Rig Mimic.\n\tLikely can't identify the camera rig root for the provided vr camera.\n");
            return(null);
        }
Example #6
0
        private void Init(GameObject vrCamera = null, int hapticLayer = NSManager.HAPTIC_LAYER)
        {
            //Debug.Log("Attempting initialization " + initialized + "  cam null? " + (vrCamera == null) + "\n");
            if (!initialized)
            {
                //VRObjectMimic.InitializeVRCamera(vrCamera);

                //Set up VRCamera
                VRObjectMimic setupCameraMimic = InitVRCamera(vrCamera);

                //Set up CameraRig
                VRObjectMimic setupRigMimic = InitCameraRig(vrCamera);

                //Set up the Body Mimic
                InitBodyMimic(setupCameraMimic, setupRigMimic, hapticLayer);

                initialized = true;
            }
        }
Example #7
0
        public VRObjectMimic AddTrackedObject(GameObject objectToMimic, VRObjectMimic.TypeOfMimickedObject mimicType = VRObjectMimic.TypeOfMimickedObject.TrackedObject)
        {
            bool AlreadyTracked = false;

            //Debug.Log("Adding Tracked Object [" + objectToMimic.name + "] of type [" + mimicType.ToString() + "]\n");
            if (!AlreadyTracked)
            {
                //Make a new mimic object
                GameObject go = new GameObject();
                go.transform.SetParent(CameraRig.transform);
                go.name = "Tracked Object Mimic [" + TrackedObjects.Count + "]";
                VRObjectMimic newTracked = go.AddComponent <VRObjectMimic>();
                newTracked.ObjectToMimic = objectToMimic;
                TrackedObjects.Add(newTracked);
                newTracked.MimickedObjectType = mimicType;

                return(newTracked);
            }

            throw new System.Exception("Not Implemented Exception - returning already tracked object\n");
            //return null;
        }
Example #8
0
        private VRObjectMimic InitVRCamera(GameObject vrCamera = null)
        {
            GameObject go = new GameObject();

            go.transform.SetParent(transform);
            go.name   = "[" + vrCamera.name + "] Mimic";
            _vrCamera = go.AddComponent <VRObjectMimic>();
            _vrCamera.Init(vrCamera);
            _vrCamera.MimickedObjectType = VRObjectMimic.TypeOfMimickedObject.Camera;

            go = new GameObject();
            var collider = go.AddComponent <SphereCollider>();

            collider.isTrigger = true;
            collider.radius    = .35f;
            var rb = go.AddComponent <Rigidbody>();

            rb.constraints = RigidbodyConstraints.FreezeAll;
            go.name        = "Player Head Collider";
            go.transform.SetParent(_vrCamera.transform);

            return(_vrCamera);
        }