You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
6.9 KiB
282 lines
6.9 KiB
|
1 month ago
|
using System;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.Serialization;
|
||
|
|
|
||
|
|
namespace UDE_HAND_INTERACTION
|
||
|
|
{
|
||
|
|
public class FingerPressInteractable : DetectorInteractable<FingerPressInteractor, FingerPressInteractable>
|
||
|
|
{
|
||
|
|
public InteractableSurface _surfacePatch;
|
||
|
|
public ISurfacePatch SurfacePatch { get; private set; }
|
||
|
|
|
||
|
|
[FormerlySerializedAs("_maxDistance")]
|
||
|
|
public float _enterHoverNormal;
|
||
|
|
public float _exitHoverNormal;
|
||
|
|
public float _enterHoverTangent;
|
||
|
|
public float _exitHoverTangent;
|
||
|
|
[FormerlySerializedAs("_releaseDistance")]
|
||
|
|
public float _cancelSelectNormal;
|
||
|
|
public float _cancelSelectTangent;
|
||
|
|
|
||
|
|
|
||
|
|
public class MinThresholdsConfig
|
||
|
|
{
|
||
|
|
public bool Enabled;
|
||
|
|
public float MinNormal = 0.01f;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private MinThresholdsConfig _minThresholds = new MinThresholdsConfig()
|
||
|
|
{
|
||
|
|
Enabled = false,
|
||
|
|
MinNormal = 0.01f
|
||
|
|
};
|
||
|
|
|
||
|
|
public class DragThresholdsConfig
|
||
|
|
{
|
||
|
|
public bool Enabled;
|
||
|
|
public float DragNormal;
|
||
|
|
public float DragTangent;
|
||
|
|
public ProgressCurve DragEaseCurve;
|
||
|
|
}
|
||
|
|
|
||
|
|
private DragThresholdsConfig _dragThresholds = new DragThresholdsConfig()
|
||
|
|
{
|
||
|
|
Enabled = true,
|
||
|
|
DragNormal = 0.01f,
|
||
|
|
DragTangent = 0.01f,
|
||
|
|
DragEaseCurve = new ProgressCurve(AnimationCurve.EaseInOut(0, 0, 1, 1), 0.05f)
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
public class PositionPinningConfig
|
||
|
|
{
|
||
|
|
|
||
|
|
public bool Enabled;
|
||
|
|
public float MaxPinDistance;
|
||
|
|
public AnimationCurve PinningEaseCurve;
|
||
|
|
public ProgressCurve ResyncCurve;
|
||
|
|
}
|
||
|
|
|
||
|
|
private PositionPinningConfig _positionPinning = new PositionPinningConfig()
|
||
|
|
{
|
||
|
|
Enabled = false,
|
||
|
|
MaxPinDistance = 0.075f,
|
||
|
|
PinningEaseCurve = AnimationCurve.EaseInOut(0.2f, 0, 1, 1),
|
||
|
|
ResyncCurve = new ProgressCurve(AnimationCurve.EaseInOut(0, 0, 1, 1), 0.2f)
|
||
|
|
};
|
||
|
|
|
||
|
|
|
||
|
|
public class RecoilAssistConfig
|
||
|
|
{
|
||
|
|
public bool Enabled;
|
||
|
|
public bool UseDynamicDecay;
|
||
|
|
public AnimationCurve DynamicDecayCurve;
|
||
|
|
public bool UseVelocityExpansion;
|
||
|
|
public float VelocityExpansionMinSpeed;
|
||
|
|
public float VelocityExpansionMaxSpeed;
|
||
|
|
public float VelocityExpansionDistance;
|
||
|
|
public float VelocityExpansionDecayRate;
|
||
|
|
public float ExitDistance;
|
||
|
|
public float ReEnterDistance;
|
||
|
|
}
|
||
|
|
|
||
|
|
private RecoilAssistConfig _recoilAssist = new RecoilAssistConfig()
|
||
|
|
{
|
||
|
|
Enabled = false,
|
||
|
|
UseDynamicDecay = false,
|
||
|
|
DynamicDecayCurve = new AnimationCurve(
|
||
|
|
new Keyframe(0f, 50f), new Keyframe(0.9f, 0.5f, -47, -47)),
|
||
|
|
UseVelocityExpansion = false,
|
||
|
|
VelocityExpansionMinSpeed = 0.4f,
|
||
|
|
VelocityExpansionMaxSpeed = 1.4f,
|
||
|
|
VelocityExpansionDistance = 0.055f,
|
||
|
|
VelocityExpansionDecayRate = 0.125f,
|
||
|
|
ExitDistance = 0.02f,
|
||
|
|
ReEnterDistance = 0.02f
|
||
|
|
};
|
||
|
|
|
||
|
|
private float _closeDistanceThreshold = 0.001f;
|
||
|
|
|
||
|
|
private int _tiebreakerScore = 0;
|
||
|
|
|
||
|
|
public float EnterHoverNormal
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _enterHoverNormal;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_enterHoverNormal = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float EnterHoverTangent
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _enterHoverTangent;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_enterHoverTangent = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float ExitHoverNormal
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _exitHoverNormal;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_exitHoverNormal = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float ExitHoverTangent
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _exitHoverTangent;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_exitHoverTangent = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float CancelSelectNormal
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _cancelSelectNormal;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_cancelSelectNormal = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float CancelSelectTangent
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _cancelSelectTangent;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_cancelSelectTangent = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public float CloseDistanceThreshold
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _closeDistanceThreshold;
|
||
|
|
}
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_closeDistanceThreshold = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
public MinThresholdsConfig MinThresholds
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _minThresholds;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_minThresholds = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public DragThresholdsConfig DragThresholds
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _dragThresholds;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_dragThresholds = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public PositionPinningConfig PositionPinning
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _positionPinning;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_positionPinning = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public RecoilAssistConfig RecoilAssist
|
||
|
|
{
|
||
|
|
get
|
||
|
|
{
|
||
|
|
return _recoilAssist;
|
||
|
|
}
|
||
|
|
|
||
|
|
set
|
||
|
|
{
|
||
|
|
_recoilAssist = value;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
protected override void Awake()
|
||
|
|
{
|
||
|
|
base.Awake();
|
||
|
|
_surfacePatch = transform.GetComponentInChildren<InteractableSurface>();
|
||
|
|
SurfacePatch = _surfacePatch.GetComponent<ISurfacePatch>();
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void Start()
|
||
|
|
{
|
||
|
|
this.BeginStart(ref _started, () => base.Start());
|
||
|
|
this.AssertField(SurfacePatch, nameof(SurfacePatch));
|
||
|
|
|
||
|
|
_exitHoverNormal = Mathf.Max(_enterHoverNormal, _exitHoverNormal);
|
||
|
|
_exitHoverTangent = Mathf.Max(_enterHoverTangent, _exitHoverTangent);
|
||
|
|
|
||
|
|
if (_cancelSelectTangent > 0)
|
||
|
|
{
|
||
|
|
_cancelSelectTangent = Mathf.Max(_exitHoverTangent, _cancelSelectTangent);
|
||
|
|
}
|
||
|
|
|
||
|
|
if (_minThresholds.Enabled && _minThresholds.MinNormal > 0f)
|
||
|
|
{
|
||
|
|
_minThresholds.MinNormal = Mathf.Min(_minThresholds.MinNormal, _enterHoverNormal);
|
||
|
|
}
|
||
|
|
this.EndStart(ref _started);
|
||
|
|
}
|
||
|
|
|
||
|
|
public bool ClosestBackingSurfaceHit(Vector3 point, out SurfaceHit hit)
|
||
|
|
{
|
||
|
|
return SurfacePatch.BackingSurface.ClosestSurfacePoint(point, out hit);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|