Class Slider
Graphical representation of a Slider, displayed on the Beatmap Canvas by the HitObjectManager, and checked for mouse click by the BeatmapRunner.
Namespace: MouseDance.Runtime
Assembly: MouseDance.Runtime.dll
Syntax
public class Slider : MonoBehaviour, ISlider, IHitObjectWithEvents, IHitObject
Remarks
The Slider takes care of its own fading in and out. It makes use of an SDFCurve to show the curve. It directs the SliderBall to roll through it when the time comes. Hit and miss visual effects are handled by the HitObjectManager.
Fields
_approachCircle
Declaration
[Header("Approach Circle")]
[SerializeField]
[Tooltip("Used to animate the Approach Circle's size.")]
protected RectTransform _approachCircle
Field Value
Type | Description |
---|---|
RectTransform |
_approachCircleFinalSize
Diameter of the Approach Circle at the end of its animation. This is usually the same value as the _sliderThickness.
Declaration
protected float _approachCircleFinalSize
Field Value
Type | Description |
---|---|
Single |
_approachCircleFinalSizeMultiplier
Declaration
[SerializeField]
[Tooltip("How big the Approach Circle should be at its final position, relative to the Start Cap's size. Default is 1 (same size as the Start Cap size). If your Start Cap has a custom shape and the Approach Circle is still visible at its final position, you may want to set this to a value smaller than 1.")]
protected float _approachCircleFinalSizeMultiplier
Field Value
Type | Description |
---|---|
Single |
_approachCircleImage
Declaration
[SerializeField]
[Tooltip("Used to fade-in or fade-out the Approach Circle as needed.")]
protected Image _approachCircleImage
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_approachCircleOpacity
Declaration
[SerializeField]
[Tooltip("Final opacity of the Approach Circle once it's fully faded-in. Normally set to 1.0, but you can set this to less than 1.0 if you want the Approach Circle to be transparent even after it has faded-in.")]
[Range(0F, 1F)]
protected float _approachCircleOpacity
Field Value
Type | Description |
---|---|
Single |
_approachCircleStartSize
Diameter of the Approach Circle at the start. This is naturally larger than the final size, since the Approach Circle shrinks as time goes by.
Declaration
protected float _approachCircleStartSize
Field Value
Type | Description |
---|---|
Single |
_ball
Reference to the Slider Ball that will move through the Slider.
Declaration
protected ISliderBall _ball
Field Value
Type | Description |
---|---|
ISliderBall |
_ballColour
Colour the Slider Ball will be in, once it starts moving through this Slider.
Declaration
protected Color _ballColour
Field Value
Type | Description |
---|---|
Color |
_ballNowMoving
Whether Slider Ball has finally started to move through this Slider.
Declaration
protected bool _ballNowMoving
Field Value
Type | Description |
---|---|
Boolean |
_ballRadius
Size the Slider Ball will be in, once it starts moving through this Slider.
Declaration
protected float _ballRadius
Field Value
Type | Description |
---|---|
Single |
_ballSpeed
Speed of Ball in osu! pixels per millisecond
Declaration
protected double _ballSpeed
Field Value
Type | Description |
---|---|
Double |
_ballTravelDuration
Duration it takes for Ball to travel the Slider once, in milliseconds. To get the total duration, this is multiplied by _numberOfTimes.
Declaration
protected float _ballTravelDuration
Field Value
Type | Description |
---|---|
Single |
_beatmapRunner
Needed to report to the game when user pressed the slider.
Declaration
protected IBeatmapRunner _beatmapRunner
Field Value
Type | Description |
---|---|
IBeatmapRunner |
_borderScaleAtSmallestCircleSize
Declaration
[SerializeField]
[Tooltip("What the Border Image's scale needs to be when this Slider is set to Circle Size 10. Leave at 1.0 if adjustment is not necessary.")]
protected float _borderScaleAtSmallestCircleSize
Field Value
Type | Description |
---|---|
Single |
_colliderSizeOffset
Declaration
[SerializeField]
[Tooltip("Adjustment to the size of the Collider after it is resized according to the Circle Size. This value is added (or subtracted if this value is negative). Leave at 0 if not needed.")]
protected float _colliderSizeOffset
Field Value
Type | Description |
---|---|
Single |
_curveSmoothnessPercent
Declaration
[SerializeField]
[Range(0.01F, 1F)]
[Tooltip("How many points the curve will have compared to its pixel length. 1.0 means to use 100% of the pixel length value.\n\nThe pixel length is a high value, and we don't need that much points in the curve to produce a smooth-looking curve (you may even have problems in WebGL builds if the amount of points is too high), so a value of 0.1 (10%) is advisable as more than enough, but you can change this value as needed.")]
protected float _curveSmoothnessPercent
Field Value
Type | Description |
---|---|
Single |
_curveType
What kind of Osu curve this Slider is showing.
Declaration
protected CurveType _curveType
Field Value
Type | Description |
---|---|
OsuParsers.Enums.Beatmaps.CurveType |
_endCapBorder
Declaration
[SerializeField]
protected Image _endCapBorder
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_endCapImage
Declaration
[SerializeField]
protected Image _endCapImage
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_endCapRepeatArrow
Declaration
[SerializeField]
[Tooltip("Needed so we can orient the Repeat Arrow in the correct direction.")]
protected Transform _endCapRepeatArrow
Field Value
Type | Description |
---|---|
Transform |
_endCapRepeatArrowImage
Declaration
[Header("Repeat Arrow (Arrow shown at the End Cap)")]
[SerializeField]
[Tooltip("Needed so we can show the Repeat Arrow when needed.")]
protected Image _endCapRepeatArrowImage
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_growHitCircleOnShow
Declaration
[SerializeField]
[Tooltip("Do we animate the Start Cap growing in size at the same time that it's being faded-in?")]
protected bool _growHitCircleOnShow
Field Value
Type | Description |
---|---|
Boolean |
_headScore
Determines whether player did a perfect press on the Slider head (start cap) or not.
Declaration
protected int _headScore
Field Value
Type | Description |
---|---|
Int32 |
_lineEndCap
Declaration
[Header("End Cap (Circle that's positioned at the end of the Slider)")]
[SerializeField]
protected RectTransform _lineEndCap
Field Value
Type | Description |
---|---|
RectTransform |
_manager
Needed to allow this Slider to be despawned and moved back to pool for reusing, and for reporting when user has pressed the slider right or wrong so it can play the proper sound/visual fx.
Declaration
protected HitObjectManager _manager
Field Value
Type | Description |
---|---|
HitObjectManager |
_numberOfSliderPartsPressed
Declaration
protected int _numberOfSliderPartsPressed
Field Value
Type | Description |
---|---|
Int32 |
_numberOfTimes
Number of times Ball has to travel through the Slider. This should be at least 1.
Declaration
protected int _numberOfTimes
Field Value
Type | Description |
---|---|
Int32 |
_pointBuffer
Declaration
protected readonly List<Vector2> _pointBuffer
Field Value
Type | Description |
---|---|
List<Vector2> |
_points
Local-space positions of each point in the slider's line. This is the path that the ball needs to move through.
Declaration
protected readonly List<Vector3> _points
Field Value
Type | Description |
---|---|
List<Vector3> |
_positionOffset
Declaration
[SerializeField]
[Tooltip("If the game is shown or positioned in some special way, you can add an offset to the positions of sliders here. Leave value at (0, 0) if not needed.")]
protected Vector2 _positionOffset
Field Value
Type | Description |
---|---|
Vector2 |
_rectTransform
Declaration
[SerializeField]
[Tooltip("Used for positioning the entire Slider.")]
protected RectTransform _rectTransform
Field Value
Type | Description |
---|---|
RectTransform |
_reportedSuccess
Flag to indicate if we already reported hit to the BeatmapRunner or not, to prevent duplicate calls.
Declaration
protected bool _reportedSuccess
Field Value
Type | Description |
---|---|
Boolean |
_sdfCurve
This is the main body of the Slider that the player sees.
Declaration
protected SDFCurve _sdfCurve
Field Value
Type | Description |
---|---|
SDFCurve |
_sliderThickness
Thickness of the slider, in diameter.
Declaration
protected float _sliderThickness
Field Value
Type | Description |
---|---|
Single |
_sliderThicknessMultiplier
Declaration
[Header("Settings")]
[SerializeField]
[Tooltip("Multiplier to the slider thickness. 1.0 means no change. Greater than 1 means bigger, lesser than 1 means smaller. This multiplier is applied on top of the Osu file's \"Circle Size\" setting, and even on top of the MouseDance.Runtime.HitObjectManager's Circle Radius Multiplier.")]
protected float _sliderThicknessMultiplier
Field Value
Type | Description |
---|---|
Single |
_startBorderScaleAfter
Declaration
[SerializeField]
[Tooltip("Start scaling the Border Image towards \"Border Scale At Smallest Circle Size\" after this Circle Size value. So a value of 5 here means, Border Image scale starts getting adjusted when the Circle Size this Slider is set to is from 6 to 10.")]
protected int _startBorderScaleAfter
Field Value
Type | Description |
---|---|
Int32 |
_startCap
Declaration
[Header("Start Cap (Circle that's positioned at the start of the Slider)")]
[SerializeField]
[Tooltip("Used to properly set the size of the Start Cap.")]
protected RectTransform _startCap
Field Value
Type | Description |
---|---|
RectTransform |
_startCapBorder
Declaration
[SerializeField]
protected Image _startCapBorder
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_startCapFadeOutDuration
Declaration
[SerializeField]
[Tooltip("Duration how long to do a fade-out of the Start Cap, once the Ball is finally moving through the Slider.")]
protected float _startCapFadeOutDuration
Field Value
Type | Description |
---|---|
Single |
_startCapImage
Declaration
[SerializeField]
[Tooltip("Used to fade the Start Cap in and out as needed.")]
protected Image _startCapImage
Field Value
Type | Description |
---|---|
UnityEngine.UI.Image |
_text
Declaration
[SerializeField]
[Tooltip("Used to display the number on the Slider.")]
protected TextMeshProUGUI _text
Field Value
Type | Description |
---|---|
TMPro.TextMeshProUGUI |
_tickCount
Declaration
protected int _tickCount
Field Value
Type | Description |
---|---|
Int32 |
_tickIndices
Indices in the _points list that each SliderTick is representing.
Declaration
protected readonly List<int> _tickIndices
Field Value
Type | Description |
---|---|
List<Int32> |
_ticks
List of all SliderTick prefabs that the Slider is currently using.
Declaration
protected readonly List<SliderTick> _ticks
Field Value
Type | Description |
---|---|
List<SliderTick> |
_timeBallMove
Absolute time that the ball will start to move through the Slider.
Declaration
protected float _timeBallMove
Field Value
Type | Description |
---|---|
Single |
_timeStarted
Absolute time the Slider started showing up. This is used to properly calculate the percentage progress of its lifetime.
Declaration
protected float _timeStarted
Field Value
Type | Description |
---|---|
Single |
_timeToApproachCircleEnd
Absolute time the Approach Circle for the Slider will finish.
Declaration
protected float _timeToApproachCircleEnd
Field Value
Type | Description |
---|---|
Single |
_timeToApproachCircleFullOpacity
Absolute time when the Approach Circle has completely faded-in.
Declaration
protected float _timeToApproachCircleFullOpacity
Field Value
Type | Description |
---|---|
Single |
_timeToDie
Absolute time the Slider should start fading out.
Declaration
protected float _timeToDie
Field Value
Type | Description |
---|---|
Single |
_timeToFullOpacity
Absolute time when the Slider has completely faded-in.
Declaration
protected float _timeToFullOpacity
Field Value
Type | Description |
---|---|
Single |
_wasEverReleased
We need to keep track of if ever player released the mouse button when pressing this slider, because doing so prevents them from getting a perfect score for this slider, even if they managed to hit all the slider parts.
Declaration
protected bool _wasEverReleased
Field Value
Type | Description |
---|---|
Boolean |
Properties
Colour
Colour that this Slider is in. Used by visual effects so that their colour matches the Slider's colour.
Declaration
public virtual Color Colour { get; }
Property Value
Type | Description |
---|---|
Color |
ComboColourIndex
The index of the colour used by this Slider. This can be used to identify or differentiate this Slider from other Hit Objects that are using a different colour.
Declaration
public virtual int ComboColourIndex { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
ComboCounter
The number displayed on this Slider.
Declaration
public virtual int ComboCounter { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
EffectsPos
When this Hit Object is pressed or missed, this is the position where the visual effects should spawn in. For Sliders, this position is the Slider's tail-end.
Declaration
public virtual Vector3 EffectsPos { get; }
Property Value
Type | Description |
---|---|
Vector3 | An (x, y, z) position |
Remarks
This is an (x, y, z) position, though the z value is 0 and can be ignored. The only reason why this is a Vector3 and not a Vector2 is so that this value can be easily assigned to a Transform's position.
Index
Index position of this Slider in the entire Beatmap. Starts at 0.
Declaration
public virtual int Index { get; protected set; }
Property Value
Type | Description |
---|---|
Int32 |
IsEnabled
Informs the BeatmapRunner whether it should consider this Slider as hittable or not. Disabled Sliders are "despawned" and are back into the pool and therefore should not be used.
Declaration
public virtual bool IsEnabled { get; }
Property Value
Type | Description |
---|---|
Boolean | True: This Slider is "enabled", currently being used and is on-screen. |
PoolId
What pool of Slider prefabs this prefab belongs to. Important once it's time to despawn this Slider.
Declaration
public virtual string PoolId { get; protected set; }
Property Value
Type | Description |
---|---|
String |
Pressed
Whether this Slider has been pressed already.
Declaration
public virtual bool Pressed { get; protected set; }
Property Value
Type | Description |
---|---|
Boolean | True: Slider has already been pressed. |
RequiredBallDistanceToMouse
How close the mouse cursor (or touch input, on mobile) needs to be to the ball for it to count as a "hit". Used in OnBallReachedPositionInPath(Int32, Int32, Boolean, Single).
Declaration
protected float RequiredBallDistanceToMouse { get; }
Property Value
Type | Description |
---|---|
Single |
RequiresHold
Does this Hit Object need to be pressed for a long time? For Sliders, this always returns true.
Declaration
public virtual bool RequiresHold { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
Hide()
Hide this Slider immediately (no fade out).
Declaration
public virtual void Hide()
IsNameMatch(String)
Is specified name the kind of name assigned to Sliders?
Declaration
public static bool IsNameMatch(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name |
Returns
Type | Description |
---|---|
Boolean |
OnBallReachedPositionInPath(Int32, Int32, Boolean, Single)
Called by the SliderBall to notify this Slider of the ball's progress rolling through.
Declaration
public virtual void OnBallReachedPositionInPath(int pathIdx, int numberOfTimes, bool forwardDirection, float ballDistanceToMouse)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pathIdx | The position that the ball has reached. |
Int32 | numberOfTimes | Number of times left. 1 means this is the final movement. |
Boolean | forwardDirection | Whether we are moving forward (from head to tail) or reverse (from tail to head). |
Single | ballDistanceToMouse | How far away the mouse cursor is from the Slider Ball (in osu!pixels) at the moment. This is important because a hit is only considered if the mouse cursor is near enough. |
OnPressed(Int32)
Called by the BeatmapRunner to notify this Slider that its start cap (head) has been pressed by the player. This lets the Slider know whether the head had been collected properly. This is important since it's part of how the player's score is calculated for this Slider.
Declaration
public virtual void OnPressed(int idxThatNeedsToBePressed)
Parameters
Type | Name | Description |
---|---|---|
Int32 | idxThatNeedsToBePressed | The current Hit Object index that should be pressed right now. If this doesn't match the Slider's own Index, then the player clicked out-of-sequence. |
OnPressedBody()
Called by the BeatmapRunner to notify this Slider that the player clicked on the SliderBall while it's already in-the-process of moving through this Slider.
Declaration
public virtual void OnPressedBody()
OnReachedEnd()
Called by the BeatmapRunner to notify this Slider that its End Time has been reached.
Declaration
public virtual void OnReachedEnd()
OnReleased()
Called by the BeatmapRunner to notify this Slider that the player released their press on it.
Declaration
public virtual void OnReleased()
Resize(Single, Single)
Declaration
public virtual void Resize(float radius, float radiusMultiplier)
Parameters
Type | Name | Description |
---|---|---|
Single | radius | |
Single | radiusMultiplier |
Resize(Single, Single, Boolean)
Resize this Slider with specified radius.
Declaration
public virtual void Resize(float radius, float radiusMultiplier, bool applyToSdfCurve)
Parameters
Type | Name | Description |
---|---|---|
Single | radius | The radius that will be used for the start and end caps, as well as the thickness of the slider body. |
Single | radiusMultiplier | Multiplier to the size coming from CircleRadiusMultiplier. |
Boolean | applyToSdfCurve | Apply resizing to the SDF Curve as well. |
Show(HitObjectManager, IBeatmapRunner, ISliderBall, String, Int32, Int32, Int32, Gradient, Color32, Color32, Color32, Boolean, Boolean, Double, Slider, Single, Single, Single, Single, Double, Double)
Show this Slider with the specified position, colour, etc. This overload also initializes the Slider's reference to the HitObjectManager and BeatmapRunner, and is called for newly instantiated Sliders.
Declaration
public virtual void Show(HitObjectManager manager, IBeatmapRunner beatmapRunner, ISliderBall ball, string poolId, int idx, int comboCounter, int comboColourIdx, Gradient colour, Color32 borderColour, Color32 repeatArrowColour, Color32 ballColour, bool applyColourToApproachCircles, bool showNumber, double beatLength, Slider slider, float positionScale, float radius, float radiusMultiplier, float approachRateDuration, double sliderMultiplier, double sliderTickRate)
Parameters
Type | Name | Description |
---|---|---|
HitObjectManager | manager | Which HitObjectManager manages this Slider. Needed to allow this Slider to be despawned and moved back to pool for reusing, and for reporting when user has pressed the Slider right or wrong so it can play the proper sound/visual fx. |
IBeatmapRunner | beatmapRunner | Needed by the Slider so it can report to the game when player pressed that Slider's head. This also lets the Slider know if the player pressed too early or not. |
ISliderBall | ball | Slider needs to be able to tell the Slider Ball to roll through it when the time comes. |
String | poolId | Which pool of prefabs this Hit Circle will belong to. |
Int32 | idx | Numerical position of the Slider in the entire Beatmap. |
Int32 | comboCounter | The number that should be displayed in this Slider. |
Int32 | comboColourIdx | The index of the colour used by this Hit Object. This can be used to identify or differentiate this Hit Object from others using a different colour. |
Gradient | colour | Colour that this Slider should be in. |
Color32 | borderColour | Colour that this Slider's borders should be in. |
Color32 | repeatArrowColour | Colour that this Slider's repeat arrow should be in. |
Color32 | ballColour | Colour that the SliderBall should be in once it's rolling through this Slider. |
Boolean | applyColourToApproachCircles | Whether specified colour should also be applied to the Approach Circle. If false, Approach Circle will just be white. |
Boolean | showNumber | Whether to show the number on this Slider or not. |
Double | beatLength | How long one beat is, in milliseconds. This is needed because we will be putting Slider Ticks on each beat. |
OsuParsers.Beatmaps.Objects.Slider | slider | More data on the Slider. |
Single | positionScale | |
Single | radius | The radius that will be used for the start and end caps, as well as the thickness of the slider body. Based on the OsuParsers.Beatmaps.Sections.BeatmapDifficultySection.CircleSize. |
Single | radiusMultiplier | Multiplier to the size coming from CircleRadiusMultiplier. |
Single | approachRateDuration | How long it will take for the Approach Circle to do its shrinking animation. |
Double | sliderMultiplier | Controls ball speed. |
Double | sliderTickRate | How many Slider Ticks per beat. Default is 1 (1 Slider Tick per 1 beat). 0.5 means 1 Slider Tick per 2 beats. |
Show(String, Int32, Int32, Int32, Gradient, Color32, Color32, Color32, Boolean, Boolean, Double, Slider, Single, Single, Single, Single, Double, Double)
Show this Slider with the specified position, colour, etc. This is called on reused Sliders.
Declaration
public virtual void Show(string poolId, int idx, int comboCounter, int comboColourIdx, Gradient colour, Color32 borderColour, Color32 repeatArrowColour, Color32 ballColour, bool applyColourToApproachCircles, bool showNumber, double beatLength, Slider slider, float positionScale, float radius, float radiusMultiplier, float approachRateDuration, double sliderMultiplier, double sliderTickRate)
Parameters
Type | Name | Description |
---|---|---|
String | poolId | Which pool of prefabs this Hit Circle will belong to. |
Int32 | idx | Numerical position of the Slider in the entire Beatmap. |
Int32 | comboCounter | The number that should be displayed in this Slider. |
Int32 | comboColourIdx | The index of the colour used by this Hit Object. This can be used to identify or differentiate this Hit Object from others using a different colour. |
Gradient | colour | Colour that this Slider should be in. |
Color32 | borderColour | Colour that this Slider's borders should be in. |
Color32 | repeatArrowColour | Colour that this Slider's repeat arrow should be in. |
Color32 | ballColour | Colour that the SliderBall should be in once it's rolling through this Slider. |
Boolean | applyColourToApproachCircles | Whether specified colour should also be applied to the Approach Circle. If false, Approach Circle will just be white. |
Boolean | showNumber | Whether to show the number on this Slider or not. |
Double | beatLength | How long one beat is, in milliseconds. This is needed because we will be putting Slider Ticks on each beat. |
OsuParsers.Beatmaps.Objects.Slider | slider | More data on the Slider. |
Single | positionScale | |
Single | radius | The radius that will be used for the start and end caps, as well as the thickness of the slider body. Based on the OsuParsers.Beatmaps.Sections.BeatmapDifficultySection.CircleSize. |
Single | radiusMultiplier | Multiplier to the size coming from CircleRadiusMultiplier. |
Single | approachRateDuration | How long it will take for the Approach Circle to do its shrinking animation. |
Double | sliderMultiplier | Controls ball speed. |
Double | sliderTickRate | How many Slider Ticks per beat. Default is 1 (1 Slider Tick per 1 beat). 0.5 means 1 Slider Tick per 2 beats. |
Update()
Update method called by Unity every frame. This is used to update the Slider's animations (Approach Circle shrinking animation, fading in and out).
Declaration
public virtual void Update()