Add double-click-to-reset on all sliders (interval + pointer tolerance) and sync PaintHud slider defaults
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf794643a6
commit
7fb0ff54b1
4 files changed
+537
-23
No files matched your search
@@ -67,7 +67,7 @@ public partial class MeshPainter : MonoBehaviour
|
||||
/// <summary>Companion to <see cref="CamoHalfLambert"/>: scales down the direct specular highlight.</summary>
|
||||
public float CamoSpecularDampen
|
||||
{
|
||||
get => GetMatFloat(SpecularDampenId, 0f);
|
||||
get => GetMatFloat(SpecularDampenId, 0.1f);
|
||||
set => SetMatFloat(SpecularDampenId, value);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Double-clicking a slider resets it to its default value. The default is the slider's authored
|
||||
/// value, serialized when the component is added (runtime seeding from settings/persistence must not
|
||||
/// overwrite it, so it is captured at edit time, not in Awake). The reset goes through slider.value,
|
||||
/// so onValueChanged listeners (persistence, SliderCurve, value labels) fire as if the user dragged.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Slider))]
|
||||
public class SliderDoubleClickReset : MonoBehaviour, IPointerClickHandler
|
||||
{
|
||||
[SerializeField, Tooltip("Raw slider value restored on double-click. Seeded from the slider's authored value when the component is added.")]
|
||||
private float _defaultValue;
|
||||
|
||||
[SerializeField, Tooltip("Max seconds between the two clicks.")]
|
||||
private float _maxClickInterval = 0.25f;
|
||||
|
||||
[SerializeField, Tooltip("Max pointer movement (screen pixels) between the two clicks.")]
|
||||
private float _maxPointerDistance = 8f;
|
||||
|
||||
private float _lastClickTime = float.NegativeInfinity;
|
||||
private Vector2 _lastClickPosition;
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (eventData.button != PointerEventData.InputButton.Left) return;
|
||||
|
||||
// Unitys clickCount (festes ~0.3s-Fenster, kein Positions-Check) bewusst ignoriert.
|
||||
bool isDouble = Time.unscaledTime - _lastClickTime <= _maxClickInterval
|
||||
&& (eventData.position - _lastClickPosition).sqrMagnitude <= _maxPointerDistance * _maxPointerDistance;
|
||||
|
||||
_lastClickTime = isDouble ? float.NegativeInfinity : Time.unscaledTime;
|
||||
_lastClickPosition = eventData.position;
|
||||
|
||||
if (isDouble) GetComponent<Slider>().value = _defaultValue;
|
||||
}
|
||||
|
||||
private void Reset() => _defaultValue = GetComponent<Slider>().value;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3e16aacd913a5149ab3ccf77d93cd5c
|
||||
Reference in new issue
Block a user