mirror of
https://udrimavric.com/MAVRIC/Stratasys-450mc-VR.git
synced 2025-01-22 15:18:33 -05:00
Simplified rotate and scale target classes, added to thumbwheel
This commit is contained in:
parent
cd5af28a09
commit
1542176845
File diff suppressed because it is too large
Load Diff
@ -11,20 +11,10 @@ namespace Interactions
|
|||||||
private bool isHovering;
|
private bool isHovering;
|
||||||
|
|
||||||
[SerializeField] private Vector3 scrollAxis = Vector3.up;
|
[SerializeField] private Vector3 scrollAxis = Vector3.up;
|
||||||
|
[SerializeField] private float scrollScale = 1000;
|
||||||
|
|
||||||
public RotateTarget rotator;
|
public RotateTarget rotator;
|
||||||
|
public ScaleTarget scalar;
|
||||||
[SerializeField] private MeshRenderer meshRenderer;
|
|
||||||
|
|
||||||
[SerializeField] private Material onMat, offMat;
|
|
||||||
|
|
||||||
|
|
||||||
public TextMeshProUGUI text;
|
|
||||||
|
|
||||||
public void OnHoverEntered(HoverEnterEventArgs args)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnSelected(SelectEnterEventArgs args)
|
public void OnSelected(SelectEnterEventArgs args)
|
||||||
{
|
{
|
||||||
@ -35,7 +25,6 @@ namespace Interactions
|
|||||||
{
|
{
|
||||||
if (isHovering) yield break;
|
if (isHovering) yield break;
|
||||||
isHovering = true;
|
isHovering = true;
|
||||||
meshRenderer.material = onMat;
|
|
||||||
Vector3 previousPos = mover.position;
|
Vector3 previousPos = mover.position;
|
||||||
|
|
||||||
while (isHovering)
|
while (isHovering)
|
||||||
@ -44,21 +33,15 @@ namespace Interactions
|
|||||||
|
|
||||||
Vector3 currentPos = mover.position;
|
Vector3 currentPos = mover.position;
|
||||||
|
|
||||||
|
//Calculate the difference in position only along one axis
|
||||||
Vector3 diff = (previousPos - currentPos);
|
Vector3 diff = (previousPos - currentPos);
|
||||||
diff = new Vector3(diff.x * scrollAxis.x, diff.y * scrollAxis.y, diff.z * scrollAxis.z);
|
diff = new Vector3(diff.x * scrollAxis.x, diff.y * scrollAxis.y, diff.z * scrollAxis.z);
|
||||||
|
float diffTotal = (diff.x + diff.y + diff.z) * scrollScale;
|
||||||
text.text = diff.ToString("0.00000");
|
|
||||||
|
|
||||||
previousPos = currentPos;
|
previousPos = currentPos;
|
||||||
rotator.Rotate(diff);
|
rotator.Rotate(diffTotal);
|
||||||
|
scalar.Scale(diffTotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
meshRenderer.material = offMat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnHoverExited(HoverExitEventArgs args)
|
|
||||||
{
|
|
||||||
//isHovering = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnUnSelected(SelectExitEventArgs args)
|
public void OnUnSelected(SelectExitEventArgs args)
|
||||||
|
@ -10,39 +10,15 @@ public class RotateTarget : MonoBehaviour
|
|||||||
[SerializeField] private Transform target;
|
[SerializeField] private Transform target;
|
||||||
|
|
||||||
[SerializeField] private float speed = 10f;
|
[SerializeField] private float speed = 10f;
|
||||||
[Range(0f, 1f)]
|
|
||||||
[SerializeField] private float inputValue = 0f;
|
[SerializeField] private Vector3 rotationAxis = Vector3.right;
|
||||||
[Range(-1f, 1f)]
|
|
||||||
[SerializeField, ReadOnly] private float direction = 0f;
|
public void Rotate(float amount)
|
||||||
[SerializeField] private bool invertDirection = false;
|
|
||||||
private void Update()
|
|
||||||
{
|
{
|
||||||
if (target == null) return;
|
amount *= Time.deltaTime;
|
||||||
return;
|
|
||||||
|
|
||||||
RemapDirection();
|
amount *= speed;
|
||||||
|
|
||||||
target.RotateAround(target.position, target.up, speed * direction * Time.deltaTime);
|
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;
|
|
||||||
|
|
||||||
public void Rotate(Vector3 value)
|
|
||||||
{
|
|
||||||
float totalRot = value.x + value.y + value.z;
|
|
||||||
|
|
||||||
totalRot *= Time.deltaTime;
|
|
||||||
|
|
||||||
totalRot *= speed;
|
|
||||||
|
|
||||||
Vector3 axis = Vector3.forward;
|
|
||||||
|
|
||||||
target.Rotate(axis,totalRot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,33 +14,14 @@ public class ScaleTarget : MonoBehaviour
|
|||||||
[SerializeField] private Vector3 scaleAxis = Vector3.right;
|
[SerializeField] private Vector3 scaleAxis = Vector3.right;
|
||||||
|
|
||||||
[SerializeField] private float speed = 1f;
|
[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;
|
target.localScale += scaleAxis * (value * speed * Time.deltaTime);
|
||||||
|
|
||||||
RemapDirection();
|
|
||||||
|
|
||||||
target.localScale += scaleAxis * (speed * direction * Time.deltaTime);
|
|
||||||
|
|
||||||
// Clamp the scale but only on the scale axis
|
|
||||||
var clampedScale = target.localScale;
|
var clampedScale = target.localScale;
|
||||||
clampedScale.x = Mathf.Clamp(clampedScale.x, minScale, maxScale);
|
clampedScale.x = Mathf.Clamp(clampedScale.x, minScale, maxScale);
|
||||||
clampedScale.y = Mathf.Clamp(clampedScale.y, minScale, maxScale);
|
clampedScale.y = Mathf.Clamp(clampedScale.y, minScale, maxScale);
|
||||||
clampedScale.z = Mathf.Clamp(clampedScale.z, minScale, maxScale);
|
clampedScale.z = Mathf.Clamp(clampedScale.z, minScale, maxScale);
|
||||||
target.localScale = clampedScale;
|
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