//------------------------------------------------- private void ComputeTextEndTransforms() { //This is done as a separate step after all the ButtonHintInfos have been initialized //to make the text hints fan out appropriately based on the button's position on the controller. centerPosition /= actionHintInfos.Count; float maxDistanceFromCenter = 0.0f; foreach (var hintInfo in actionHintInfos) { hintInfo.Value.distanceFromCenter = Vector3.Distance(hintInfo.Value.textStartAnchor.position, centerPosition); if (hintInfo.Value.distanceFromCenter > maxDistanceFromCenter) { maxDistanceFromCenter = hintInfo.Value.distanceFromCenter; } } foreach (var hintInfo in actionHintInfos) { Vector3 centerToButton = hintInfo.Value.textStartAnchor.position - centerPosition; centerToButton.Normalize(); centerToButton = Vector3.Project(centerToButton, renderModel.transform.forward); //Spread out the text end positions based on the distance from the center float t = hintInfo.Value.distanceFromCenter / maxDistanceFromCenter; float scale = hintInfo.Value.distanceFromCenter * Mathf.Pow(2, 10 * (t - 1.0f)) * 20.0f; //Flip the direction of the end pos based on which hand this is float endPosOffset = 0.1f; Vector3 hintEndPos = hintInfo.Value.textStartAnchor.position + (hintInfo.Value.textEndOffsetDir * endPosOffset) + (centerToButton * scale * 0.1f); if (SteamVR_Utils.IsValid(hintEndPos)) { hintInfo.Value.textEndAnchor.position = hintEndPos; hintInfo.Value.canvasOffset.position = hintEndPos; } else { Debug.LogWarning("<b>[SteamVR Interaction]</b> Invalid end position for: " + hintInfo.Value.textStartAnchor.name, hintInfo.Value.textStartAnchor.gameObject); } hintInfo.Value.canvasOffset.localRotation = Quaternion.identity; } }
protected IEnumerator DoRangeOfMotionBlend(EVRSkeletalMotionRange oldRangeOfMotion, EVRSkeletalMotionRange newRangeOfMotion, float overTime) { float startTime = Time.time; float endTime = startTime + overTime; Vector3[] oldBonePositions; Quaternion[] oldBoneRotations; Vector3[] newBonePositions; Quaternion[] newBoneRotations; while (Time.time < endTime) { yield return(null); float lerp = (Time.time - startTime) / overTime; if (skeletonBlend > 0) { skeletonAction.SetRangeOfMotion(oldRangeOfMotion); skeletonAction.UpdateValueWithoutEvents(); oldBonePositions = (Vector3[])GetBonePositions().Clone(); oldBoneRotations = (Quaternion[])GetBoneRotations().Clone(); skeletonAction.SetRangeOfMotion(newRangeOfMotion); skeletonAction.UpdateValueWithoutEvents(); newBonePositions = GetBonePositions(); newBoneRotations = GetBoneRotations(); for (int boneIndex = 0; boneIndex < bones.Length; boneIndex++) { if (bones[boneIndex] == null) { continue; } if (SteamVR_Utils.IsValid(newBoneRotations[boneIndex]) == false || SteamVR_Utils.IsValid(oldBoneRotations[boneIndex]) == false) { continue; } Vector3 blendedRangeOfMotionPosition = Vector3.Lerp(oldBonePositions[boneIndex], newBonePositions[boneIndex], lerp); Quaternion blendedRangeOfMotionRotation = Quaternion.Lerp(oldBoneRotations[boneIndex], newBoneRotations[boneIndex], lerp); if (skeletonBlend < 1) { if (blendPoser != null) { SetBonePosition(boneIndex, Vector3.Lerp(blendSnapshot.bonePositions[boneIndex], blendedRangeOfMotionPosition, skeletonBlend)); SetBoneRotation(boneIndex, Quaternion.Lerp(GetBlendPoseForBone(boneIndex, blendedRangeOfMotionRotation), blendedRangeOfMotionRotation, skeletonBlend)); } else { SetBonePosition(boneIndex, Vector3.Lerp(bones[boneIndex].localPosition, blendedRangeOfMotionPosition, skeletonBlend)); SetBoneRotation(boneIndex, Quaternion.Lerp(bones[boneIndex].localRotation, blendedRangeOfMotionRotation, skeletonBlend)); } } else { SetBonePosition(boneIndex, blendedRangeOfMotionPosition); SetBoneRotation(boneIndex, blendedRangeOfMotionRotation); } } } if (onBoneTransformsUpdated != null) { onBoneTransformsUpdated.Invoke(this, inputSource); } if (onBoneTransformsUpdatedEvent != null) { onBoneTransformsUpdatedEvent.Invoke(this, inputSource); } } rangeOfMotionBlendRoutine = null; }