This commit is contained in:
2026-02-12 22:15:15 +08:00
parent 47a5cff08b
commit 502c6efedc
58 changed files with 2114 additions and 708 deletions

View File

@@ -1,5 +1,7 @@
// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖
using System;
using System.Collections.Generic;
using FairyGUI;
using UnityEngine;
using NBC;
@@ -16,45 +18,138 @@ namespace NBF
this.AutoAddClick(OnClick);
TryGetTime = 5;
Progress.max = 1;
GetVideoData();
stageCtrl.selectedIndex = 0;
}
private void GetVideoData()
protected override void OnInit()
{
Game.Instance.GetList(OnGetList);
SwipeGesture gesture = new SwipeGesture(BtnPause);
gesture.onBegin.Set(OnSwipeBegin);
gesture.onMove.Set(OnSwipeMove);
gesture.onEnd.Set(OnSwipeEnd);
gesture.onAction.Add(OnSwipeGesture);
Game.Instance.PreLoadNextData(Nmsl);
// ResetPlayerPos();
}
private void OnGetList()
private void Nmsl()
{
if (Game.Instance.Videos.Count > 0)
Play(0);
}
#region UI组件管理
// private void ResetPlayerPos()
// {
// for (int i = 0; i < _videoPlayers.Count; i++)
// {
// var player = _videoPlayers[i];
// player.y = BtnPause.height * (i - 1);
// player.x = 0;
// player.size = BtnPause.size;
// }
// }
#endregion
#region
// private int _tryTime = 1;
// private int _lastPlayValue;
private int _nowIndex = 0;
public void Play(int value = 0)
{
var nowIndex = _nowIndex + value;
VideoTop.PlayVideo(nowIndex - 1, VideoPlayMode.Top);
VideoBottom.PlayVideo(nowIndex + 1, VideoPlayMode.Bottom);
Video.PlayVideo(nowIndex, VideoPlayMode.Mid);
_nowIndex = nowIndex;
Video.height = BtnPause.height;
VideoTop.height = BtnPause.height;
VideoBottom.height = BtnPause.height;
VideoManager.Instance.ReturnPlayer(_nowIndex);
}
#endregion
#region
private float _defY = 0;
private float _offsetValue;
private void OnSwipeBegin(EventContext context)
{
_offsetValue = 0;
}
private void OnSwipeMove(EventContext context)
{
// if (IsLoading) return;
var gesture = context.sender as SwipeGesture;
if (gesture == null) return;
_offsetValue += gesture.delta.y;
if (_nowIndex == 0 && _offsetValue > 0)
{
stageCtrl.selectedIndex = 1;
return; // 第一个不允许滑动至上一个
}
else
Video.y = _defY + _offsetValue;
}
private void OnSwipeEnd(EventContext context)
{
Video.y = _defY;
}
private void OnSwipeGesture(EventContext context)
{
// if (IsLoading) return;
SwipeGesture swipeGesture = (SwipeGesture)context.sender;
var value = Math.Abs(_offsetValue);
if (value < 300)
{
Notices.Show($"没有视频数据!{TryGetTime}秒后重试");
Timer.Once(TryGetTime, this, GetVideoData);
TryGetTime *= 2;
return;
}
if (swipeGesture.position.y < 0) //向上滑动
{
Log.Info($"向上滑动 切换下一个视频 _offsetValue={_offsetValue} y={swipeGesture.position.y}");
if (Game.Instance.IsLastVideo(_nowIndex))
{
Game.Instance.PreLoadNextData();
return;
}
Play(1);
}
else if (_nowIndex > 0)
{
Log.Info($"向下滑动 切换上一个视频 _offsetValue={_offsetValue} y={swipeGesture.position.y}");
Play(-1);
}
}
#endregion
protected override void OnUpdate()
{
base.OnUpdate();
Progress.value = VideoManager.Instance.PlayProgress;
// Progress.value = VideoManager.Instance.PlayProgress;
}
private void OnClick(GComponent btn)
{
if (btn == BtnNext)
{
VideoManager.Instance.Next();
}
else if (btn == BtnPrev)
{
VideoManager.Instance.Previous();
}
// if (btn == BtnNext)
// {
// // VideoManager.Instance.Next();
// }
// else if (btn == BtnPrev)
// {
// // VideoManager.Instance.Previous();
// }
}
}
}