Skip to content

Commit

Permalink
fix scripts and add vertically movement
Browse files Browse the repository at this point in the history
  • Loading branch information
UsefFarahmand committed Oct 3, 2024
1 parent 3d8b826 commit d4a7a9c
Show file tree
Hide file tree
Showing 22 changed files with 100 additions and 31 deletions.
11 changes: 0 additions & 11 deletions Runtime/DeltaTimeMode.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Runtime/LightScrollSnap.asmdef

This file was deleted.

8 changes: 8 additions & 0 deletions Runtime/Scripts.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;

namespace LightScrollSnap
namespace UScrollSnap
{
public abstract class BaseScrollSnapEffect : ScriptableObject
{
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using UnityEngine;
using UnityEngine.UI;

namespace LightScrollSnap
namespace UScrollSnap.Effects
{
[CreateAssetMenu(fileName = "FadeEffect", menuName = "ScrollSnapEffect/FadeEffect")]
public class FadeEffect : BaseScrollSnapEffect
[CreateAssetMenu(fileName = "FadeEffect", menuName = "UScrollSnap/FadeEffect")]
internal class FadeEffect : BaseScrollSnapEffect
{
public float fadeAlpha = .45f;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using UnityEngine;

namespace LightScrollSnap
namespace UScrollSnap
{
[CreateAssetMenu(fileName = "ScaleEffect", menuName = "ScrollSnapEffect/Scale Effect")]
public class ScaleEffect : BaseScrollSnapEffect
[CreateAssetMenu(fileName = "ScaleEffect", menuName = "UScrollSnap/Scale Effect")]
internal class ScaleEffect : BaseScrollSnapEffect
{
public Vector2 selectedItemScale = Vector2.one * 1.25f;
public Vector2 unselectedItemScale = Vector2.one;
Expand Down
File renamed without changes.
34 changes: 26 additions & 8 deletions Runtime/ScrollSnap.cs → Runtime/Scripts/ScrollSnap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using UScrollSnap.SharedTypes;
using UScrollSnap.Tools;

namespace LightScrollSnap
namespace UScrollSnap
{
[RequireComponent(typeof(ScrollRect))]
public class ScrollSnap : MonoBehaviour
{
#region INSPECTOR PROPERTIES

[SerializeField] private LayoutDirection layoutDirection = LayoutDirection.Horizontally;
[SerializeField] private DeltaTimeMode deltaTimeMode = DeltaTimeMode.Unscaled;

[Header("Scroll Settings")] [SerializeField]
[Header("Scroll Settings")]
[SerializeField]
private Scrollbar scrollbar;

[SerializeField] [Range(0, 1)] private float initialPos;
[SerializeField][Range(0, 1)] private float initialPos;
public bool autoScrollToClickedItem = true;
public float smoothScrollDuration = 0.35f;
public float smoothSnapDuration = 0.25f;

[Header("Snap Settings")] [SerializeField]
[Header("Snap Settings")]
[SerializeField]
private float snapDelayDuration = 0.15f;

[SerializeField] private float snapDistanceThreshold = 0.001f;

[Header("Effect Settings")] [SerializeField]
[Header("Effect Settings")]
[SerializeField]
private List<BaseScrollSnapEffect> effects;

#endregion
Expand Down Expand Up @@ -104,10 +110,22 @@ private void SetupItems()

_distance = _itemCount > 1 ? 1f / (_itemCount - 1f) : 1;
_items = new List<RectTransform>(_itemCount);
for (int i = 0; i < _itemCount; i++)

if (layoutDirection == LayoutDirection.Horizontally)
{
_items.Add(Content.GetChild(i).GetComponent<RectTransform>());
_posses[i] = _distance * i;
for (int i = 0; i < _itemCount; i++)
{
_items.Add(Content.GetChild(i).GetComponent<RectTransform>());
_posses[i] = _distance * i;
}
}
else
{
for (int i = _itemCount - 1; i >= 0; i--)
{
_items.Add(Content.GetChild(i).GetComponent<RectTransform>());
_posses[i] = _distance * i;
}
}

SetupClickHandlers();
Expand Down
File renamed without changes.
8 changes: 8 additions & 0 deletions Runtime/Scripts/SharedTypes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Scripts/SharedTypes/DeltaTimeMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UScrollSnap.SharedTypes
{
internal enum DeltaTimeMode
{
Scaled,
Unscaled,
}
}
File renamed without changes.
8 changes: 8 additions & 0 deletions Runtime/Scripts/SharedTypes/LayoutDirection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UScrollSnap.SharedTypes
{
internal enum LayoutDirection
{
Horizontally,
Vertically,
}
}
11 changes: 11 additions & 0 deletions Runtime/Scripts/SharedTypes/LayoutDirection.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime/Scripts/Tools.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using UnityEngine;
using UnityEngine.EventSystems;

namespace LightScrollSnap
namespace UScrollSnap.Tools
{
public class ScrollItemClickHandler : MonoBehaviour, IPointerClickHandler
internal class ScrollItemClickHandler : MonoBehaviour, IPointerClickHandler
{
private event Action _clickListener;
private void OnDestroy() => RemoveAllListeners();
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions Runtime/Scripts/UScrollSnap.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "UScrollSnap",
"rootNamespace": "UScrollSnap",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}
File renamed without changes.

0 comments on commit d4a7a9c

Please sign in to comment.