private static Transform GetTooltipTransform(VRDevice device, Location location) { Transform controller = GlobalState.GetControllerTransform(device); if (null == controller) { return(null); } Transform tooltip = null; switch (location) { case Location.Grip: tooltip = controller.Find("GripButtonAnchor/Tooltip"); break; case Location.Trigger: tooltip = controller.Find("TriggerButtonAnchor/Tooltip"); break; case Location.Primary: tooltip = controller.Find("PrimaryButtonAnchor/Tooltip"); break; case Location.Secondary: tooltip = controller.Find("SecondaryButtonAnchor/Tooltip"); break; case Location.Joystick: tooltip = controller.Find("JoystickBaseAnchor/Tooltip"); break; } return(tooltip); }
/// <summary> /// Places the player in the specified position of the world /// </summary> /// <param name="worldPosition"></param> public void SetWorldPosition(Vector3 worldPosition) { // There are two things moving the camera: the camera parent (that this script is attached to) // and the user's head (which the MR device is attached to. :)). When setting the world position, // we need to set it relative to the user's head in the scene so they are looking/standing where // we expect. var newPosition = worldPosition - (CameraCache.Main.transform.position - transform.position); // If we're Stationary, we'll need to raycast to estimate our height. In RoomScale, that will be accounted for by the offset between the camera and its parent. #if UNITY_2017_2_OR_NEWER if (XRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor) #else if (VRDevice.GetTrackingSpaceType() == TrackingSpaceType.Stationary && !StayOnTheFloor) #endif { RaycastHit hitInfo; newPosition.y += (Physics.Raycast(CameraCache.Main.transform.position, Vector3.down, out hitInfo, 5.0f) ? hitInfo.distance : 1.7f); } else { newPosition.y = StayOnTheFloor ? transform.position.y : worldPosition.y; } transform.position = newPosition; }
public override bool InitInternal() { if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x3000) { return(false); } // TODO : Read offsets from the plugin. #if !true m_AnchorPosition = Vector3.zero; m_AnchorRotation = Quaternion.identity; #else VRDevice vrDevice = VRContext.currentDevice; if (vrDevice != null) { m_AnchorPosition = vrDevice.inOutsideMarkPose.position; m_AnchorRotation = vrDevice.inOutsideMarkPose.rotation; } else { m_AnchorPosition = Vector3.zero; m_AnchorRotation = Quaternion.identity; } #endif // return(base.InitInternal()); }
/// Manual recenter for Cardboard. /// Do not use for controller-based Daydream recenter - Google VR Services will take care /// of that, no C# implementation behaviour is needed. /// Apply the recenteringOffset to the Camera or its parent at runtime. public static void Recenter() { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR gvr_reset_tracking(VRDevice.GetNativePtr()); #endif // (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR Debug.Log("Use GvrEditorEmulator for in-editor recentering"); }
/// Set the Cardboard viewer params. /// Example URI for 2015 Cardboard Viewer V2: /// http://google.com/cardboard/cfg?p=CgZHb29nbGUSEkNhcmRib2FyZCBJL08gMjAxNR0rGBU9JQHegj0qEAAASEIAAEhCAABIQgAASEJYADUpXA89OggeZnc-Ej6aPlAAYAM public static void SetViewerProfile(String viewerProfileUri) { #if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR gvr_set_default_viewer_profile(VRDevice.GetNativePtr(), viewerProfileUri); #endif // (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR Debug.Log("Unavailable for non-Android and non-iOS builds"); }
public override void OnActivated() { m_prevTrackingSpace = VRDevice.GetTrackingSpaceType(); UpdateTrackingSpaceType(); EnsureDeviceStateLength(3); }
/// <summary> Returns whether there's a floor available. </summary> public static bool IsRoomScale() { #if UNITY_2019_3_OR_NEWER var devices = new List <InputDevice>(); InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices); if (devices.Count == 0) { return(false); } var hmdDevice = devices[0]; #if !UNITY_2020_1_OR_NEWER if (hmdDevice.subsystem != null) { #endif return(hmdDevice.subsystem.GetTrackingOriginMode().HasFlag(TrackingOriginModeFlags.Floor)); #if !UNITY_2020_1_OR_NEWER } else { #pragma warning disable 0618 return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #pragma warning restore 0618 } #endif #elif UNITY_2017_2_OR_NEWER return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #else return(VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #endif }
protected virtual void OnVRContextInited(VRContext context) { // if ((XDevicePlugin.GetInt(XDevicePlugin.ID_CONTEXT, XDevicePlugin.kField_CtxDeviceVersionInt, 0) & 0xF000) != 0x4000) { Destroy(this); Ximmerse.Log.w("TrackedHead", "TrackedHead only works in Outside-in!!!"); return; } else { VRDevice vrDevice = context.vrDevice; if (vrDevice.outsideInMarkPose.position != Vector3.zero) { markTransform.localPosition = vrDevice.outsideInMarkPose.position; } } // if (eyeContainer == null) { eyeContainer = new GameObject("Rotate-Pivot").transform; eyeContainer.SetParent(transform); // eyeContainer.localPosition = Vector3.zero; eyeContainer.localRotation = Quaternion.identity; eyeContainer.localScale = Vector3.one; // if (context.vrDevice != null && context.vrDevice.family != "Dummy") { markTransform.localPosition = markTransform.localPosition + context.vrDevice.neckToEye; eyeContainer.localPosition = context.vrDevice.neckToEye; #if UNITY_EDITOR // Editor features. if (m_Gizmos.Length > 0 && m_Gizmos[0] != null) { m_Gizmos[0].transform.localPosition = m_Gizmos[0].transform.localPosition + context.vrDevice.neckToEye; } #endif } } // for (int i = 0; i < 3; ++i) { Transform eye = context.GetAnchor(VRNode.LeftEye + i, null); if (eye != null) { eye.SetParent(eyeContainer, false); } } // switch (PlayerPrefsEx.GetInt("XimmerseDevice.type", 0)) { // No head tracking. case 0x1010: source = ControllerType.None; m_ControllerInput = null; break; } }
public static bool IsRoomScale() { #if UNITY_2017_2_OR_NEWER return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #else return(VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #endif }
public VRDeviceLoader() { if (VRDevice.Device == null) { var device = CreateDevice(); VRDevice.Initialize(device); } }
public static void HideAll(VRDevice device) { SetVisible(device, Location.Grip, false); SetVisible(device, Location.Trigger, false); SetVisible(device, Location.Primary, false); SetVisible(device, Location.Secondary, false); SetVisible(device, Location.Joystick, false); }
private static void OnVREvent(int eventID) { VRDevice device = GetDevice() as VRDevice; // This function is called back from random native code threads. lock (device.eventQueue) { device.eventQueue.Enqueue(eventID); } }
IEnumerator Calculate(int subItemIndex, VRDevice device) { while (playFlag || clipIndex != -1) { yield return(null); float valueOfPosition = CalcPosition(clipIndex, device); float valueOfRotation = CalcRotation(clipIndex, device); float value = (4 * valueOfPosition + valueOfRotation) / 5; device.SetSliderValue(value / (threshold * weight)); switch (device.GetDeviceIndex()) { case 1: Debug.Log("머리 사용자 값 : " + value + ", 기준 값 : " + (threshold * weight) + ", 슬라이더 값 : " + (value / (threshold * weight)) + ", 거리 : " + valueOfPosition + ", 기울기 : " + valueOfRotation); break; case 2: Debug.Log("왼손 사용자 값 : " + value + ", 기준 값 : " + (threshold * weight) + ", 슬라이더 값 : " + (value / (threshold * weight)) + ", 거리 : " + valueOfPosition + ", 기울기 : " + valueOfRotation); break; case 3: Debug.Log("오른손 사용자 값 : " + value + ", 기준 값 : " + (threshold * weight) + ", 슬라이더 값 : " + (value / (threshold * weight)) + ", 거리 : " + valueOfPosition + ", 기울기 : " + valueOfRotation); break; case 4: Debug.Log("왼발 사용자 값 : " + value + ", 기준 값 : " + (threshold * weight) + ", 슬라이더 값 : " + (value / (threshold * weight)) + ", 거리 : " + valueOfPosition + ", 기울기 : " + valueOfRotation); break; case 5: Debug.Log("오른발 사용자 값 : " + value + ", 기준 값 : " + (threshold * weight) + ", 슬라이더 값 : " + (value / (threshold * weight)) + ", 거리 : " + valueOfPosition + ", 기울기 : " + valueOfRotation); break; } if (value < threshold * weight) { device.SetState(0); device.SetSphereColor(Color.green); device.AddCorrectTime(Time.time - device.GetDeltaTime()); device.SetDeltaTime(Time.time); } else if (value < threshold * weight * 2) { device.SetState(1); device.SetSphereColor(Color.yellow); device.AddCorrectTime((Time.time - device.GetDeltaTime()) / 2); device.AddErrorTime((Time.time - device.GetDeltaTime()) / 2); device.SetDeltaTime(Time.time); } else { device.SetState(2); device.SetSphereColor(Color.red); device.AddErrorTime(Time.time - device.GetDeltaTime()); device.SetDeltaTime(Time.time); } } }
private void Start() { var deviceInitializer = GetComponentInChildren <IVRDeviceInitializer>(); var device = deviceInitializer.CreateDevice(); VRDevice.Initialize(device); VRDevice.Device.SetupAvatar(Avatar); BetterStreamingAssets.Initialize(); }
public float CalcPosition(int index, VRDevice device) { Debug.Log("신체 배율 : " + device.GetUserSize() / device.GetStandardSize()); Vector3 distanceOfDevice = (((waist.GetPosition() - device.GetPosition()) * 100) / device.GetStandardSize()) * device.GetUserSize(); Vector3 distanceOfStandard = positionList[device.GetDeviceIndex() - 1, index] - distanceOfDevice; float distanceOfPosition = distanceOfStandard.magnitude; return(distanceOfPosition); }
public static Transform GetTooltipTransform(VRDevice device, Tooltips.Location location) { if (device == VRDevice.PrimaryController) { return(instance.VRControllers.GetPrimaryTooltipTransform(location)); } else { return(instance.VRControllers.GetSecondaryTooltipTransform(location)); } }
public static void SetVisible(VRDevice device, Location location, bool visible) { Transform tooltip = GlobalState.GetTooltipTransform(device, location); if (null == tooltip) { return; } tooltip.gameObject.SetActive(visible); }
public static Transform GetControllerTransform(VRDevice device) { if (device == VRDevice.PrimaryController) { return(GetPrimaryControllerTransform()); } if (device == VRDevice.SecondaryController) { return(GetSecondaryControllerTransform()); } return(null); }
public override void UpdateTrackingSpaceType() { switch (VRModule.trackingSpaceType) { case VRModuleTrackingSpaceType.Stationary: VRDevice.SetTrackingSpaceType(TrackingSpaceType.Stationary); break; case VRModuleTrackingSpaceType.RoomScale: VRDevice.SetTrackingSpaceType(TrackingSpaceType.RoomScale); break; } }
private static void SetOpacity(VRDevice device, float angle) { Transform tooltip = GlobalState.GetTooltipTransform(device, Location.Grip); SetOpacity(tooltip, angle); tooltip = GlobalState.GetTooltipTransform(device, Location.Trigger); SetOpacity(tooltip, angle); tooltip = GlobalState.GetTooltipTransform(device, Location.Primary); SetOpacity(tooltip, angle); tooltip = GlobalState.GetTooltipTransform(device, Location.Secondary); SetOpacity(tooltip, angle); tooltip = GlobalState.GetTooltipTransform(device, Location.Joystick); SetOpacity(tooltip, angle); }
private bool IsErasable(VRDevice device) { bool rw = device.MediaIsReWritable; if (rw && device.Error.Facility == PrimoSoftware.DVDBuilder.ErrorFacility.Success) { bool blank = device.MediaIsBlank; if (!blank && (device.Error.Facility == PrimoSoftware.DVDBuilder.ErrorFacility.Success)) { return(true); } } return(false); }
void Start() { //Roomscale VR will track a player's actual height while playing. As such, we need to position the camera on //the ground and the player will be the correct height in the game if (VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale) { //Log the tracking type and position the rig on the ground VRLog.Log("Roomscale Tracking"); transform.position = Vector3.zero; } else { VRLog.Log("Stationary Tracking"); } }
public static void SetText(VRDevice device, Location location, Action action, string text, bool visible = true) { Transform tooltip = GlobalState.GetTooltipTransform(device, location); if (null == tooltip) { return; } Transform textTransform = tooltip.Find("Canvas/Panel/Text"); if (null != textTransform) { TextMeshProUGUI tmpro = textTransform.GetComponent <TextMeshProUGUI>(); tmpro.text = text; } string icon = ""; switch (action) { case Action.Push: icon = "action-push"; break; case Action.HoldPush: icon = "action-hold-push"; break; case Action.Horizontal: icon = "action-joystick-horizontal"; break; case Action.HoldHorizontal: icon = "action-hold-joystick-horizontal"; break; case Action.Vertical: icon = "action-joystick-vertical"; break; case Action.HoldVertical: icon = "action-hold-joystick-vertical"; break; case Action.Joystick: icon = "action-joystick"; break; } Transform imageTransform = tooltip.Find("Canvas/Panel/Image"); if (null != imageTransform) { Image image = imageTransform.GetComponent <Image>(); icon = "empty"; // don't use icon value yet, we don't have any image image.sprite = UIUtils.LoadIcon(icon); } tooltip.gameObject.SetActive(visible); }
IEnumerator Timer(VRDevice device, float timeRemaining, float frequency, float amplitude) { float waitTime = Mathf.Min(timeRemaining, 2f); yield return(new WaitForSeconds(waitTime)); //Do something timeRemaining -= waitTime; if (timeRemaining > 0) { Vibrate(device, timeRemaining, frequency, amplitude); } else { Vibrate(device, 0, 0, 0); } }
/// <summary> Returns whether there's a floor available. </summary> public static bool IsRoomScale() { #if UNITY_2019_3_OR_NEWER var devices = new List <InputDevice>(); InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices); if (devices.Count == 0) { return(false); } var hmdDevice = devices[0]; return(hmdDevice.subsystem.GetTrackingOriginMode().HasFlag(TrackingOriginModeFlags.Floor)); #elif UNITY_2017_2_OR_NEWER return(XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #else return(VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale); #endif }
public float CalcRotation(int index, VRDevice device) { Vector3 distanceOfDevice = (waist.GetRotation() - device.GetRotation()); distanceOfDevice.x = Mathf.Abs(distanceOfDevice.x); distanceOfDevice.y = Mathf.Abs(distanceOfDevice.y); distanceOfDevice.z = Mathf.Abs(distanceOfDevice.z); Vector3 distanceOfStandard = rotationList[device.GetDeviceIndex() - 1, index]; Vector3 multipleOfRotation = new Vector3(distanceOfDevice.x * distanceOfStandard.x, distanceOfDevice.y * distanceOfStandard.y, distanceOfDevice.z * distanceOfStandard.z); float distanceOfRotation = Mathf.Acos((multipleOfRotation.x + multipleOfRotation.y + multipleOfRotation.z) / (distanceOfDevice.magnitude * distanceOfStandard.magnitude)); Debug.Log("인덱스 : " + device.GetDeviceIndex() + " 기울기 테스트, 허리 : " + waist.GetRotation() + ", 왼손 : " + device.GetRotation() + ", 두 값의 차 : " + distanceOfDevice + ", 기준값 : " + distanceOfStandard + ", 두 벡터 곱 : " + multipleOfRotation + ", 사잇각 : " + distanceOfRotation); return(distanceOfRotation * 180); }
public static void InitializeMinVRLayoutSwitching(VRDevice server) { if (server == null) { throw new ArgumentNullException("server", "Provided VRDevice was null! Failed to initialize for MinVR Layout Switching!"); } if (server.vrNodeType != VRDevice.VRNodeType.NetServer) { Debug.LogWarning("Provided VRDevice to initialize for MinVR Layout Switching does not have vrNodeType NetServer!"); } foreach (var item in _layout_switch_bindings) { server.unityKeysToVREvents.Add(item); } }
public override Vector3 GetLocalPosition(int node) { Vector3 position = base.GetLocalPosition(node); if (node == m_Controllers[2].value) { if (m_CenterEye == null) { m_CenterEye = VRContext.GetAnchor(VRNode.CenterEye); m_VRDevice = VRContext.currentDevice; } if (m_CenterEye != null && m_VRDevice != null) { position -= m_CenterEye.localRotation * (m_VRDevice.neckToEye + m_VRDevice.outsideInMarkPose.position); } } return(position); }
public Transform VRInputToTransform(VRDevice vrDevice, VRInput vrInput) { Transform result = null; if (vrDevice == VRDevice.LeftController) { result = (Transform)leftVRInputToTransform[vrInput]; } if (vrDevice == VRDevice.RightController) { result = (Transform)rightVRInputToTransform[vrInput]; } //Debug.Log("VRInputToTransform("+vrDevice+","+vrInput+") result = "+result.name); return(result); }
//setup and VR, Application, Player, Quality, and Screen settings void SetVRAppSettings() { //Disable autovr camera tracking since the camera's transform is set by RenderManager poses. #if UNITY_2017 if (_clientKit.context.CheckStatus()) { VRDevice.DisableAutoVRCameraTracking(_camera0, true); } #endif VRSettings.showDeviceView = false; //Application.targetFrameRate = 90; Application.targetFrameRate = -1; Application.runInBackground = true; QualitySettings.vSyncCount = 0; QualitySettings.maxQueuedFrames = -1; //limit the number of frames queued up to be rendered, reducing latency Screen.sleepTimeout = SleepTimeout.NeverSleep; //VR should never timeout the screen: }