mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-22 15:18:33 -05:00
Merge pull request 'Bugfix: Thumbwheel Scrolling' (#24) from bugfix/Thumbwheel-Scroll into development
Reviewed-on: http://104.1.10.149:3000/MAVRIC/Stratasys-450mc-VR/pulls/24
This commit is contained in:
commit
ae0e8ce49a
File diff suppressed because it is too large
Load Diff
@ -490,6 +490,10 @@ PrefabInstance:
|
||||
propertyPath: m_AnchoredPosition.y
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5827223565076819818, guid: b83677d186e49a64cadef8d7a5a9d3c6, type: 3}
|
||||
propertyPath: m_IsActive
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 6899455370481246272, guid: b83677d186e49a64cadef8d7a5a9d3c6, type: 3}
|
||||
propertyPath: m_SizeDelta.x
|
||||
value: 0
|
||||
|
62
Assets/Scripts/Interactions/XRScroll.cs
Normal file
62
Assets/Scripts/Interactions/XRScroll.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
namespace Interactions
|
||||
{
|
||||
public class XRScroll : XRBaseInteractable
|
||||
{
|
||||
private bool isTracking;
|
||||
|
||||
[SerializeField] private Vector3 scrollAxis = Vector3.up;
|
||||
[SerializeField] private float scrollScale = 1000;
|
||||
|
||||
public UnityEvent<float> scrollUpdated;
|
||||
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
isTracking = false;
|
||||
StopAllCoroutines();
|
||||
}
|
||||
|
||||
|
||||
public void OnSelected(SelectEnterEventArgs args)
|
||||
{
|
||||
StartCoroutine(TrackScrolling(args.interactorObject.transform));
|
||||
}
|
||||
|
||||
private IEnumerator TrackScrolling(Transform mover)
|
||||
{
|
||||
if (isTracking) yield break;
|
||||
isTracking = true;
|
||||
Vector3 previousPos = mover.position;
|
||||
|
||||
while (isTracking)
|
||||
{
|
||||
yield return null;
|
||||
|
||||
Vector3 currentPos = mover.position;
|
||||
|
||||
//Calculate the difference in position only along one axis
|
||||
Vector3 diff = (previousPos - currentPos);
|
||||
diff = new Vector3(diff.x * scrollAxis.x, diff.y * scrollAxis.y, diff.z * scrollAxis.z);
|
||||
float diffTotal = (diff.x + diff.y + diff.z) * scrollScale;
|
||||
|
||||
previousPos = currentPos;
|
||||
scrollUpdated?.Invoke(diffTotal);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnUnSelected(SelectExitEventArgs args)
|
||||
{
|
||||
isTracking = false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Interactions/XRScroll.cs.meta
Normal file
11
Assets/Scripts/Interactions/XRScroll.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3647f60f096e78e428aa74212dd78d08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -10,25 +10,15 @@ public class RotateTarget : MonoBehaviour
|
||||
[SerializeField] private Transform target;
|
||||
|
||||
[SerializeField] private float speed = 10f;
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField] private float inputValue = 0f;
|
||||
[Range(-1f, 1f)]
|
||||
[SerializeField, ReadOnly] private float direction = 0f;
|
||||
[SerializeField] private bool invertDirection = false;
|
||||
private void Update()
|
||||
|
||||
[SerializeField] private Vector3 rotationAxis = Vector3.right;
|
||||
|
||||
public void Rotate(float amount)
|
||||
{
|
||||
if (target == null) return;
|
||||
amount *= Time.deltaTime;
|
||||
|
||||
RemapDirection();
|
||||
|
||||
target.RotateAround(target.position, target.up, speed * direction * Time.deltaTime);
|
||||
amount *= speed;
|
||||
|
||||
target.Rotate(rotationAxis,amount);
|
||||
}
|
||||
|
||||
private void RemapDirection(float min = -1f, float max = 1f)
|
||||
{
|
||||
direction = Mathf.Lerp(min, max, inputValue);
|
||||
direction *= invertDirection ? -1f : 1f;
|
||||
}
|
||||
|
||||
public void SetDirectionValue(float value) => inputValue = value;
|
||||
}
|
||||
|
@ -14,33 +14,14 @@ public class ScaleTarget : MonoBehaviour
|
||||
[SerializeField] private Vector3 scaleAxis = Vector3.right;
|
||||
|
||||
[SerializeField] private float speed = 1f;
|
||||
[Range(0f, 1f)]
|
||||
[SerializeField] private float inputValue = 0f;
|
||||
[Range(-1f, 1f)]
|
||||
[SerializeField, ReadOnly] private float direction = 0f;
|
||||
[SerializeField] private bool invertDirection = false;
|
||||
|
||||
private void Update()
|
||||
public void Scale(float value)
|
||||
{
|
||||
if (target == null) return;
|
||||
|
||||
RemapDirection();
|
||||
|
||||
target.localScale += scaleAxis * (speed * direction * Time.deltaTime);
|
||||
|
||||
// Clamp the scale but only on the scale axis
|
||||
target.localScale += scaleAxis * (value * speed * Time.deltaTime);
|
||||
var clampedScale = target.localScale;
|
||||
clampedScale.x = Mathf.Clamp(clampedScale.x, minScale, maxScale);
|
||||
clampedScale.y = Mathf.Clamp(clampedScale.y, minScale, maxScale);
|
||||
clampedScale.z = Mathf.Clamp(clampedScale.z, minScale, maxScale);
|
||||
target.localScale = clampedScale;
|
||||
}
|
||||
|
||||
private void RemapDirection(float min = -1f, float max = 1f)
|
||||
{
|
||||
direction = Mathf.Lerp(min, max, inputValue);
|
||||
direction *= invertDirection ? -1f : 1f;
|
||||
}
|
||||
|
||||
public void SetDirectionValue(float value) => inputValue = value;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user