BITKit/Src/Unity/Scripts/UX/Player/UXPlayer.cs

54 lines
1.3 KiB
C#
Raw Normal View History

2024-05-31 01:23:15 +08:00
using System.Collections;
using System.Collections.Generic;
using BITKit;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UIElements;
namespace BITKit.UX
{
public class UXPlayer : MonoBehaviour
{
[SerializeReference, SubclassSelector] private IReference rootPath;
[SerializeField] private UnityEvent<float> onSetTime;
private Slider _playSlider;
private Label _currentLabel;
private Label _totalLabel;
private Button _playButton;
private VisualElement _container;
private void Start()
{
_container = GetComponent<UIDocument>().rootVisualElement.Q(rootPath.Value);
_playSlider = _container.Q<Slider>("play-slider");
_currentLabel = _container.Q<Label>("current-label");
_totalLabel = _container.Q<Label>("total-label");
_playButton = _container.Q<Button>("play-button");
_playSlider.RegisterValueChangedCallback(evt =>
{
onSetTime.Invoke(evt.newValue);
});
}
public void SetProgress(float time)
{
_playSlider.SetValueWithoutNotify(time);
}
public void SetTime(string time)
{
_currentLabel.text = time;
}
public void SetTotalTime(string time)
{
_totalLabel.text = time;
}
public void SetPlaying(bool isPlaying)
{
_playButton.EnableInClassList("playing",isPlaying);
}
public void SetActive(bool active)
{
_container.SetActive(active);
}
}
}