MouseDance MouseDance
MouseDance MouseDance
MouseDance User Docs powered by DocFx, DiscordFx

Search Results for

    Class HitObjectManager

    Responsible for spawning and pooling Hit Objects and visual effects, plus playing any sound effects.

    Inheritance
    Object
    Object
    Component
    Behaviour
    MonoBehaviour
    HitObjectManager
    Namespace: MouseDance.Runtime
    Assembly: MouseDance.Runtime.dll
    Syntax
    public class HitObjectManager : MonoBehaviour

    Fields

    _allHitCircles

    All Hit Circles that have been instantiated, whether they are currently used or not. Key is Pool Id, value is pool list.

    Declaration
    protected readonly Dictionary<string, List<HitCircle>> _allHitCircles
    Field Value
    Type Description
    Dictionary<String, List<HitCircle>>

    _allSliders

    All Sliders that have been instantiated, whether they are currently used or not. Key is Pool Id, value is pool list.

    Declaration
    protected readonly Dictionary<string, List<Slider>> _allSliders
    Field Value
    Type Description
    Dictionary<String, List<Slider>>

    _allSliderTicks

    All Slider Ticks that have been instantiated, whether they are currently used or not.

    Declaration
    protected readonly List<SliderTick> _allSliderTicks
    Field Value
    Type Description
    List<SliderTick>

    _audioSource

    Declaration
    [Header("Sound Effects")]
    [SerializeField]
    [Tooltip("Where sound effects are played.")]
    protected AudioSource _audioSource
    Field Value
    Type Description
    AudioSource

    _autoGeneratedGradients

    Gradient colours with values coming from the Beatmap data.

    Declaration
    protected readonly List<Gradient> _autoGeneratedGradients
    Field Value
    Type Description
    List<Gradient>

    _balls

    All Slider Balls used. Key is Pool Id, value is SliderBall.

    Declaration
    protected readonly Dictionary<string, SliderBall> _balls
    Field Value
    Type Description
    Dictionary<String, SliderBall>

    _beatmap

    Used to provide data about the Beatmap, for IHitObjectSizeCalculator.

    Declaration
    protected Beatmap _beatmap
    Field Value
    Type Description
    OsuParsers.Beatmaps.Beatmap

    _beatmapColours

    Colour data coming from the Beatmap.

    Declaration
    protected BeatmapColoursSection _beatmapColours
    Field Value
    Type Description
    OsuParsers.Beatmaps.Sections.BeatmapColoursSection

    _beatmapInput

    If assigned, this is provided to instantiated SliderBalls, so that if user specified a custom way of getting the mouse cursor position, the SliderBall can retrieve it.

    Declaration
    protected IBeatmapInput _beatmapInput
    Field Value
    Type Description
    IBeatmapInput

    _canvas

    Declaration
    [SerializeField]
    [Tooltip("Canvas where SDF Curves are displayed. Used for figuring out how much the SDF Curves should be scaled.")]
    protected RectTransform _canvas
    Field Value
    Type Description
    RectTransform

    _canvasScaler

    Declaration
    [Header("Visual Effects")]
    [SerializeField]
    [Tooltip("Needed for figuring out the proper scale of visual effects.")]
    protected CanvasScaler _canvasScaler
    Field Value
    Type Description
    UnityEngine.UI.CanvasScaler

    _colours

    Declaration
    [SerializeField]
    [Tooltip("Contains colours used for the Hit Objects.")]
    protected HitObjectColours _colours
    Field Value
    Type Description
    HitObjectColours

    _currentComboColourIdx

    What colour the current hit objects to spawn will be in. Corresponds to the index in GradientColours. This is updated every time we are about to spawn a hit object that restarts the combo (see OsuParsers.Beatmaps.Objects.HitObject.IsNewCombo).

    Declaration
    protected int _currentComboColourIdx
    Field Value
    Type Description
    Int32

    _currentComboCounter

    The "combo" counter determines what number is displayed for the next hit object to spawn.

    Declaration
    protected int _currentComboCounter
    Field Value
    Type Description
    Int32

    _currentlyUsedHitObjectList

    All Hit Objects currently used (and seen on-screen) in a list. This is used to quickly loop through all currently displayed Hit Objects to do things like changing their sizes or colours.

    Declaration
    protected readonly List<IHitObjectWithEvents> _currentlyUsedHitObjectList
    Field Value
    Type Description
    List<IHitObjectWithEvents>

    _currentlyUsedHitObjects

    Allows getting any currently used Hit Object instance based on their GameObject name. Used in GetHitObjectByName(String). This is used when a Hit Object was clicked, to get the Hit Object instance without having to use GetComponent<T>(). Key is Game Object name, value is Hit Object.

    Declaration
    protected readonly Dictionary<string, IHitObjectWithEvents> _currentlyUsedHitObjects
    Field Value
    Type Description
    Dictionary<String, IHitObjectWithEvents>

    _effects

    Declaration
    [SerializeField]
    [Tooltip("Contains all hit/miss visual effect prefabs that we need.")]
    protected HitEffectsSet _effects
    Field Value
    Type Description
    HitEffectsSet

    _hitObjectContainer

    Declaration
    [Header("Hit Objects")]
    [SerializeField]
    [Tooltip("Where Hit Objects will be parented to.")]
    protected RectTransform _hitObjectContainer
    Field Value
    Type Description
    RectTransform

    _hitObjects

    Declaration
    [Header("Config")]
    [SerializeField]
    [Tooltip("Contains all Hit Object prefabs that we need.")]
    protected HitObjectSet _hitObjects
    Field Value
    Type Description
    HitObjectSet

    _hitObjectSizeCalculator

    If assigned, this is used to figure out the size of Hit Objects. If not assigned, the Circle Size coming from the Beatmap is used instead.

    Declaration
    protected IHitObjectSizeCalculator _hitObjectSizeCalculator
    Field Value
    Type Description
    IHitObjectSizeCalculator

    _readyHitCircles

    Pooled Hit Circles that are ready to be reused. Key is Pool Id, value is pool list.

    Declaration
    protected readonly Dictionary<string, List<HitCircle>> _readyHitCircles
    Field Value
    Type Description
    Dictionary<String, List<HitCircle>>

    _readySliders

    Pooled Sliders that are ready to be reused. Key is Pool Id, value is pool list.

    Declaration
    protected readonly Dictionary<string, List<Slider>> _readySliders
    Field Value
    Type Description
    Dictionary<String, List<Slider>>

    _readySliderTicks

    Pooled Slider Ticks that are ready to be reused.

    Declaration
    protected readonly List<SliderTick> _readySliderTicks
    Field Value
    Type Description
    List<SliderTick>

    _screenAdjust

    Declaration
    [SerializeField]
    [Tooltip("Used for offsetting where SDF Curves show on-screen.")]
    protected RectTransform _screenAdjust
    Field Value
    Type Description
    RectTransform

    _sdfCurveCamera

    Declaration
    [SerializeField]
    [Tooltip("Used for figuring out the ortho scale of the Camera, which is needed in order to display SDF Curves at the correct size (SDF Curve works best when displayed by a camera in orthographic mode).")]
    protected Camera _sdfCurveCamera
    Field Value
    Type Description
    Camera

    _sdfCurveContainer

    Declaration
    [Header("SDF Curve")]
    [SerializeField]
    [Tooltip("Where the instantiated SDF Curves will be parented to.")]
    protected Transform _sdfCurveContainer
    Field Value
    Type Description
    Transform

    _settings

    Declaration
    [SerializeField]
    [Tooltip("Other values used for tweaking Hit Objects and effects.")]
    protected HitObjectManagerSettings _settings
    Field Value
    Type Description
    HitObjectManagerSettings

    _sliderByIndex

    Allows getting any currently used Slider instance based on their index. Key is index, value is Slider.

    Declaration
    protected readonly Dictionary<int, ISlider> _sliderByIndex
    Field Value
    Type Description
    Dictionary<Int32, ISlider>

    _sounds

    Declaration
    [SerializeField]
    [Tooltip("Contains all hit/miss sound effects that we need.")]
    protected SoundEffectSet _sounds
    Field Value
    Type Description
    SoundEffectSet

    _viewCameraForBall

    Declaration
    [Header("Slider Ball")]
    [SerializeField]
    [Tooltip("Used for figuring out the distance between the mouse cursor and the Slider Ball.")]
    protected Camera _viewCameraForBall
    Field Value
    Type Description
    Camera

    WhiteColour

    Declaration
    protected static readonly Gradient WhiteColour
    Field Value
    Type Description
    Gradient

    Properties

    GetHitObjectSizeCalculatorType

    If we have an IHitObjectSizeCalculator callback registered, this is its type.

    Declaration
    public Type GetHitObjectSizeCalculatorType { get; }
    Property Value
    Type Description
    Type

    HasHitObjectSizeCalculator

    Whether we have an IHitObjectSizeCalculator callback registered.

    Declaration
    public bool HasHitObjectSizeCalculator { get; }
    Property Value
    Type Description
    Boolean

    Methods

    AddToPool<T>(Dictionary<String, List<T>>, String, T)

    Used for assigning values to the _allHitCircles, _readyHitCircles, _allSliders, and _readySliders. Basically all Dictionaries that have a poolId for its key.

    Declaration
    protected static void AddToPool<T>(Dictionary<string, List<T>> pool, string id, T o)
    Parameters
    Type Name Description
    Dictionary<String, List<T>> pool
    String id
    T o
    Type Parameters
    Name Description
    T

    CleanUp()

    Despawn all currently used instances. Used when player chooses to restart the beatmap.

    Declaration
    public virtual void CleanUp()

    CycleColour(Int32)

    Go to the next colour in the list. This assigns a new value to _currentComboColourIdx.

    Declaration
    protected virtual void CycleColour(int times)
    Parameters
    Type Name Description
    Int32 times

    Despawn(HitCircle)

    Mark a Hit Circle as now completely used up, so that it is ready to be re-used later on.

    Declaration
    public virtual void Despawn(HitCircle hitCircle)
    Parameters
    Type Name Description
    HitCircle hitCircle

    Despawn(Slider)

    Mark a Slider as now completely used up, so that it is ready to be re-used later on.

    Declaration
    public virtual void Despawn(Slider slider)
    Parameters
    Type Name Description
    Slider slider

    DespawnSliderTick(SliderTick)

    Mark a Slider Tick as now completely used up, so that it is ready to be re-used later on.

    Declaration
    public virtual void DespawnSliderTick(SliderTick sliderTick)
    Parameters
    Type Name Description
    SliderTick sliderTick

    GetAppropriateBorderColour()

    Gets the proper current colour for the border of the next Slider.

    Declaration
    protected virtual Color32 GetAppropriateBorderColour()
    Returns
    Type Description
    Color32

    GetAppropriateHitObjectColour()

    Gets the proper current Gradient to be used for the next Hit Object.

    Declaration
    protected virtual Gradient GetAppropriateHitObjectColour()
    Returns
    Type Description
    Gradient

    GetAppropriateSliderBallColour()

    Gets the proper current colour for the SliderBall once it goes through the next Slider.

    Declaration
    protected virtual Color32 GetAppropriateSliderBallColour()
    Returns
    Type Description
    Color32

    GetHitObjectByName(String)

    Get a reference to a currently used Hit Object based on the GameObject name.

    Declaration
    public virtual IHitObjectWithEvents GetHitObjectByName(string gameObjectName)
    Parameters
    Type Name Description
    String gameObjectName
    Returns
    Type Description
    IHitObjectWithEvents
    Remarks

    This is used when a Hit Object was clicked on, to get the Hit Object instance without having to use GetComponent<T>().

    GetSliderByIndex(Int32)

    Get a reference to a Slider based on its index.

    Declaration
    public virtual ISlider GetSliderByIndex(int idx)
    Parameters
    Type Name Description
    Int32 idx
    Returns
    Type Description
    ISlider

    OnHit(IHitObject, Single, Int32)

    Spawns effects and/or plays hit sound for when user successfully hit a Hit Circle.

    Declaration
    public virtual void OnHit(IHitObject hitObject, float result, int score)
    Parameters
    Type Name Description
    IHitObject hitObject

    The Hit Circle that was hit.

    Single result

    Normalized value indicating if user pressed within correct time window. -1 to +1 is a hit. Any value outside that (lesser than -1 or greater than +1) means miss (negative for too early, positive for too late). 0 means user pressed exactly at hit circle's time.

    Int32 score

    score given for this particular pressed hit circle

    OnHitOutOfSequence(IHitObject, String)

    Spawns effects and/or plays error sound meant for when user tries to hit a hit object that isn't supposed to be hit yet (e.g. trying to hit 2 when 1 hasn't been hit yet).

    Declaration
    public virtual void OnHitOutOfSequence(IHitObject hitObject, string effectsId = null)
    Parameters
    Type Name Description
    IHitObject hitObject

    Used for figuring out where to position the visual effects and what colour to give it, if any.

    String effectsId

    Optional. Identifier for the visual/sound effect you want to be played. Leave at null to use defaults.

    OnHitSliderEnd(IHitObject, SliderReachType, Boolean, Boolean, Int32, Int32, Int32, Boolean)

    Spawns effects and/or plays hit sound for when user successfully keeps holding mouse down on the slider ball once it has finished going through a slider.

    Declaration
    public virtual void OnHitSliderEnd(IHitObject slider, SliderReachType reachType, bool reachedEnd, bool userHit, int headScore = -1, int partsPressed = -1, int partsTotal = -1, bool wasReleased = true)
    Parameters
    Type Name Description
    IHitObject slider

    The slider whose tail was hit.

    SliderReachType reachType

    Whether the ball has reached the Slider's tail or head.

    Boolean reachedEnd

    True: ball has reached the end of movement for this Slider, there are no more repeats. False: Ball will repeat movement on this slider.

    Boolean userHit

    Whether mouse was pressed down and near enough the ball at the moment.

    Int32 headScore

    Determines whether player did a perfect press on the Slider head (start cap) or not.

    Int32 partsPressed

    Number of Slider parts that the player successfully hit (head, ticks, tail).

    Int32 partsTotal

    Number of parts that the Slider has (head, ticks, tail).

    Boolean wasReleased

    Did user ever release the mouse button when the slider was pressed?

    OnHitSliderStart(IHitObject)

    Spawns effects and/or plays hit sound for when user successfully hits Slider Head at the start of the Slider time.

    Declaration
    public virtual void OnHitSliderStart(IHitObject slider)
    Parameters
    Type Name Description
    IHitObject slider

    OnHitSliderTick(SliderTick, Boolean)

    Called when Slider Ball reached a Slider Tick so that it can be removed and play the corresponding hit sound.

    Declaration
    public virtual void OnHitSliderTick(SliderTick sliderTick, bool didUserHitTick)
    Parameters
    Type Name Description
    SliderTick sliderTick
    Boolean didUserHitTick

    OnHitTooEarly(IHitObject)

    Spawns effects and/or plays error sound meant for when user tries to hit a hit object that was supposed to be hit, but it's not yet time to hit it.

    Declaration
    public virtual void OnHitTooEarly(IHitObject hitObject)
    Parameters
    Type Name Description
    IHitObject hitObject

    OnHitTooLate(IHitObject)

    Spawns effects and/or plays error sound meant for when user tries to hit a hit object that was supposed to be hit, but whose time is already up.

    Declaration
    public virtual void OnHitTooLate(IHitObject hitObject)
    Parameters
    Type Name Description
    IHitObject hitObject

    OnHitWrong(IHitObject, String)

    Spawns effects and/or plays error sound meant for when user tries to hit a hit object but is somehow not allowed.

    Declaration
    public virtual void OnHitWrong(IHitObject hitObject, string effectsId = null)
    Parameters
    Type Name Description
    IHitObject hitObject

    Used for figuring out where to position the visual effects and what colour to give it, if any.

    String effectsId

    Optional. Identifier for the visual/sound effect you want to be played. Leave at null to use defaults.

    OnMiss(IHitObject)

    Spawns effects and/or plays sound for when user missed a Hit Object.

    Declaration
    public virtual void OnMiss(IHitObject hitObject)
    Parameters
    Type Name Description
    IHitObject hitObject

    RecalculateDisplayedHitObjectSize()

    Recalculate the size of currently displayed Hit Objects.

    Declaration
    public virtual void RecalculateDisplayedHitObjectSize()

    SetBeatmap(Beatmap)

    Assign the beatmap data to use. This is used in case the Beatmap has colours specified to use, this is also where we get Hit Object size, or to provide beatmap data for _hitObjectSizeCalculator.

    Declaration
    public virtual void SetBeatmap(Beatmap newBeatmap)
    Parameters
    Type Name Description
    OsuParsers.Beatmaps.Beatmap newBeatmap

    SetColours(BeatmapColoursSection)

    Get colour data specified in the Beatmap.

    Declaration
    public virtual void SetColours(BeatmapColoursSection newColours)
    Parameters
    Type Name Description
    OsuParsers.Beatmaps.Sections.BeatmapColoursSection newColours

    SetHitObjectSizeCalculator(IHitObjectSizeCalculator)

    Assign the custom Hit Object Size Calculator, this is used to provide instantiated Hit Objects with what their size should be.

    Declaration
    public void SetHitObjectSizeCalculator(IHitObjectSizeCalculator newHitObjectSizeCalculator)
    Parameters
    Type Name Description
    IHitObjectSizeCalculator newHitObjectSizeCalculator

    SetInput(IBeatmapInput)

    Assign the custom Input callback, this is used to let instantiated SliderBalls know how their distance from the mouse cursor.

    Declaration
    public void SetInput(IBeatmapInput newBeatmapInput)
    Parameters
    Type Name Description
    IBeatmapInput newBeatmapInput

    Spawn(BeatmapRunner, Double, Int32, Int32, HitCircle, Single, Single, Single, Beatmap)

    Spawn a Hit Circle with the specified position, colour, etc. This will re-use existing instances when possible.

    Declaration
    public virtual void Spawn(BeatmapRunner beatmapRunner, double beatLength, int offsetToComboIdx, int idx, HitCircle hitCircle, float positionScale, float approachStartDelay, float approachRateDuration, Beatmap beatmap)
    Parameters
    Type Name Description
    BeatmapRunner beatmapRunner

    Needed by the Hit Circle so it can report to the game when player pressed that Hit Circle. This also lets the Hit Circle know if the player pressed too early or not, and how much score the player got.

    Double beatLength

    Duration of a beat, in milliseconds.

    Int32 offsetToComboIdx

    Skip combo index so this Hit Circle can be at a specific colour. Hit Circles already have a ComboOffset from their data in osu, but this can be used to add even more offset.

    Int32 idx

    Numerical position of the Hit Circle in the entire Beatmap.

    OsuParsers.Beatmaps.Objects.HitCircle hitCircle

    More data on this Hit Circle.

    Single positionScale

    How far from the center of the screen this Hit Circle should be placed. This is a multiplier so 2.0 will place this twice as far from the center of the screen. Set to 1.0 if you do not want any scaling.

    Single approachStartDelay
    Single approachRateDuration

    How long it will take for the Approach Circle to do its shrinking animation.

    OsuParsers.Beatmaps.Beatmap beatmap

    Data on the entire Beatmap.

    Spawn(IBeatmapRunner, Double, Int32, Int32, Slider, Single, Single, Beatmap)

    Spawn a Slider with the specified position, colour, etc. This will re-use existing instances when possible.

    Declaration
    public virtual void Spawn(IBeatmapRunner beatmapRunner, double beatLength, int offsetToComboIdx, int idx, Slider slider, float positionScale, float approachRateDuration, Beatmap beatmap)
    Parameters
    Type Name Description
    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.

    Double beatLength

    Duration of a beat, in milliseconds.

    Int32 offsetToComboIdx

    Skip combo index so this Slider can be at a specific colour. Sliders already have a ComboOffset from their data in osu, but this can be used to add even more offset.

    Int32 idx

    Numerical position of the Slider in the entire Beatmap.

    OsuParsers.Beatmaps.Objects.Slider slider

    More data on this Slider.

    Single positionScale

    How far from the center of the screen this Slider should be placed. This is a multiplier so 2.0 will place this twice as far from the center of the screen. Set to 1.0 if you do not want any scaling.

    Single approachRateDuration

    How long it will take for the Approach Circle to do its shrinking animation.

    OsuParsers.Beatmaps.Beatmap beatmap

    Data on the entire Beatmap.

    SpawnSDFCurve(Slider, Single, Single, Gradient, Color)

    Used by Sliders to spawn the SDF Curve for it.

    Declaration
    public virtual SDFCurve SpawnSDFCurve(Slider slider, float radius, float sliderSizeMultiplier, Gradient colour, Color borderColour)
    Parameters
    Type Name Description
    OsuParsers.Beatmaps.Objects.Slider slider

    Slider that this SDF Curve will be for

    Single radius

    The radius that the Slider has, based on OsuParsers.Beatmaps.Sections.BeatmapDifficultySection.CircleSize.

    Single sliderSizeMultiplier

    Multiplier to the size provided by the Slider.

    Gradient colour

    Gradient colour for the curve

    Color borderColour

    Colour for the curve's border

    Returns
    Type Description
    SDFCurve

    SpawnSDFCurve(Slider, Single, Single, Color, Color, Color)

    Declaration
    protected virtual SDFCurve SpawnSDFCurve(Slider slider, float radius, float sliderSizeMultiplier, Color gradientInnerColor, Color gradientOuterColor, Color borderColor)
    Parameters
    Type Name Description
    OsuParsers.Beatmaps.Objects.Slider slider
    Single radius
    Single sliderSizeMultiplier
    Color gradientInnerColor
    Color gradientOuterColor
    Color borderColor
    Returns
    Type Description
    SDFCurve

    SpawnSliderTick(Vector2, Color32)

    Spawn a Slider Tick at the specified position. This will re-use existing instances when possible.

    Declaration
    public virtual SliderTick SpawnSliderTick(Vector2 pos, Color32 colour)
    Parameters
    Type Name Description
    Vector2 pos

    Position that the Slider Tick will be in.

    Color32 colour

    Colour that the Slider Tick will be in.

    Returns
    Type Description
    SliderTick

    UpdateCombo(Int32, Int32, HitObject)

    Updates _currentComboCounter to the next number. Updates _currentComboColourIdx to a new value by cycling through the list of colours.

    Declaration
    protected virtual void UpdateCombo(int idx, int offsetToComboIdx, HitObject hitObject)
    Parameters
    Type Name Description
    Int32 idx
    Int32 offsetToComboIdx

    Skip combo index so this Hit Circle can be at a specific colour. Hit Circles already have a ComboOffset from their data in osu, but this can be used to add even more offset.

    OsuParsers.Beatmaps.Objects.HitObject hitObject

    Extension Methods

    Util.SetLayerDeep(Component, LayerMask)
    Util.SetLayerDeep(Component, Int32)
    Util.SetLayerDeep(Component, LayerMask, Stack<Transform>)