namespace UIWidgets.Examples
{
using System;
using UnityEngine;
///
/// Splitter Slider.
///
public class SplitterSlider : MonoBehaviour
{
///
/// Left filler.
///
[SerializeField]
protected RectTransform LeftFiller;
///
/// Right filler.
///
[SerializeField]
protected RectTransform RightFiller;
///
/// Track range.
///
[SerializeField]
protected RectTransform TrackRange;
///
/// Audio clip.
///
[SerializeField]
public AudioClip Track;
///
/// Length of the rects.
///
/// The length.
protected float RectLength()
{
return LeftFiller.rect.width + RightFiller.rect.width + TrackRange.rect.width;
}
///
/// Gets the start of the track in samples.
///
/// The start of the track in samples.
public int GetTrackStart()
{
return Mathf.RoundToInt(LeftFiller.rect.width / RectLength() * Track.samples);
}
///
/// Gets the start of track in seconds.
///
/// The track start in seconds.
public int GetTrackStartInSeconds()
{
return Mathf.RoundToInt(LeftFiller.rect.width / RectLength() * Track.length);
}
///
/// Gets the length of the track in samples.
///
/// The length of the track in samples.
public int GetTrackLength()
{
return Mathf.RoundToInt(TrackRange.rect.width / RectLength() * Track.samples);
}
///
/// Gets the length of the track in seconds.
///
/// The length of the track in seconds.
public int GetTrackLengthInSeconds()
{
return Mathf.RoundToInt(TrackRange.rect.width / RectLength() * Track.length);
}
///
/// Gets the end of the track in samples.
///
/// The end of the track in samples.
public int GetTrackEnd()
{
return Mathf.RoundToInt((LeftFiller.rect.width + TrackRange.rect.width) / RectLength() * Track.samples);
}
///
/// Gets the end of the track in seconds.
///
/// The end of the track in seconds.
public int GetTrackEndInSeconds()
{
return Mathf.RoundToInt((LeftFiller.rect.width + TrackRange.rect.width) / RectLength() * Track.length);
}
///
/// Test this instance.
///
public void Test()
{
Debug.Log(string.Format("Start: {0} samples; {1} seconds", GetTrackStart().ToString(), GetTrackStartInSeconds().ToString()));
Debug.Log(string.Format("Length: {0} samples; {1} seconds", GetTrackLength().ToString(), GetTrackLengthInSeconds().ToString()));
Debug.Log(string.Format("End: {0} samples; {1} seconds", GetTrackEnd().ToString(), GetTrackEndInSeconds().ToString()));
}
}
}