Select press now controls width in Brush Selector (Advanced scene)
This commit is contained in:
Родитель
c060e6f027
Коммит
f155f3f9f0
|
@ -181,6 +181,13 @@ MonoBehaviour:
|
|||
m_Script: {fileID: 11500000, guid: 763670ccc75098848bdcfc979bef36c9, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
handedness: 2
|
||||
element: 6
|
||||
SetChildrenInactiveWhenDetached: 1
|
||||
positionOffset: {x: 0, y: 0, z: 0}
|
||||
rotationOffset: {x: 0, y: 0, z: 0}
|
||||
scale: {x: 1, y: 1, z: 1}
|
||||
setScaleOnAttach: 0
|
||||
minColorDelta: 0.05
|
||||
minPositionDelta: 0.025
|
||||
maxTimeDelta: 0.25
|
||||
|
|
|
@ -324,6 +324,32 @@ MonoBehaviour:
|
|||
activeBrushindex: 3
|
||||
colorPicker: {fileID: 0}
|
||||
menuTimeout: 2
|
||||
selectPressedDrawThreshold: 0.001
|
||||
selectPressedStartValue: 0.2
|
||||
selectWidthCurve:
|
||||
serializedVersion: 2
|
||||
m_Curve:
|
||||
- serializedVersion: 2
|
||||
time: 0
|
||||
value: 0
|
||||
inSlope: 0.18211141
|
||||
outSlope: 0.18211141
|
||||
tangentMode: 0
|
||||
- serializedVersion: 2
|
||||
time: 0.6359759
|
||||
value: 0.77979594
|
||||
inSlope: 1.3545039
|
||||
outSlope: 1.3545039
|
||||
tangentMode: 0
|
||||
- serializedVersion: 2
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: -0.017451808
|
||||
outSlope: -0.017451808
|
||||
tangentMode: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 0
|
||||
touchpadMaterial: {fileID: 2100000, guid: 9ab2a9ffd08a18a4b897b448b582c956, type: 2}
|
||||
touchpadColor:
|
||||
serializedVersion: 2
|
||||
|
|
|
@ -66,6 +66,14 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
}
|
||||
}
|
||||
|
||||
public float Width
|
||||
{
|
||||
set
|
||||
{
|
||||
width = Mathf.Clamp01 (value);
|
||||
}
|
||||
}
|
||||
|
||||
[Header("Drawing settings")]
|
||||
[SerializeField]
|
||||
private float minColorDelta = 0.01f;
|
||||
|
@ -83,6 +91,7 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
private Renderer brushRenderer;
|
||||
|
||||
protected bool draw = false;
|
||||
protected float width = 0f;
|
||||
|
||||
[Header("Mode settings")]
|
||||
[SerializeField]
|
||||
|
@ -128,6 +137,7 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
LineRenderer line = newStroke.GetComponent<LineRenderer>();
|
||||
newStroke.transform.position = startPosition;
|
||||
line.SetPosition(0, tip.position);
|
||||
float initialWidth = line.widthMultiplier;
|
||||
|
||||
while (draw)
|
||||
{
|
||||
|
@ -135,6 +145,8 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
line.SetPosition(line.positionCount - 1, tip.position);
|
||||
line.material.color = currentStrokeColor;
|
||||
lastPointAddedTime = Time.unscaledTime;
|
||||
// Adjust the width between 1x and 2x width based on strength of trigger pull
|
||||
line.widthMultiplier = Mathf.Lerp(initialWidth * 0.5f, initialWidth * 2, width);
|
||||
|
||||
if (Vector3.Distance(lastPointPosition, tip.position) > minPositionDelta || Time.unscaledTime > lastPointAddedTime + maxTimeDelta)
|
||||
{
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License. See LICENSE in the project root for license information.
|
||||
|
||||
using HoloToolkit.Unity.Controllers;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.WSA.Input;
|
||||
|
@ -61,22 +62,25 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
private ColorPickerWheel colorPicker;
|
||||
private Color currentStrokeColor = Color.white;
|
||||
private bool draw = false;
|
||||
private float width = 0f;
|
||||
private float lastPointAddedTime = 0f;
|
||||
|
||||
private IEnumerator Start()
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
colorPicker = FindObjectOfType<ColorPickerWheel>();
|
||||
brushRenderer.material.color = colorPicker.SelectedColor;
|
||||
|
||||
// Subscribe to press events for drawing
|
||||
InteractionManager.InteractionSourcePressed += InteractionSourcePressed;
|
||||
InteractionManager.InteractionSourceReleased += InteractionSourceReleased;
|
||||
InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated;
|
||||
}
|
||||
|
||||
// Wait for the color picker
|
||||
while (colorPicker == null)
|
||||
{
|
||||
colorPicker = FindObjectOfType<ColorPickerWheel>();
|
||||
yield return null;
|
||||
}
|
||||
|
||||
brushRenderer.material.color = colorPicker.SelectedColor;
|
||||
private void OnDisable()
|
||||
{
|
||||
InteractionManager.InteractionSourcePressed -= InteractionSourcePressed;
|
||||
InteractionManager.InteractionSourceReleased -= InteractionSourceReleased;
|
||||
InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated;
|
||||
}
|
||||
|
||||
private void InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
|
||||
|
@ -84,6 +88,15 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
if (obj.state.source.handedness == InteractionSourceHandedness.Right && obj.pressType == InteractionSourcePressType.Select)
|
||||
{
|
||||
Draw = true;
|
||||
width = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
|
||||
{
|
||||
if (obj.state.source.handedness == InteractionSourceHandedness.Right)
|
||||
{
|
||||
width = obj.state.selectPressedAmount;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,6 +105,7 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
if (obj.state.source.handedness == InteractionSourceHandedness.Right && obj.pressType == InteractionSourcePressType.Select)
|
||||
{
|
||||
Draw = false;
|
||||
width = 0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +129,7 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
LineRenderer line = newStroke.GetComponent<LineRenderer>();
|
||||
newStroke.transform.position = startPosition;
|
||||
line.SetPosition(0, tip.position);
|
||||
float initialWidth = line.widthMultiplier;
|
||||
|
||||
while (draw)
|
||||
{
|
||||
|
@ -123,6 +138,8 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
line.material.color = colorPicker.SelectedColor;
|
||||
brushRenderer.material.color = colorPicker.SelectedColor;
|
||||
lastPointAddedTime = Time.unscaledTime;
|
||||
// Adjust the width between 1x and 2x width based on strength of trigger pull
|
||||
line.widthMultiplier = Mathf.Lerp(initialWidth, initialWidth * 2, width);
|
||||
|
||||
if (Vector3.Distance(lastPointPosition, tip.position) > minPositionDelta || Time.unscaledTime > lastPointAddedTime + maxTimeDelta)
|
||||
{
|
||||
|
|
|
@ -34,6 +34,12 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
private ColorPickerWheel colorPicker;
|
||||
[SerializeField]
|
||||
private float menuTimeout = 2f;
|
||||
[SerializeField]
|
||||
private float selectPressedDrawThreshold = 0.001f;
|
||||
[SerializeField]
|
||||
private float selectPressedStartValue = 0.2f;
|
||||
[SerializeField]
|
||||
private AnimationCurve selectWidthCurve;
|
||||
|
||||
[SerializeField]
|
||||
private Material touchpadMaterial;
|
||||
|
@ -53,6 +59,7 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
|
||||
private float startTime;
|
||||
private bool resetInput;
|
||||
private float selectPressedSmooth = 0f;
|
||||
|
||||
private Brush activeBrush;
|
||||
|
||||
|
@ -61,7 +68,6 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
displayBrushindex = -1;
|
||||
currentAction = SwipeEnum.Left;
|
||||
}
|
||||
|
@ -179,14 +185,6 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
Destroy(originalTouchpadMaterial);
|
||||
}
|
||||
|
||||
private void InteractionSourcePressed(InteractionSourcePressedEventArgs obj)
|
||||
{
|
||||
if (obj.state.source.handedness == handedness && obj.pressType == InteractionSourcePressType.Select && activeBrush != null)
|
||||
{
|
||||
activeBrush.Draw = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void InteractionSourceUpdated(InteractionSourceUpdatedEventArgs obj)
|
||||
{
|
||||
if (obj.state.source.handedness == handedness)
|
||||
|
@ -206,16 +204,25 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
// Ping the touchpad material so it gets bright
|
||||
touchpadTouchTime = Time.unscaledTime;
|
||||
}
|
||||
|
||||
if (activeBrush != null)
|
||||
{
|
||||
// If the pressed amount is greater than our threshold, draw
|
||||
if (obj.state.selectPressedAmount >= selectPressedDrawThreshold)
|
||||
{
|
||||
activeBrush.Draw = true;
|
||||
activeBrush.Width = ProcessSelectPressedAmount (obj.state.selectPressedAmount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, stop drawing
|
||||
activeBrush.Draw = false;
|
||||
selectPressedSmooth = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InteractionSourceReleased(InteractionSourceReleasedEventArgs obj)
|
||||
{
|
||||
if (obj.state.source.handedness == handedness && obj.pressType == InteractionSourcePressType.Select && activeBrush != null)
|
||||
{
|
||||
activeBrush.Draw = false;
|
||||
}
|
||||
}
|
||||
protected override void OnAttachToController()
|
||||
{
|
||||
// Turn off the default controller's renderers
|
||||
|
@ -230,11 +237,9 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
touchpadRenderer.material = touchpadMaterial;
|
||||
touchpadRenderer.enabled = true;
|
||||
}
|
||||
|
||||
|
||||
// Subscribe to input now that we're parented under the controller
|
||||
InteractionManager.InteractionSourceUpdated += InteractionSourceUpdated;
|
||||
InteractionManager.InteractionSourcePressed += InteractionSourcePressed;
|
||||
InteractionManager.InteractionSourceReleased += InteractionSourceReleased;
|
||||
}
|
||||
|
||||
protected override void OnDetachFromController()
|
||||
|
@ -251,8 +256,13 @@ namespace HoloToolkit.Unity.ControllerExamples
|
|||
|
||||
// Unubscribe from input
|
||||
InteractionManager.InteractionSourceUpdated -= InteractionSourceUpdated;
|
||||
InteractionManager.InteractionSourcePressed -= InteractionSourcePressed;
|
||||
InteractionManager.InteractionSourceReleased -= InteractionSourceReleased;
|
||||
}
|
||||
|
||||
private float ProcessSelectPressedAmount (float selectPressedAmount)
|
||||
{
|
||||
float selectPressedProcessed = Mathf.Clamp01(selectWidthCurve.Evaluate(selectPressedAmount - selectPressedStartValue / (1f - selectPressedStartValue)));
|
||||
selectPressedSmooth = Mathf.Lerp(selectPressedSmooth, selectPressedProcessed, Time.deltaTime * 5);
|
||||
return selectPressedSmooth;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
|
|
|
@ -520,28 +520,11 @@ Prefab:
|
|||
propertyPath: m_RootOrder
|
||||
value: 4
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114661879801688092, guid: 54018739d95b963469324ffd1b785e1b,
|
||||
type: 2}
|
||||
propertyPath: colorPicker
|
||||
value:
|
||||
objectReference: {fileID: 790017090}
|
||||
- target: {fileID: 114412594797402372, guid: 54018739d95b963469324ffd1b785e1b,
|
||||
type: 2}
|
||||
propertyPath: Objects.Array.data[0]
|
||||
value:
|
||||
objectReference: {fileID: 927986835}
|
||||
- target: {fileID: 4619208353451588, guid: 54018739d95b963469324ffd1b785e1b, type: 2}
|
||||
propertyPath: m_LocalPosition.x
|
||||
value: -0.025982331
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4619208353451588, guid: 54018739d95b963469324ffd1b785e1b, type: 2}
|
||||
propertyPath: m_LocalPosition.y
|
||||
value: 0.014997281
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 4619208353451588, guid: 54018739d95b963469324ffd1b785e1b, type: 2}
|
||||
propertyPath: m_LocalPosition.z
|
||||
value: -0.000000029802322
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114412594797402372, guid: 54018739d95b963469324ffd1b785e1b,
|
||||
type: 2}
|
||||
propertyPath: Objects.Array.data[1]
|
||||
|
@ -567,6 +550,11 @@ Prefab:
|
|||
propertyPath: Objects.Array.data[5]
|
||||
value:
|
||||
objectReference: {fileID: 1368415538}
|
||||
- target: {fileID: 114661879801688092, guid: 54018739d95b963469324ffd1b785e1b,
|
||||
type: 2}
|
||||
propertyPath: colorPicker
|
||||
value:
|
||||
objectReference: {fileID: 790017090}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: 54018739d95b963469324ffd1b785e1b, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
|
@ -862,17 +850,6 @@ Prefab:
|
|||
propertyPath: m_RootOrder
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 114895734277317420, guid: fa4aec5413103264c884daee464826d9,
|
||||
type: 2}
|
||||
propertyPath: AlternateRightController
|
||||
value:
|
||||
objectReference: {fileID: 1430356196732642, guid: 58f27e3d07d02114d9feb8eb5448261a,
|
||||
type: 2}
|
||||
- target: {fileID: 114895734277317420, guid: fa4aec5413103264c884daee464826d9,
|
||||
type: 2}
|
||||
propertyPath: AlwaysUseAlternateRightModel
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
m_RemovedComponents: []
|
||||
m_ParentPrefab: {fileID: 100100000, guid: fa4aec5413103264c884daee464826d9, type: 2}
|
||||
m_IsPrefabParent: 0
|
||||
|
|
Загрузка…
Ссылка в новой задаче