// 本脚本只在不存在时会生成一次。已存在不会再次生成覆盖 using System; using System.Collections.Generic; using FairyGUI; using UnityEngine; using NBC; using UIPanel = NBC.UIPanel; namespace NBF { public partial class PlayerPanel : UIPanel { private int TryGetTime = 5; protected override void OnShowed() { this.AutoAddClick(OnClick); TryGetTime = 5; Progress.max = 1; } protected override void OnInit() { 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 Nmsl() { 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) { return; // 第一个不允许滑动至上一个 } 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) { 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; } private void OnClick(GComponent btn) { // if (btn == BtnNext) // { // // VideoManager.Instance.Next(); // } // else if (btn == BtnPrev) // { // // VideoManager.Instance.Previous(); // } } } }