// Cache components for later use. private void CacheComponents() { footCollider = transform.FindDeepChild("[VRTK][AUTOGEN][FootColliderContainer]").GetComponent <CapsuleCollider>(); activeCamera = VRTK_DeviceFinder.HeadsetCamera().GetComponent <Camera>(); headsetLocation = VRTK_DeviceFinder.HeadsetTransform(); voidBallAnimator = voidBall.GetComponent <Animator>(); }
private void OnEnable() { headsetTransform = VRTK_DeviceFinder.HeadsetTransform(); bufferSize = Mathf.CeilToInt(1 / Time.fixedDeltaTime); heights = new SteamVR_RingBuffer <float>(bufferSize); }
private void Update() { if (!initalised) { var headset = VRTK_DeviceFinder.HeadsetTransform(); var controllerEvents = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent <VRTK_ControllerEvents>(); if (!headset.GetComponent <VRTK_SimplePointer>()) { var pointer = headset.gameObject.AddComponent <VRTK_SimplePointer>(); pointer.controller = controllerEvents; pointer.enableTeleport = false; pointer.pointerVisibility = VRTK_WorldPointer.pointerVisibilityStates.Always_Off; pointer.pointerLength = 100f; pointer.showPointerTip = true; } if (!headset.GetComponent <VRTK_UIPointer>()) { var uiPointer = headset.gameObject.AddComponent <VRTK_UIPointer>(); uiPointer.controller = controllerEvents; uiPointer.ignoreCanvasWithTagOrClass = "ExcludeTeleport"; } initalised = true; } }
protected virtual void SetupHeadset() { headset = VRTK_DeviceFinder.HeadsetTransform(); if (headset != null) { } }
protected virtual void Update() { if (interactableObject != null) { if (rotateTowards == null) { rotateTowards = VRTK_DeviceFinder.HeadsetTransform().gameObject; if (rotateTowards == null) { VRTK_Logger.Warn(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.COULD_NOT_FIND_OBJECT_FOR_ACTION, "PanelMenuController", "an object", "rotate towards")); } } if (isShown) { if (rotateTowards != null) { transform.rotation = Quaternion.LookRotation((rotateTowards.transform.position - transform.position) * -1, Vector3.up); } } if (isPendingSwipeCheck) { CalculateSwipeAction(); } } }
public void DoSnapToFloor() { if (!enabled) { return; } var player = VRTK_DeviceFinder.HeadsetTransform(); if (!player) { return; } var playAreaTeleport = teleport as PlayAreaLimitedTeleport; bool originalValue = false; if (playAreaTeleport) { originalValue = playAreaTeleport.GetOnlyTeleportToPointers(); playAreaTeleport.SetOnlyToPointers(false); } teleport.Teleport(floor, player.position + offset); enabled = !disableOnUse; if (keepTeleportToPointerValue && playAreaTeleport) { playAreaTeleport.SetOnlyToPointers(originalValue); } }
float getDistance() { var headsetPos = VRTK_DeviceFinder.HeadsetTransform().position; float d = Vector3.Distance(headsetPos, this.transform.position); return(d); }
void Start() { lookTowards = VRTK_DeviceFinder.HeadsetTransform(); text = new GameObject(); text.name = "Text"; t = text.AddComponent <TextMesh>(); t.text = description; t.anchor = TextAnchor.MiddleCenter; t.characterSize = 0.005f; t.fontSize = 200; t.color = Color.black; text.transform.parent = transform; text.transform.position = transform.position + new Vector3(0, 0.11f, 0); text.transform.rotation = Quaternion.Euler(0, 0, 0); /* * try * { * text.transform.rotation = Quaternion.FromToRotation(new Vector3(text.transform.position.x, 0, text.transform.position.z), new Vector3(lookTowards.position.x, 0, lookTowards.position.z)); * } * catch (NullReferenceException e) * { * Debug.Log("Can't find head"); * } */ }
/// <summary> /// Updates data of each text box /// </summary>e void Update() { if (initialized) { foreach (KeyValuePair <Text, string> item in infoTextsDict) { item.Key.text = connection.GetValueByTopic(item.Value); } Vector3 dronePosition = this.gameObject.transform.localPosition; GPSCoordinate gps = WorldProperties.UnityCoordToGPSCoord(dronePosition); dronePosText.text = "Lat: " + String.Format("{0:0.0000000}", gps.Lat) + "\nLon: " + String.Format("{0:0.0000000}", gps.Lng); if (connection.HasAuthority()) { droneAuthorityText.text = "Controllable"; droneAuthorityText.color = Color.green; } else { droneAuthorityText.text = "Request Authority"; droneAuthorityText.color = Color.white; } // Make canvas always face the user as drone moves headsetTransform = VRTK_DeviceFinder.HeadsetTransform(); if (headsetTransform != null) { Vector3 targetPosition = headsetTransform.position; // canvas LookAt code is funky. Credit: https://answers.unity.com/questions/132592/lookat-in-opposite-direction.html menuCanvas.transform.LookAt(2 * menuCanvas.transform.position - targetPosition); } } }
private IEnumerator FindDevices() { yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); HeadsetFollower = VRTK_DeviceFinder.HeadsetTransform().gameObject; RightHand = VRTK_DeviceFinder.GetControllerRightHand().GetComponent <VRTK_ControllerEvents>(); LeftHand = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent <VRTK_ControllerEvents>(); RightHand.GetComponent <VRTK_ControllerEvents>().TriggerPressed += TriggerPressed; LeftHand.GetComponent <VRTK_ControllerEvents>().TriggerPressed += TriggerPressed; RightHand.GetComponent <VRTK_ControllerEvents>().GripPressed += GripPressed; LeftHand.GetComponent <VRTK_ControllerEvents>().GripPressed += GripPressed; RightHand.GetComponent <VRTK_ControllerEvents>().TouchpadPressed += TouchpadPressed; LeftHand.GetComponent <VRTK_ControllerEvents>().TouchpadPressed += TouchpadPressed; RightHand.GetComponent <VRTK_ControllerEvents>().ButtonTwoPressed += ButtonTwoPressed; LeftHand.GetComponent <VRTK_ControllerEvents>().ButtonTwoPressed += ButtonTwoPressed; RightHand.GetComponent <VRTK_ControllerEvents>().StartMenuPressed += StartMenuPressed; LeftHand.GetComponent <VRTK_ControllerEvents>().StartMenuPressed += StartMenuPressed; }
private void GetHeadset() { headset = VRTK_DeviceFinder.HeadsetTransform(); if (headset == null) { Invoke("GetHeadset", 0.2f); } }
protected override void OnEnable() { player = VRTK_DeviceFinder.PlayAreaTransform(); head = VRTK_DeviceFinder.HeadsetTransform(); leftHand = VRTK_DeviceFinder.GetControllerLeftHand().transform; rightHand = VRTK_DeviceFinder.GetControllerRightHand().transform; base.OnEnable(); }
IEnumerator Find() { yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); Player = VRTK_DeviceFinder.HeadsetTransform(); }
// Update is called once per frame void Update() { if (VRTK_DeviceFinder.HeadsetTransform() != null && followGameObject.TransformToFollow == null) { followGameObject.TransformToFollow = VRTK_DeviceFinder.HeadsetTransform(); followGameObject.enabled = true; } }
private void GetPlayAreaAndHeadset() { playArea = VRTK_DeviceFinder.PlayAreaTransform(); headset = VRTK_DeviceFinder.HeadsetTransform(); if (playArea == null && headset == null) { Invoke("GetPlayAreaAndHeadset", 0.2f); } }
private void OnEnable() { m_controllerEvents = m_controllerEvents ? m_controllerEvents : GetComponent <VRTK_ControllerEvents>(); m_playArea = VRTK_DeviceFinder.PlayAreaTransform(); m_headset = VRTK_DeviceFinder.HeadsetTransform(); m_controllerEvents.TriggerPressed += OnTriggerClicked; m_controllerEvents.TriggerReleased += OnTriggerUnclicked; }
private void LoadedSetupChanged(VRTK_SDKManager sender, VRTK_SDKManager.LoadedSetupChangeEventArgs e) { if (!this || e.currentSetup == null) { return; } headset = VRTK_DeviceFinder.HeadsetTransform(); }
void OnEnable() { SetLine(); headset = VRTK_DeviceFinder.HeadsetTransform(); if (drawLineTo == null && transform.parent != null) { drawLineTo = transform.parent; } }
IEnumerator RotatePlayArea(float rotation) { VRTK_SDK_Bridge.HeadsetFade(Color.black, FadeDuration); yield return(new WaitForSeconds(FadeDuration)); VRTK_DeviceFinder.PlayAreaTransform().RotateAround(VRTK_DeviceFinder.HeadsetTransform().position, Vector3.up, rotation); VRTK_SDK_Bridge.HeadsetFade(Color.clear, FadeDuration); }
private IEnumerator FindDevices() { yield return(new WaitForEndOfFrame()); yield return(new WaitForEndOfFrame()); UIPointerR = VRTK_DeviceFinder.GetControllerRightHand().GetComponent <VRTK_UIPointer>(); UIPointerL = VRTK_DeviceFinder.GetControllerLeftHand().GetComponent <VRTK_UIPointer>(); HeadsetTranform = VRTK_DeviceFinder.HeadsetTransform(); }
public void FixedUpdate() { if (!headset) { headset = VRTK_DeviceFinder.HeadsetTransform(); } float yPosition = headset.position.y - heightOffset; if (flightHandler.GetFlightState() == FlightHandlerPhys.FlightState.Gliding || flightHandler.GetFlightState() == FlightHandlerPhys.FlightState.Flying) { EnableArrow(); Vector3 start = headset.position + Vector3.Normalize(new Vector3(headset.forward.x, 0, headset.forward.z)) * forwardOffset; start.y = yPosition; Vector3 direction = flightHandler.WeightedForwardDirection(); if (flightHandler.ControllerRotatedBackwards()) { SetGradient(GradientType.Backwards); } else { SetGradient(GradientType.Forwards); } direction.y = 0; DrawLine(start, direction, body, bodyPoints); Vector3 leftHead = Quaternion.Euler(0, -45, 0) * (-direction); Vector3 rightHead = Quaternion.Euler(0, 45, 0) * (-direction); Vector3 end = start + direction; DrawLine(end, leftHead, this.leftHead, headPoints); DrawLine(end, rightHead, this.rightHead, headPoints); } if (flightHandler.GetFlightState() == FlightHandlerPhys.FlightState.Falling) { EnableArrow(); float downY = headset.position.y; Vector3 start = headset.position + Vector3.Normalize(new Vector3(headset.forward.x, 0, headset.forward.z)); start.y = downY; Vector3 direction = new Vector3(0, -0.5f, 0); //flightHandler.WeightedForwardDirection(); SetGradient(GradientType.Downwards); DrawLine(start, direction, body, bodyPoints); Vector3 leftHead = Quaternion.Euler(-45, 0, -45) * (-direction); Vector3 rightHead = Quaternion.Euler(45, 0, 45) * (-direction); Vector3 end = start + direction; DrawLine(end, leftHead, this.leftHead, 2); DrawLine(end, rightHead, this.rightHead, 2); } else if (flightHandler.GetFlightState() == FlightHandlerPhys.FlightState.Ground) { DisableArrow(); } }
private void OnEnable() { playArea = VRTK_DeviceFinder.PlayAreaTransform(); headset = VRTK_DeviceFinder.HeadsetTransform(); textUI.SetActive(true); if (textSource == null) { textSource = gameObject; } }
private void ScaleWithHeadsetAdjust(Vector3 newScale) { Vector3 oldHeadsetPos = VRTK_DeviceFinder.HeadsetTransform().position; transform.localScale = newScale; Vector3 newHeadsetPos = VRTK_DeviceFinder.HeadsetTransform().position; Vector3 difference = oldHeadsetPos - newHeadsetPos; difference.y = 0; //Ignore height difference transform.position += difference; }
void Start() { state = State.IDLE; originPosition = transform.position; pivot = new Vector3(0, Pivot, 0); scaleDelta = new Vector3(Scale, Scale, Scale) / SpeedFrame; headset = VRTK_DeviceFinder.HeadsetTransform(); //add //targetRotaion = GameObject.Find("ceiling1.4").transform.rotation; textPanel = this.transform.GetChild(0).FindChild("Text").gameObject; //add end }
private void Update() { if (!initalised) { var headset = VRTK_DeviceFinder.HeadsetTransform(); if (!headset.GetComponent <VRTK_HeadsetCollisionFade>()) { headset.gameObject.AddComponent <VRTK_HeadsetCollisionFade>(); } initalised = true; } }
private IEnumerator CorrectStartingAreaSteamVR() { yield return(null); var rect = new HmdQuad_t(); if (!SteamVR_PlayArea.GetBounds(SteamVR_PlayArea.Size.Calibrated, ref rect)) { Debug.LogError("Could not get the bounds of the play area!"); yield break; } float minX = Mathf.Min(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float maxX = Mathf.Max(rect.vCorners0.v0, rect.vCorners1.v0, rect.vCorners2.v0, rect.vCorners3.v0); float minZ = Mathf.Min(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); float maxZ = Mathf.Max(rect.vCorners0.v2, rect.vCorners1.v2, rect.vCorners2.v2, rect.vCorners3.v2); var playerLocation = VRTK_DeviceFinder.HeadsetTransform().transform.position - sdkManager.transform.position; var sdkPosition = sdkManager.transform.position; if (playerLocation.XZ().magnitude < 0.5f) { sdkPosition += new Vector3(Mathf.Abs(playerLocation.x), 0, -Mathf.Abs(playerLocation.z)); } if (playerLocation.x >= 0) { if (playerLocation.z > 0) { sdkPosition.z -= playerLocation.z; } else { // Totally fine! } } else { sdkPosition.x -= playerLocation.x; if (playerLocation.z > 0) { sdkPosition.z -= playerLocation.z; } else { // Totally fine! } } sdkManager.transform.position = sdkPosition; }
private void FixedUpdate() { if (!runFromPlayer) { GoAfterTarget(); return; } var player = VRTK_DeviceFinder.HeadsetTransform(); if (!player) { return; } Vector3 playerMovement = player.transform.position.XZ() - lastPlayerPosition.XZ(); if (playerMovement.magnitude != 0 || skipRunningAway) { lastPlayerPosition = player.transform.position; } var direction = transform.position.XZ() - player.position.XZ(); if (!skipRunningAway && direction.sqrMagnitude < 4 && playerMovement.magnitude > walkingDistance * Time.deltaTime) { agent.speed = speed; agent.SetDestination(-direction + transform.position); runningAway = true; } if (runningAway) { if (skipRunningAway) { runningAway = false; } else { runningAway = agent.velocity.magnitude >= 0.05f; } target = -1; } else { GoAfterTarget(); } skipRunningAway = false; }
// Update is called once per frame void Update() { if (playArea == null) { playArea = VRTK_DeviceFinder.PlayAreaTransform(); headset = VRTK_DeviceFinder.HeadsetTransform(); } else if (playArea != null && headset != null) { transform.position = new Vector3(headset.position.x, playArea.position.y, headset.position.z); transform.rotation = Quaternion.Euler(0, headset.eulerAngles.y, 0); } }
protected virtual void ToggleButtonPressed(object sender, ControllerInteractionEventArgs e) { isVisible = !isVisible; if (isVisible && menuSlate != null) { Transform headset = VRTK_DeviceFinder.HeadsetTransform(); menuSlate.transform.position = new Vector3(headset.position.x, 0f, headset.position.z) + (headset.forward * spawnDistance); menuSlate.transform.position = new Vector3(menuSlate.transform.position.x, 0f, menuSlate.transform.position.z); Vector3 targetPosition = headset.position; targetPosition.y = menuSlate.transform.position.y; menuSlate.transform.LookAt(targetPosition); } ToggleVisibility(); }
// Update is called once per frame void Update() { if (!headsetTransform && VRTK_DeviceFinder.HeadsetTransform()) { headsetTransform = VRTK_DeviceFinder.HeadsetTransform(); } if (headsetTransform) { Vector3 rotation = transform.rotation.eulerAngles; rotation.y = headsetTransform.rotation.eulerAngles.y; transform.rotation = Quaternion.Euler(rotation); } }