1
This commit is contained in:
22
Unity/Scripts/UX/VideoPlayer/BITKit.UX.VideoPlayer.asmdef
Normal file
22
Unity/Scripts/UX/VideoPlayer/BITKit.UX.VideoPlayer.asmdef
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "BITKit.UX.VideoPlayer",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:14fe60d984bf9f84eac55c6ea033a8f4",
|
||||
"GUID:a209c53514018594f9f482516f2a6781",
|
||||
"GUID:6ef4ed8ff60a7aa4bb60a8030e6f4008",
|
||||
"GUID:2bafac87e7f4b9b418d9448d219b01ab",
|
||||
"GUID:4ca929d456ec44c4d8a918a37f3b70f3",
|
||||
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||
"GUID:be17a8778dbfe454890ed8279279e153"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
144
Unity/Scripts/UX/VideoPlayer/UXVideoPlayer.cs
Normal file
144
Unity/Scripts/UX/VideoPlayer/UXVideoPlayer.cs
Normal file
@@ -0,0 +1,144 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Video;
|
||||
using BITKit;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine.UIElements;
|
||||
using Cysharp.Threading.Tasks;
|
||||
namespace BITKit.UX
|
||||
{
|
||||
public class UXVideoPlayer : UXElement<VisualElement>, IProvider<VideoClip>
|
||||
{
|
||||
const string _minimizeContainer = "minimize-container";
|
||||
const string _maximizeContainer = "maximize-container";
|
||||
const string _closeButton = "close-button";
|
||||
const string _maximizeButton = "maximize-button";
|
||||
const string _minimizeButton = "minimize-button";
|
||||
const string _videoName = "videoName-label";
|
||||
const string _playerSlider = "player-slider";
|
||||
const string _playButton = "play-button";
|
||||
const string _totalTimeLabel = "totalTime-label";
|
||||
const string _currentTimeLabel = "currentTime-label";
|
||||
[Header(Constant.Header.Settings)]
|
||||
public bool isMaximize;
|
||||
public bool log;
|
||||
public bool autoPlay;
|
||||
[Header(Constant.Header.Components)]
|
||||
public BITKit.Media.VideoPlayer videoPlayer;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
Vector2 windowPosition;
|
||||
VisualElement minimizeContainer;
|
||||
VisualElement maximizeContainer;
|
||||
|
||||
public void Play(VideoClip clip)
|
||||
{
|
||||
videoPlayer.Stop();
|
||||
Set(clip);
|
||||
videoPlayer.player.Prepare();
|
||||
videoPlayer.player.time = 0;
|
||||
if (autoPlay)
|
||||
{
|
||||
videoPlayer.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
videoPlayer.Prepare();
|
||||
}
|
||||
foreach (var x in visualElement.Query<Label>(_videoName).ToList())
|
||||
{
|
||||
x.text = clip.name;
|
||||
}
|
||||
SetActive(true);
|
||||
if (isMaximize)
|
||||
{
|
||||
Maximize();
|
||||
}
|
||||
else
|
||||
{
|
||||
Minimize();
|
||||
}
|
||||
}
|
||||
public override void OnStart()
|
||||
{
|
||||
document.sortingOrder = 8;
|
||||
base.OnStart();
|
||||
|
||||
minimizeContainer = visualElement.Q(_minimizeContainer);
|
||||
maximizeContainer = visualElement.Q(_maximizeContainer);
|
||||
|
||||
foreach (var x in visualElement.Query<Button>(_minimizeButton).ToList())
|
||||
{
|
||||
x.clicked += Minimize;
|
||||
}
|
||||
foreach (var x in visualElement.Query<Button>(_maximizeButton).ToList())
|
||||
{
|
||||
x.clicked += Maximize;
|
||||
}
|
||||
foreach (var x in visualElement.Query<Button>(_closeButton).ToList())
|
||||
{
|
||||
x.clicked += Close;
|
||||
}
|
||||
|
||||
foreach (var x in visualElement.Query<Button>(_playButton).ToList())
|
||||
{
|
||||
videoPlayer.onPlay.AddListener(SwitchToPlaying);
|
||||
videoPlayer.onStartPlay.AddListener(SwitchToPlaying);
|
||||
videoPlayer.onPause.AddListener(SwitchToStop);
|
||||
videoPlayer.onStopPlay.AddListener(SwitchToStop);
|
||||
x.clicked += videoPlayer.PlayOrPause;
|
||||
void SwitchToPlaying()
|
||||
{
|
||||
x.AddToClassList("paused");
|
||||
|
||||
}
|
||||
void SwitchToStop()
|
||||
{
|
||||
x.RemoveFromClassList("paused");
|
||||
}
|
||||
}
|
||||
foreach (var x in visualElement.Query<Slider>(_playerSlider).ToList())
|
||||
{
|
||||
x.RegisterValueChangedCallback(x =>
|
||||
{
|
||||
videoPlayer.SetNormalizeTime(x.newValue);
|
||||
});
|
||||
videoPlayer.onTime.AddListener(x.SetValueWithoutNotify);
|
||||
videoPlayer.onStopPlay.AddListener(() => x.SetValueWithoutNotify(0));
|
||||
}
|
||||
foreach (var x in visualElement.Query<Label>(_totalTimeLabel).ToList())
|
||||
{
|
||||
videoPlayer.onSetTotalTimeAsString.AddListener(y => x.text = y);
|
||||
}
|
||||
foreach (var x in visualElement.Query<Label>(_currentTimeLabel).ToList())
|
||||
{
|
||||
videoPlayer.onTimeAsString.AddListener(y => x.text = y);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
VideoClip IProvider<VideoClip>.Get()
|
||||
{
|
||||
return videoPlayer.player.clip;
|
||||
}
|
||||
public void Set(VideoClip t)
|
||||
{
|
||||
videoPlayer.player.clip = t;
|
||||
}
|
||||
void Close()
|
||||
{
|
||||
videoPlayer.Stop();
|
||||
SetActive(false);
|
||||
}
|
||||
void Minimize()
|
||||
{
|
||||
minimizeContainer.SetActive(true);
|
||||
maximizeContainer.SetActive(false);
|
||||
}
|
||||
void Maximize()
|
||||
{
|
||||
minimizeContainer.SetActive(false);
|
||||
maximizeContainer.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user