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.AnimatedValues;
// For maintenance, every new [SerializeField] variable in Scroller must be declared here
namespace UnityEngine.UI.Extensions
{
[CustomEditor(typeof(Scroller))]
@ -20,16 +18,11 @@ namespace UnityEngine.UI.Extensions
SerializedProperty inertia;
SerializedProperty decelerationRate;
SerializedProperty snap;
SerializedProperty snapEnable;
SerializedProperty snapVelocityThreshold;
SerializedProperty snapDuration;
SerializedProperty snapEasing;
SerializedProperty draggable;
SerializedProperty scrollbar;
AnimBool showElasticity;
AnimBool showInertiaRelatedValues;
AnimBool showSnapEnableRelatedValues;
void OnEnable()
{
@ -41,16 +34,11 @@ namespace UnityEngine.UI.Extensions
inertia = serializedObject.FindProperty("inertia");
decelerationRate = serializedObject.FindProperty("decelerationRate");
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");
scrollbar = serializedObject.FindProperty("scrollbar");
showElasticity = new AnimBool(Repaint);
showInertiaRelatedValues = new AnimBool(Repaint);
showSnapEnableRelatedValues = new AnimBool(Repaint);
SetAnimBools(true);
}
@ -58,14 +46,12 @@ namespace UnityEngine.UI.Extensions
{
showElasticity.valueChanged.RemoveListener(Repaint);
showInertiaRelatedValues.valueChanged.RemoveListener(Repaint);
showSnapEnableRelatedValues.valueChanged.RemoveListener(Repaint);
}
void SetAnimBools(bool instant)
{
SetAnimBool(showElasticity, !movementType.hasMultipleDifferentValues && movementType.enumValueIndex == (int)MovementType.Elastic, instant);
SetAnimBool(showInertiaRelatedValues, !inertia.hasMultipleDifferentValues && inertia.boolValue, instant);
SetAnimBool(showSnapEnableRelatedValues, !snapEnable.hasMultipleDifferentValues && snapEnable.boolValue, instant);
}
void SetAnimBool(AnimBool a, bool value, bool instant)
@ -126,31 +112,6 @@ namespace UnityEngine.UI.Extensions
{
EditorGUILayout.PropertyField(decelerationRate);
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)
/// Sourced from - https://github.com/setchi/FancyScrollView
namespace UnityEngine.UI.Extensions
{
/// <summary>

View File

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

View File

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

View File

@ -329,7 +329,7 @@ namespace UnityEngine.UI.Extensions
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);
}