Files
peng-zhihui 06ec2e469e Released.
2022-03-13 06:31:07 +08:00

68 lines
1.3 KiB
C#

namespace UIWidgets.Examples
{
using UIWidgets;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Determinate ProgressBar sample.
/// </summary>
[RequireComponent(typeof(Button))]
public class SampleProgressBar2 : MonoBehaviour
{
/// <summary>
/// Progressbar.
/// </summary>
[SerializeField]
public ProgressbarDeterminateBase Bar;
Button button;
/// <summary>
/// Adds listeners.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
protected virtual void Start()
{
button = GetComponent<Button>();
if (button != null)
{
button.onClick.AddListener(Click);
}
}
/// <summary>
/// Toggle animation.
/// </summary>
protected virtual void Click()
{
if (Bar.IsAnimationRunning)
{
Bar.Stop();
}
else
{
if (Bar.Value == 0)
{
Bar.Animate(Bar.Max);
}
else
{
Bar.Animate(0);
}
}
}
/// <summary>
/// Remove listener.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
protected virtual void OnDestroy()
{
if (button != null)
{
button.onClick.RemoveListener(Click);
}
}
}
}