Refresh FancyScrollView with latest fixes

pull/413/head
Simon Jackson 2023-01-03 12:25:02 +00:00
parent 12f6174469
commit 048fa7269f
5 changed files with 3 additions and 45 deletions

View File

@ -4,8 +4,6 @@
using UnityEditor; using UnityEditor;
using UnityEditor.AnimatedValues; using UnityEditor.AnimatedValues;
// For maintenance, every new [SerializeField] variable in Scroller must be declared here
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
[CustomEditor(typeof(Scroller))] [CustomEditor(typeof(Scroller))]
@ -20,16 +18,11 @@ namespace UnityEngine.UI.Extensions
SerializedProperty inertia; SerializedProperty inertia;
SerializedProperty decelerationRate; SerializedProperty decelerationRate;
SerializedProperty snap; SerializedProperty snap;
SerializedProperty snapEnable;
SerializedProperty snapVelocityThreshold;
SerializedProperty snapDuration;
SerializedProperty snapEasing;
SerializedProperty draggable; SerializedProperty draggable;
SerializedProperty scrollbar; SerializedProperty scrollbar;
AnimBool showElasticity; AnimBool showElasticity;
AnimBool showInertiaRelatedValues; AnimBool showInertiaRelatedValues;
AnimBool showSnapEnableRelatedValues;
void OnEnable() void OnEnable()
{ {
@ -41,16 +34,11 @@ namespace UnityEngine.UI.Extensions
inertia = serializedObject.FindProperty("inertia"); inertia = serializedObject.FindProperty("inertia");
decelerationRate = serializedObject.FindProperty("decelerationRate"); decelerationRate = serializedObject.FindProperty("decelerationRate");
snap = serializedObject.FindProperty("snap"); snap = serializedObject.FindProperty("snap");
snapEnable = serializedObject.FindProperty("snap.Enable");
snapVelocityThreshold = serializedObject.FindProperty("snap.VelocityThreshold");
snapDuration = serializedObject.FindProperty("snap.Duration");
snapEasing = serializedObject.FindProperty("snap.Easing");
draggable = serializedObject.FindProperty("draggable"); draggable = serializedObject.FindProperty("draggable");
scrollbar = serializedObject.FindProperty("scrollbar"); scrollbar = serializedObject.FindProperty("scrollbar");
showElasticity = new AnimBool(Repaint); showElasticity = new AnimBool(Repaint);
showInertiaRelatedValues = new AnimBool(Repaint); showInertiaRelatedValues = new AnimBool(Repaint);
showSnapEnableRelatedValues = new AnimBool(Repaint);
SetAnimBools(true); SetAnimBools(true);
} }
@ -58,14 +46,12 @@ namespace UnityEngine.UI.Extensions
{ {
showElasticity.valueChanged.RemoveListener(Repaint); showElasticity.valueChanged.RemoveListener(Repaint);
showInertiaRelatedValues.valueChanged.RemoveListener(Repaint); showInertiaRelatedValues.valueChanged.RemoveListener(Repaint);
showSnapEnableRelatedValues.valueChanged.RemoveListener(Repaint);
} }
void SetAnimBools(bool instant) void SetAnimBools(bool instant)
{ {
SetAnimBool(showElasticity, !movementType.hasMultipleDifferentValues && movementType.enumValueIndex == (int)MovementType.Elastic, instant); SetAnimBool(showElasticity, !movementType.hasMultipleDifferentValues && movementType.enumValueIndex == (int)MovementType.Elastic, instant);
SetAnimBool(showInertiaRelatedValues, !inertia.hasMultipleDifferentValues && inertia.boolValue, instant); SetAnimBool(showInertiaRelatedValues, !inertia.hasMultipleDifferentValues && inertia.boolValue, instant);
SetAnimBool(showSnapEnableRelatedValues, !snapEnable.hasMultipleDifferentValues && snapEnable.boolValue, instant);
} }
void SetAnimBool(AnimBool a, bool value, bool instant) void SetAnimBool(AnimBool a, bool value, bool instant)
@ -126,31 +112,6 @@ namespace UnityEngine.UI.Extensions
{ {
EditorGUILayout.PropertyField(decelerationRate); EditorGUILayout.PropertyField(decelerationRate);
EditorGUILayout.PropertyField(snap); EditorGUILayout.PropertyField(snap);
using (new EditorGUI.IndentLevelScope())
{
DrawSnapRelatedValues();
}
}
}
}
void DrawSnapRelatedValues()
{
if (snap.isExpanded)
{
EditorGUILayout.PropertyField(snapEnable);
using (var group = new EditorGUILayout.FadeGroupScope(showSnapEnableRelatedValues.faded))
{
if (!group.visible)
{
return;
}
EditorGUILayout.PropertyField(snapVelocityThreshold);
EditorGUILayout.PropertyField(snapDuration);
EditorGUILayout.PropertyField(snapEasing);
} }
} }
} }

View File

@ -1,7 +1,6 @@
/// Credit setchi (https://github.com/setchi) /// Credit setchi (https://github.com/setchi)
/// Sourced from - https://github.com/setchi/FancyScrollView /// Sourced from - https://github.com/setchi/FancyScrollView
namespace UnityEngine.UI.Extensions namespace UnityEngine.UI.Extensions
{ {
/// <summary> /// <summary>

View File

@ -101,7 +101,7 @@ namespace UnityEngine.UI.Extensions
/// <param name="p"><see cref="Scroller"/> のスクロール位置.</param> /// <param name="p"><see cref="Scroller"/> のスクロール位置.</param>
void OnScrollerValueChanged(float p) void OnScrollerValueChanged(float p)
{ {
base.UpdatePosition(Scrollable ? ToFancyScrollViewPosition(p) : 0f); base.UpdatePosition(ToFancyScrollViewPosition(Scrollable ? p : 0f));
if (Scroller.Scrollbar) if (Scroller.Scrollbar)
{ {
@ -161,8 +161,6 @@ namespace UnityEngine.UI.Extensions
/// <inheritdoc/> /// <inheritdoc/>
protected override void UpdateContents(IList<TItemData> items) protected override void UpdateContents(IList<TItemData> items)
{ {
Debug.Assert(Context.CalculateScrollSize != null);
AdjustCellIntervalAndScrollOffset(); AdjustCellIntervalAndScrollOffset();
base.UpdateContents(items); base.UpdateContents(items);

View File

@ -53,4 +53,4 @@ namespace UnityEngine.UI.Extensions
/// <inheritdoc/> /// <inheritdoc/>
public sealed override void SetContext(FancyScrollRectContext context) => base.SetContext(context); public sealed override void SetContext(FancyScrollRectContext context) => base.SetContext(context);
} }
} }

View File

@ -329,7 +329,7 @@ namespace UnityEngine.UI.Extensions
if (hold && snap.Enable) if (hold && snap.Enable)
{ {
UpdateSelection(Mathf.Clamp(Mathf.RoundToInt(currentPosition), 0, totalCount - 1)); UpdateSelection(Mathf.RoundToInt(CircularPosition(currentPosition, totalCount)));
ScrollTo(Mathf.RoundToInt(currentPosition), snap.Duration, snap.Easing); ScrollTo(Mathf.RoundToInt(currentPosition), snap.Duration, snap.Easing);
} }