private void Grab(GameObject iGrabbedObject) { if (iGrabbedObject == null) { return; } // Initialize manipulated node m_CurrentManipulatedObject = iGrabbedObject; VRActor vrActorScript = m_CurrentManipulatedObject.GetComponent <VRActor>(); m_ObjectPreviousSyncDir = vrActorScript.SyncDirection; vrActorScript.SyncDirection = MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity; vrNode3D middleVRNode = vrActorScript.GetMiddleVRNode(); m_it.SetManipulatedNode(middleVRNode); // Save initial position m_ObjectInitialLocalPosition = m_CurrentManipulatedObject.transform.localPosition; m_ObjectInitialLocalRotation = m_CurrentManipulatedObject.transform.localRotation; // Deactivate selection during the manipulation vrInteraction selection = MiddleVR.VRInteractionMgr.GetActiveInteractionByTag("ContinuousSelection"); if (selection != null) { m_PausedSelection = selection; MiddleVR.VRInteractionMgr.Deactivate(m_PausedSelection); } }
private void Ungrab() { if (m_CurrentManipulatedObject == null) { return; } // Give to return objects script VRInteractionManipulationReturnObjects returningObjectScript = this.GetComponent <VRInteractionManipulationReturnObjects>(); if (returningObjectScript != null) { if (returningObjectScript.enabled) { returningObjectScript.AddReturningObject(m_CurrentManipulatedObject, m_ObjectInitialLocalPosition, m_ObjectInitialLocalRotation, false); } } // Reset m_it.SetManipulatedNode(null); VRActor vrActorScript = m_CurrentManipulatedObject.GetComponent <VRActor>(); vrActorScript.SyncDirection = m_ObjectPreviousSyncDir; m_CurrentManipulatedObject = null; // Reactivate selection after the manipulation if (m_PausedSelection != null) { MiddleVR.VRInteractionMgr.Activate(m_PausedSelection); m_PausedSelection = null; } }
private void Grab(GameObject iGrabbedObject) { if (iGrabbedObject == null) { return; } m_CurrentManipulatedObject = iGrabbedObject; VRActor vrActorScript = m_CurrentManipulatedObject.GetComponent <VRActor>(); m_ObjectPreviousSyncDir = vrActorScript.SyncDirection; vrActorScript.SyncDirection = MVRNodesMapper.ENodesSyncDirection.MiddleVRToUnity; vrNode3D middleVRNode = vrActorScript.GetMiddleVRNode(); m_it.SetManipulatedNode(middleVRNode); m_it.SetPivotPositionVirtualWorld(MVRTools.FromUnity(m_CurrentManipulatedObject.GetComponent <Collider>().bounds.center)); // Save initial position m_ObjectInitialLocalPosition = m_CurrentManipulatedObject.transform.localPosition; m_ObjectInitialLocalRotation = m_CurrentManipulatedObject.transform.localRotation; // Deactivate selection during the manipulation vrInteraction selection = MiddleVR.VRInteractionMgr.GetActiveInteractionByTag("ContinuousSelection"); if (selection != null) { m_PausedSelection = selection; MiddleVR.VRInteractionMgr.Deactivate(m_PausedSelection); } // Hide Wand m_VRMgr.ShowWandGeometry(false); }
public void AddReturningObject(GameObject iObject, Vector3 iLocalPosition, Quaternion iLocalRotation, bool iInstantReturn) { ReturningObject newObject; newObject.Object = iObject; newObject.TargetLocalPosition = iLocalPosition; newObject.TargetLocalRotation = iLocalRotation; newObject.StartLocalPosition = iObject.transform.localPosition; newObject.StartLocalRotation = iObject.transform.localRotation; newObject.InstantReturn = iInstantReturn; newObject.WasGrabbable = false; newObject.WasCollidable = false; // Not grabbable during return VRActor actor = iObject.GetComponent <VRActor>(); if (actor != null) { newObject.WasGrabbable = actor.Grabable; actor.Grabable = false; } // No collisions during return Collider collider = iObject.GetComponent <Collider>(); if (collider != null) { newObject.WasCollidable = collider.enabled; collider.enabled = false; } m_ReturningObjects.Add(newObject); }
private void Ungrab() { if (m_CurrentManipulatedObject == null) { return; } if (OnGrab != null) { OnGrab(this, e_GrabStatus.UNGRABBED); } // Give to return objects script VRInteractionManipulationReturnObjects returningObjectScript = this.GetComponent <VRInteractionManipulationReturnObjects>(); if (returningObjectScript != null) { if (returningObjectScript.enabled) { returningObjectScript.AddReturningObject(m_CurrentManipulatedObject, m_ManipulatedObjectInitialLocalPosition, m_ManipulatedObjectInitialLocalRotation, false); } } // Reset m_it.SetManipulatedNode(null); VRActor vrActorScript = m_CurrentManipulatedObject.GetComponent <VRActor>(); vrActorScript.SyncDirection = m_ObjectPreviousSyncDir; // Unpause rigidbody acceleration Rigidbody manipulatedRigidbody = m_CurrentManipulatedObject.GetComponent <Rigidbody>(); if (manipulatedRigidbody != null) { manipulatedRigidbody.isKinematic = m_ManipulatedObjectInitialIsKinematic; } // Reactivate selection after the manipulation if (m_PausedSelection != null) { MiddleVR.VRInteractionMgr.Activate(m_PausedSelection); m_PausedSelection = null; } m_CurrentManipulatedObject = null; }
private void _ResetObjectProperties(ReturningObject iObject) { // Reset Grabbable VRActor actor = iObject.Object.GetComponent <VRActor>(); if (actor != null) { actor.Grabable = iObject.WasGrabbable; } // Reset collisions Collider collider = iObject.Object.GetComponent <Collider>(); if (collider != null) { collider.enabled = iObject.WasCollidable; } }
private void Grab(GameObject iGrabbedObject) { if (iGrabbedObject == null) { return; } if (OnGrab != null) { OnGrab(this, e_GrabStatus.GRABBED); } // Initialize manipulated node m_CurrentManipulatedObject = iGrabbedObject; VRActor vrActorScript = m_CurrentManipulatedObject.GetComponent <VRActor>(); m_ObjectPreviousSyncDir = vrActorScript.SyncDirection; vrActorScript.SyncDirection = MVRNodesMapper.ENodesSyncDirection.BothDirections; vrNode3D middleVRNode = vrActorScript.GetMiddleVRNode(); m_it.SetManipulatedNode(middleVRNode); // Save initial position m_ManipulatedObjectInitialLocalPosition = m_CurrentManipulatedObject.transform.localPosition; m_ManipulatedObjectInitialLocalRotation = m_CurrentManipulatedObject.transform.localRotation; // Pause rigidbody acceleration Rigidbody manipulatedRigidbody = iGrabbedObject.GetComponent <Rigidbody>(); if (manipulatedRigidbody != null) { m_ManipulatedObjectInitialIsKinematic = manipulatedRigidbody.isKinematic; manipulatedRigidbody.isKinematic = true; } // Deactivate selection during the manipulation vrInteraction selection = MiddleVR.VRInteractionMgr.GetActiveInteractionByTag("ContinuousSelection"); if (selection != null) { m_PausedSelection = selection; MiddleVR.VRInteractionMgr.Deactivate(m_PausedSelection); } }
protected virtual void OnTriggerStay(Collider collider) { if (TouchEvents == VRTouch.ETouchParameter.SendTouchEvents) { // We are the touch emitter GameObject touchedObject = collider.gameObject; VRActor actor = touchedObject.GetComponent <VRActor>(); if (actor != null) { VRTouch touch = _FindVRTouch(touchedObject); if (touch != null) { // Send message to touched object actor._OnMVRTouchMoved(touch); // Send message to ourself this.SendMessage("OnMVRTouchMoved", touch, SendMessageOptions.DontRequireReceiver); } } } }
protected virtual void _SendVRTouchEnd(VRTouch iTouch, bool iOnDestroy) { // Other actor VRActor actor = iTouch.TouchedObject.GetComponent <VRActor>(); if (actor != null) { // Send message to touched object actor._OnMVRTouchEnd(iTouch); // Send message to ourself this.SendMessage("OnMVRTouchEnd", iTouch, SendMessageOptions.DontRequireReceiver); // XXX Cb: in OnDestroy we are iterating over the m_Touches list // here we are removing an element, so in OnDestroy, foreach // complains that the list has been modified // There is probably a cleaner way to do this !! if (!iOnDestroy) { // Ourself m_Touches.Remove(iTouch); } } }
// ***** SEND TOUCH protected virtual void OnTriggerEnter(Collider collider) { if (TouchEvents == VRTouch.ETouchParameter.SendTouchEvents) { GameObject touchedObject = collider.gameObject; // Other actor VRActor otherActor = touchedObject.GetComponent <VRActor>(); if (otherActor != null) { VRTouch touch = new VRTouch(); touch.TouchedObject = touchedObject; touch.TouchObject = this.gameObject; // Send message to touched object otherActor._OnMVRTouchBegin(touch); // Send message to ourself so attached script can also react this.SendMessage("OnMVRTouchBegin", touch, SendMessageOptions.DontRequireReceiver); m_Touches.Add(touch); } } }
protected void Initialize() { GameObject vrSystemCenterNode = null; if (GameObject.Find("VRManager").GetComponent <VRManagerScript>().VRSystemCenterNode != null) { vrSystemCenterNode = GameObject.Find("VRManager").GetComponent <VRManagerScript>().VRSystemCenterNode; } else { vrNode3D vrSystemMVRNode = MiddleVR.VRDisplayMgr.GetNodeByTag(MiddleVR.VR_SYSTEM_CENTER_NODE_TAG); if (vrSystemMVRNode != null) { vrSystemCenterNode = GameObject.Find(vrSystemMVRNode.GetName()); } } if (vrSystemCenterNode == null) { return; } // If our navigation node has a parent, we want to move relatively to this vehicule if (vrSystemCenterNode.transform.parent != null) { m_NavRefNode = vrSystemCenterNode.transform.parent.gameObject; if (m_NavRefNode != null) { VRActor vrActorScript = m_NavRefNode.AddComponent <VRActor>(); m_NavRefVrNode = vrActorScript.GetMiddleVRNode(); m_it.SetNavigationReferentialNode(m_NavRefVrNode); } } m_Initialized = true; }
// Update is called once per frame void Update() { if (m_Buttons == null) { m_Buttons = MiddleVR.VRDeviceMgr.GetWandButtons(); } if (m_Buttons == null) { if (m_SearchedButtons == false) { //MiddleVRTools.Log("[~] VRWandInteraction: Wand buttons undefined. Please specify Wand Buttons in the configuration tool."); m_SearchedButtons = true; } } Collider hit = GetClosestHit(); if (hit != null) { //print("Closest : " + hit.name); if (m_CurrentObject != hit.gameObject && m_ObjectInHand == null) { //MiddleVRTools.Log("Enter other : " + hit.name); HighlightObject(m_CurrentObject, false); m_CurrentObject = hit.gameObject; HighlightObject(m_CurrentObject, true); if (book != null && !book.name.Equals(m_CurrentObject.name)) { if (book.GetComponent <BookControl>() != null) { book.GetComponent <BookControl>().wand = false; } } //MiddleVRTools.Log("Current : " + m_CurrentObject.name); } } // Else else { //MiddleVRTools.Log("No touch ! "); if (m_CurrentObject != null && m_CurrentObject != m_ObjectInHand) { HighlightObject(m_CurrentObject, false, HighlightColor); m_CurrentObject = null; } } //MiddleVRTools.Log("Current : " + m_CurrentObject); if (m_Buttons != null && m_CurrentObject != null) { uint MainButton = MiddleVR.VRDeviceMgr.GetWandButton0(); VRActor script = m_CurrentObject.GetComponent <VRActor>(); if (book != null && !book.name.Equals(m_CurrentObject.name)) { if (book.GetComponent <BookControl>() != null) { book.GetComponent <BookControl>().wand = false; } } //MiddleVRTools.Log("Trying to take :" + m_CurrentObject.name); if (script != null) { if (m_CurrentObject.GetComponent <BookControl>() != null) { book = m_CurrentObject; book.GetComponent <BookControl>().selectBook(); } // Grab if (m_Buttons.IsToggled(MainButton)) { if (script.Grabable) { Grab(m_CurrentObject); } } // Release if (m_Buttons.IsToggled(MainButton, false) && m_ObjectInHand != null) { Ungrab(); } // Action if (((!RepeatAction && m_Buttons.IsToggled(MainButton)) || (RepeatAction && m_Buttons.IsPressed(MainButton)))) { m_CurrentObject.SendMessage("VRAction", SendMessageOptions.DontRequireReceiver); } } else { if (book != null && book.GetComponent <BookControl>() != null) { book.GetComponent <BookControl>().wand = false; } } } }
// Update is called once per frame void Update() { Collider hit = GetClosestHit(); if (hit != null) { //print("Closest : " + hit.name); if (CurrentObject != hit.gameObject && ObjectInHand == null) { //MiddleVRTools.Log("Enter other : " + hit.name); HighlightObject(CurrentObject, false); CurrentObject = hit.gameObject; HighlightObject(CurrentObject, true); //MiddleVRTools.Log("Current : " + CurrentObject.name); } } // Else else { //MiddleVRTools.Log("No touch ! "); if (CurrentObject != null && CurrentObject != ObjectInHand) { HighlightObject(CurrentObject, false, HighlightColor); CurrentObject = null; } } //MiddleVRTools.Log("Current : " + CurrentObject); if (m_Buttons == null) { m_Buttons = MiddleVR.VRDeviceMgr.GetJoystick(JoystickName); } if (m_Buttons == null) { if (m_SearchedButtons == false) { //MiddleVRTools.Log("[~] VRWandInteraction: Wand buttons undefined. Please specify Wand Buttons in the configuration tool."); m_SearchedButtons = true; } } if (m_Buttons != null && CurrentObject != null) { VRActor script = CurrentObject.GetComponent <VRActor>(); //MiddleVRTools.Log("Trying to take :" + CurrentObject.name); if (script != null) { // Grab if (m_Buttons.IsButtonToggled(m_MainButton)) { if (script.Grabable) { Grab(CurrentObject); } } // Release if (m_Buttons.IsButtonToggled(m_MainButton, false) && ObjectInHand != null) { Ungrab(); } // Action if (((!RepeatAction && m_Buttons.IsButtonToggled(m_MainButton)) || (RepeatAction && m_Buttons.IsButtonPressed(m_MainButton)))) { CurrentObject.SendMessage("VRAction", SendMessageOptions.DontRequireReceiver); } } } }