AR文件更新流程&AR网络延时问题
This commit is contained in:
parent
16cd2fd26b
commit
74ba5790f9
194
Assets/AR/ARDownloader.cs
Normal file
194
Assets/AR/ARDownloader.cs
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Assets.Scenes.Ride.Scripts;
|
||||||
|
using Assets.Scripts.Apis.Models;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
namespace Assets.AR
|
||||||
|
{
|
||||||
|
public class ARDownloader
|
||||||
|
{
|
||||||
|
private MapRoute _route;
|
||||||
|
|
||||||
|
private readonly string _localARDataPath;
|
||||||
|
private readonly string _localARRoutePath;
|
||||||
|
private readonly string _localVideoPath;
|
||||||
|
private readonly string _serverARDataPath;
|
||||||
|
private readonly string _serverARRoutePath;
|
||||||
|
private readonly string _serverVideoPath;
|
||||||
|
|
||||||
|
public bool IsVideoDownloaded { get; private set; }
|
||||||
|
public bool IsARDataDownloaded { get; private set; }
|
||||||
|
public bool IsARRouteDownloaded { get; private set; }
|
||||||
|
public float Total { get; private set; } = 0;
|
||||||
|
|
||||||
|
public ARDownloader(MapRoute route)
|
||||||
|
{
|
||||||
|
this._route = route;
|
||||||
|
|
||||||
|
var dataPath = $"{PFConstants.ARFolder}/{_route.Id}";
|
||||||
|
var path = PFConstants.VideoFolder;
|
||||||
|
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||||
|
|
||||||
|
_localARDataPath = $"{dataPath}/{_route.Id}.json";
|
||||||
|
_localARRoutePath = $"{dataPath}/route-{_route.Id}.json";
|
||||||
|
_localVideoPath = $"{path}/{_route.FileName}";
|
||||||
|
|
||||||
|
_serverARDataPath = _route.ARConfig;
|
||||||
|
_serverARRoutePath = _route.VideoRoute;
|
||||||
|
_serverVideoPath = _route.Url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTask<UnityWebRequest> DownLoadVideoAsync(IProgress<float> progress = null,
|
||||||
|
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
return await DownloadToFileAsync(_serverVideoPath, _localVideoPath, progress, cancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTask<UnityWebRequest> DownLoadARRouteAsync(IProgress<float> progress = null,
|
||||||
|
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
return await DownloadToFileAsync(_serverARRoutePath, _localARRoutePath, progress, cancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async UniTask<UnityWebRequest> DownLoadARDataAsync(IProgress<float> progress = null,
|
||||||
|
CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
return await DownloadToFileAsync(_serverARDataPath, _localARDataPath, progress, cancellation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> CheckAllAsync()
|
||||||
|
{
|
||||||
|
IsARRouteDownloaded = await CheckARRouteAsync();
|
||||||
|
IsARDataDownloaded = await CheckARDataAsync();
|
||||||
|
IsVideoDownloaded = await CheckVideoAsync();
|
||||||
|
|
||||||
|
if (IsVideoDownloaded)
|
||||||
|
Total += 1f;
|
||||||
|
if (IsARRouteDownloaded)
|
||||||
|
Total += 1f;
|
||||||
|
if (IsARDataDownloaded)
|
||||||
|
Total += 1f;
|
||||||
|
|
||||||
|
return IsVideoDownloaded || IsARRouteDownloaded || IsARDataDownloaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// return true if the video is needed to download
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> CheckVideoAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (!File.Exists(_localVideoPath)) return true;
|
||||||
|
var result = await HeadFileAsync(_serverVideoPath, _localVideoPath);
|
||||||
|
return result.responseCode != 304;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// return true if the video is needed to download
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> CheckARRouteAsync()
|
||||||
|
{
|
||||||
|
if (!File.Exists(_localARRoutePath)) return true;
|
||||||
|
var result = await HeadFileAsync(_serverARRoutePath, _localARRoutePath);
|
||||||
|
return result.responseCode != 304;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// return true if the video is needed to download
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<bool> CheckARDataAsync()
|
||||||
|
{
|
||||||
|
if (!File.Exists(_localARDataPath)) return true;
|
||||||
|
var result = await HeadFileAsync(_serverARDataPath, _localARDataPath);
|
||||||
|
return result.responseCode != 304;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载文件到本地(持续存入磁盘减少内存占用)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="downloadUrl">文件连接</param>
|
||||||
|
/// <param name="fullPath">本地文件全路径</param>
|
||||||
|
/// <param name="progress">下载进度</param>
|
||||||
|
public static async UniTask<UnityWebRequest> DownloadToFileAsync(string downloadUrl, string fullPath,
|
||||||
|
IProgress<float> progress = null, CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
var dh = new DownloadHandlerFile(fullPath)
|
||||||
|
{
|
||||||
|
removeFileOnAbort = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = UnityWebRequest.Get(downloadUrl);
|
||||||
|
request.downloadHandler = dh;
|
||||||
|
request.method = UnityWebRequest.kHttpVerbGET;
|
||||||
|
|
||||||
|
var result = await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update,
|
||||||
|
(cancellation?.Token ?? default(CancellationToken)));
|
||||||
|
|
||||||
|
var etag = result.GetResponseHeader("ETag");
|
||||||
|
var path = fullPath + ".etag";
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
File.Create(path);
|
||||||
|
}
|
||||||
|
File.WriteAllText(path, etag);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// head request for file meta info such as etag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="downloadUrl">download url</param>
|
||||||
|
/// <param name="fullPath">local path for storage</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async UniTask<UnityWebRequest> HeadFileAsync(string downloadUrl, string fullPath,
|
||||||
|
IProgress<float> progress = null, CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var etagFile = fullPath + ".etag";
|
||||||
|
var etag = string.Empty;
|
||||||
|
if (File.Exists(etagFile))
|
||||||
|
{
|
||||||
|
etag = File.ReadAllText(etagFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = UnityWebRequest.Head(downloadUrl);
|
||||||
|
if (!string.IsNullOrEmpty(etag))
|
||||||
|
request.SetRequestHeader("If-None-Match", etag);
|
||||||
|
|
||||||
|
var result =
|
||||||
|
await request
|
||||||
|
.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update,
|
||||||
|
(cancellation?.Token ?? default(CancellationToken)));
|
||||||
|
|
||||||
|
if (result.responseCode != 304)
|
||||||
|
{
|
||||||
|
etag = result.GetResponseHeader("ETag");
|
||||||
|
File.WriteAllText(fullPath + ".etag", etag);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Assets/AR/ARDownloader.cs.meta
Normal file
3
Assets/AR/ARDownloader.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 84a219eba2114884a2e246578ade9ab9
|
||||||
|
timeCreated: 1684373675
|
||||||
@ -39,13 +39,16 @@ namespace Assets.AR
|
|||||||
|
|
||||||
public int TestPower { get; set; }
|
public int TestPower { get; set; }
|
||||||
|
|
||||||
public float ZOffset { get; set; }
|
protected void Start()
|
||||||
|
{
|
||||||
|
this.Lane = route.Lane;//轨迹上的距离
|
||||||
|
}
|
||||||
|
|
||||||
//重置碰撞检测参数
|
//重置碰撞检测参数
|
||||||
public void ResetCollisionDetectionParameters()
|
public void ResetCollisionDetectionParameters()
|
||||||
{
|
{
|
||||||
this.StartPosition = 0;//开始位置
|
this.StartPosition = 0;//开始位置
|
||||||
this.Lane = 0.0f;//轨迹上的距离
|
this.Lane = route.Lane;//轨迹上的距离
|
||||||
this.DeltaLane = 0.0f;//差距
|
this.DeltaLane = 0.0f;//差距
|
||||||
this.LaneWidth = 0.0f;//轨迹宽度
|
this.LaneWidth = 0.0f;//轨迹宽度
|
||||||
this.LaneCamera = 0.0f;//轨迹上摄像头的位置
|
this.LaneCamera = 0.0f;//轨迹上摄像头的位置
|
||||||
@ -59,10 +62,10 @@ namespace Assets.AR
|
|||||||
{
|
{
|
||||||
PositionOffset = Vector3.up * route.CameraHeight * (-1);
|
PositionOffset = Vector3.up * route.CameraHeight * (-1);
|
||||||
var cameraRotation = this.GetCameraRotation(this.frame - this.FrameIndexDistanceCorrection);
|
var cameraRotation = this.GetCameraRotation(this.frame - this.FrameIndexDistanceCorrection);
|
||||||
var normalizeCameraRotation = Quaternion.Euler(new Vector3(cameraRotation.eulerAngles.x, cameraRotation.eulerAngles.y, cameraRotation.eulerAngles.z+ZOffset));
|
var normalizeCameraRotation = Quaternion.Euler(new Vector3(cameraRotation.eulerAngles.x+route.CameraRotationsOffset.x, cameraRotation.eulerAngles.y+route.CameraRotationsOffset.y, cameraRotation.eulerAngles.z+route.CameraRotationsOffset.z));
|
||||||
|
|
||||||
var filteredCameraPosition = this.GetFilteredCameraPosition(this.frame - this.FrameIndexDistanceCorrection);
|
var filteredCameraPosition = this.GetFilteredCameraPosition(this.frame - this.FrameIndexDistanceCorrection);
|
||||||
var vector3 = Vector3.left * (this.route.LeftHanded ? -1f : 1f) * (this.LaneWidth * (this.Lane + this.LaneCamera) - this.BaseOffset);
|
var vector3 = Vector3.left * (this.route.LeftHanded ? -1f : 1f) * (this.LaneWidth * (this.Lane + this.LaneCamera + this.route.Lane) - this.BaseOffset);
|
||||||
var targetPos = filteredCameraPosition + normalizeCameraRotation * (vector3 + this.PositionOffset);
|
var targetPos = filteredCameraPosition + normalizeCameraRotation * (vector3 + this.PositionOffset);
|
||||||
|
|
||||||
this.transform.position = targetPos;
|
this.transform.position = targetPos;
|
||||||
|
|||||||
@ -8,7 +8,7 @@ namespace Assets.AR
|
|||||||
{
|
{
|
||||||
protected const float LaneWidth = 0.7f;
|
protected const float LaneWidth = 0.7f;
|
||||||
protected const float StartRegionDistance = 200f;
|
protected const float StartRegionDistance = 200f;
|
||||||
private const float StartRowsGap = 2.2f;
|
private const float StartRowsGap = 1.0f;
|
||||||
private const float StartRowsRandomDistance = 0.4f;
|
private const float StartRowsRandomDistance = 0.4f;
|
||||||
private const float StartRowsRandomWidth = 0.15f;
|
private const float StartRowsRandomWidth = 0.15f;
|
||||||
private const float MinCollisionDistance = 1.33f;
|
private const float MinCollisionDistance = 1.33f;
|
||||||
@ -34,7 +34,7 @@ namespace Assets.AR
|
|||||||
{
|
{
|
||||||
var frame = 100f;
|
var frame = 100f;
|
||||||
this.StartRegionRouteWidth = this.GetRouteLeftOffset(frame) + this.GetRouteRightOffset(frame);
|
this.StartRegionRouteWidth = this.GetRouteLeftOffset(frame) + this.GetRouteRightOffset(frame);
|
||||||
this.RiderCountInStartRow = Mathf.Max(2, Mathf.CeilToInt(this.StartRegionRouteWidth / 0.7f));
|
this.RiderCountInStartRow = Mathf.Max(1, Mathf.CeilToInt(this.StartRegionRouteWidth / LaneWidth));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateGameObjects(
|
protected override void UpdateGameObjects(
|
||||||
@ -96,9 +96,9 @@ namespace Assets.AR
|
|||||||
this.CalculateOvertakingParameters();
|
this.CalculateOvertakingParameters();
|
||||||
foreach (ARLaneGameObject collision in this.collisionList)
|
foreach (ARLaneGameObject collision in this.collisionList)
|
||||||
{
|
{
|
||||||
collision.LaneWidth = 0.7f;
|
collision.LaneWidth = LaneWidth;
|
||||||
var num6 = this.Route.LeftHanded ? this.GetRouteLeftOffset(collision.Frame) : this.GetRouteRightOffset(collision.Frame);
|
var num6 = this.Route.LeftHanded ? this.GetRouteLeftOffset(collision.Frame) : this.GetRouteRightOffset(collision.Frame);
|
||||||
var num7 = Mathf.Lerp(this.GetStartOffset(collision.StartPosition).x, 0.0f, collision.Distance / 200f);
|
var num7 = Mathf.Lerp(this.GetStartOffset(collision.StartPosition).x, 0.0f, collision.Distance / StartRegionDistance);
|
||||||
collision.BaseOffset = num6 + num7;
|
collision.BaseOffset = num6 + num7;
|
||||||
}
|
}
|
||||||
this.CalculateCameraAvoidance(cameraDistance);
|
this.CalculateCameraAvoidance(cameraDistance);
|
||||||
@ -224,22 +224,19 @@ namespace Assets.AR
|
|||||||
Vector2 startOffset;
|
Vector2 startOffset;
|
||||||
if (this.randomizedStartOffsets.TryGetValue(atIndex, out startOffset))
|
if (this.randomizedStartOffsets.TryGetValue(atIndex, out startOffset))
|
||||||
return startOffset;
|
return startOffset;
|
||||||
startOffset = new Vector2(UnityEngine.Random.Range(-0.15f, 0.15f), UnityEngine.Random.Range(-0.4f, 0.4f));
|
startOffset = new Vector2(UnityEngine.Random.Range(-StartRowsRandomWidth, StartRowsRandomWidth), UnityEngine.Random.Range(-StartRowsRandomDistance,StartRowsRandomDistance));
|
||||||
this.randomizedStartOffsets.Add(atIndex, startOffset);
|
this.randomizedStartOffsets.Add(atIndex, startOffset);
|
||||||
return startOffset;
|
return startOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetRouteDistance(int startPosition, float routeDistance)
|
public float GetRouteDistance(int startPosition, float routeDistance)
|
||||||
{
|
{
|
||||||
if (!this.AllowStartOrder || (double)routeDistance >= 200.0)
|
if (!this.AllowStartOrder || (double)routeDistance >= StartRegionDistance)
|
||||||
return routeDistance;
|
return routeDistance;
|
||||||
var start = (float)((RiderCountInStartRow == 0 ? 0 : (startPosition - 1) / this.RiderCountInStartRow) * 2.2000000476837158 + 6.0) + this.GetStartOffset(startPosition).y;
|
float num = Mathf.Lerp((float) ((double) ((startPosition - 1) / this.RiderCountInStartRow) * StartRowsGap + 6.0) + this.GetStartOffset(startPosition).y, 0.0f, routeDistance / StartRegionDistance);
|
||||||
var num = Mathf.Lerp(start , 0.0f, routeDistance / 200f);
|
|
||||||
return routeDistance + num;
|
return routeDistance + num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//计算碰撞距离
|
//计算碰撞距离
|
||||||
protected static float GetCollisionParameter(
|
protected static float GetCollisionParameter(
|
||||||
float distSource,
|
float distSource,
|
||||||
|
|||||||
@ -59,8 +59,6 @@ namespace Assets.AR
|
|||||||
public int VideoFrameOffset { get; set; }
|
public int VideoFrameOffset { get; set; }
|
||||||
|
|
||||||
public float CameraHeight { get; set; }
|
public float CameraHeight { get; set; }
|
||||||
|
|
||||||
public float ZOffset { get; set; }
|
|
||||||
|
|
||||||
public float RiderScale { get; set; } = 1f;
|
public float RiderScale { get; set; } = 1f;
|
||||||
|
|
||||||
@ -73,10 +71,15 @@ namespace Assets.AR
|
|||||||
public int FrameCount => this.CameraPositions.Length;
|
public int FrameCount => this.CameraPositions.Length;
|
||||||
|
|
||||||
public double Lenght => this.FrameDistances[this.FrameCount - 1];
|
public double Lenght => this.FrameDistances[this.FrameCount - 1];
|
||||||
|
|
||||||
|
public VectorData CameraRotationsOffset { get; set; }
|
||||||
|
|
||||||
|
public float Lane { get; set; }
|
||||||
|
|
||||||
private float DefaultLeftSideOffset => !this.LeftHanded ? 4f : 0.0f;
|
private float DefaultLeftSideOffset => !this.LeftHanded ? 4f : 0.0f;
|
||||||
|
|
||||||
private float DefaultRightSideOffset => !this.LeftHanded ? 0.0f : 4f;
|
private float DefaultRightSideOffset => !this.LeftHanded ? 0.0f : 4f;
|
||||||
|
|
||||||
|
|
||||||
public int GetVisibilityAt(int frame)
|
public int GetVisibilityAt(int frame)
|
||||||
{
|
{
|
||||||
@ -431,17 +434,9 @@ namespace Assets.AR
|
|||||||
|
|
||||||
public void LoadData(ARRouteData data)
|
public void LoadData(ARRouteData data)
|
||||||
{
|
{
|
||||||
// //todo:修改rotation z
|
|
||||||
// foreach (var rotation in data.CameraRotations)
|
|
||||||
// {
|
|
||||||
// rotation.z += 4f;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var str = JsonConvert.SerializeObject(data);
|
|
||||||
this.Visibility = data.Visibility;
|
this.Visibility = data.Visibility;
|
||||||
this.VideoFrameOffset = data.VideoFrameOffset;
|
this.VideoFrameOffset = data.VideoFrameOffset;
|
||||||
this.LeftHanded = data.LeftHanded;
|
this.LeftHanded = data.LeftHanded;
|
||||||
this.ZOffset = data.Zoffset;
|
|
||||||
this.SlamSegments = data.SlamSegments;
|
this.SlamSegments = data.SlamSegments;
|
||||||
this.CameraHeight = data.CameraHeight;
|
this.CameraHeight = data.CameraHeight;
|
||||||
this.RiderScale = (double)data.RiderScale != 0.0 ? data.RiderScale : 1f;
|
this.RiderScale = (double)data.RiderScale != 0.0 ? data.RiderScale : 1f;
|
||||||
@ -454,6 +449,8 @@ namespace Assets.AR
|
|||||||
this.LeftSideOffsets = data.LeftSideOffsets;
|
this.LeftSideOffsets = data.LeftSideOffsets;
|
||||||
this.RightSideOffsetFrames = data.RightSideOffsetFrames;
|
this.RightSideOffsetFrames = data.RightSideOffsetFrames;
|
||||||
this.RightSideOffsets = data.RightSideOffsets;
|
this.RightSideOffsets = data.RightSideOffsets;
|
||||||
|
this.CameraRotationsOffset = data.CameraRotationsOffset;
|
||||||
|
this.Lane = data.Lane;
|
||||||
if (data.LightRotationFrames == null || data.LightRotationFrames.Length == 0)
|
if (data.LightRotationFrames == null || data.LightRotationFrames.Length == 0)
|
||||||
{
|
{
|
||||||
this.LightRotationFrames = new float[0];
|
this.LightRotationFrames = new float[0];
|
||||||
|
|||||||
@ -248,11 +248,12 @@ namespace Assets.AR
|
|||||||
public int VideoFrameOffsetMac = -1;
|
public int VideoFrameOffsetMac = -1;
|
||||||
public float CameraHeight;
|
public float CameraHeight;
|
||||||
public float RiderScale = 1f;
|
public float RiderScale = 1f;
|
||||||
public float Zoffset = 0f;
|
|
||||||
public int[] LeftSideOffsetFrames;
|
public int[] LeftSideOffsetFrames;
|
||||||
public float[] LeftSideOffsets;
|
public float[] LeftSideOffsets;
|
||||||
public int[] RightSideOffsetFrames;
|
public int[] RightSideOffsetFrames;
|
||||||
public float[] RightSideOffsets;
|
public float[] RightSideOffsets;
|
||||||
|
public VectorData CameraRotationsOffset;
|
||||||
|
public float Lane;
|
||||||
}
|
}
|
||||||
public class VectorData
|
public class VectorData
|
||||||
{
|
{
|
||||||
|
|||||||
@ -91,17 +91,10 @@ namespace Assets.AR
|
|||||||
}
|
}
|
||||||
private string LastAnimatorState { get; set; }
|
private string LastAnimatorState { get; set; }
|
||||||
|
|
||||||
protected override void Start()
|
|
||||||
{
|
|
||||||
base.Start();
|
|
||||||
SetZOffset();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
protected override void Update()
|
||||||
{
|
{
|
||||||
if (this.route == null)
|
if (this.route == null)
|
||||||
return;
|
return;
|
||||||
SetMainRiderLane();
|
|
||||||
base.Update();
|
base.Update();
|
||||||
var num = this.Speed;
|
var num = this.Speed;
|
||||||
this.Paused = this.Speed == 0;
|
this.Paused = this.Speed == 0;
|
||||||
@ -168,24 +161,6 @@ namespace Assets.AR
|
|||||||
this.lastVisibilitylevel = this.VisibilityLevel;
|
this.lastVisibilitylevel = this.VisibilityLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetZOffset()
|
|
||||||
{
|
|
||||||
var manager = FindObjectOfType<VideoGameManager>();
|
|
||||||
var map = manager.GetMapRoute();
|
|
||||||
this.ZOffset = map.Id == 6296 ? -4f : 0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SetMainRiderLane()
|
|
||||||
{
|
|
||||||
if (IsMain)
|
|
||||||
{
|
|
||||||
var manager = FindObjectOfType<VideoGameManager>();
|
|
||||||
var map = manager.GetMapRoute();
|
|
||||||
if(map.Id == 6296)//TODO:这里写死溧阳AR骑行
|
|
||||||
Lane = -2f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FixedUpdate()
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
//if (this.Paused || (double)this.Speed <= 0.0)
|
//if (this.Paused || (double)this.Speed <= 0.0)
|
||||||
|
|||||||
@ -213,7 +213,8 @@ public static class App
|
|||||||
{
|
{
|
||||||
InitLanguage();
|
InitLanguage();
|
||||||
#if !UNITY_EDITOR
|
#if !UNITY_EDITOR
|
||||||
Host = "http://pf.juze.pro/";
|
Host = "http://192.168.0.98:6662/";
|
||||||
|
//Host = "http://pf.juze.pro/";
|
||||||
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21000);
|
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21000);
|
||||||
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001);
|
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001);
|
||||||
//线上
|
//线上
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
@ -14,13 +13,12 @@ using Assets.Scenes.Ride.Scripts.Model;
|
|||||||
using Assets.AR;
|
using Assets.AR;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
|
||||||
namespace Assets.Scripts.Scenes.VideoRide
|
namespace Assets.Scripts.Scenes.VideoRide
|
||||||
{
|
{
|
||||||
public class VideoLoading : MonoBehaviour, IProgress<float>
|
public class VideoLoading : MonoBehaviour
|
||||||
{
|
{
|
||||||
VideoGameManager manager { get; set; }
|
|
||||||
|
|
||||||
private Text mapName;
|
private Text mapName;
|
||||||
private RawImage mapRouteImage;
|
private RawImage mapRouteImage;
|
||||||
private CanvasGroup canvasGroup;
|
private CanvasGroup canvasGroup;
|
||||||
@ -35,26 +33,27 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
private Text slope;
|
private Text slope;
|
||||||
private GameObject panel;
|
private GameObject panel;
|
||||||
private GameObject download;
|
private GameObject download;
|
||||||
private GameObject watch;
|
private GameObject watch ;
|
||||||
|
protected GameObject loadingPanel;
|
||||||
protected GameObject loadingPanel { get; set; }
|
|
||||||
|
|
||||||
private Text level;
|
private Text level;
|
||||||
private Text rideNum;
|
private Text rideNum;
|
||||||
private Text uploadByUserName;
|
private Text uploadByUserName;
|
||||||
private RawImage head;
|
private RawImage head;
|
||||||
private RawImage country;
|
private RawImage country;
|
||||||
private RawImage mapCountry;
|
private RawImage mapCountry;
|
||||||
private RawImage altitudeGraph { get; set; }
|
private RawImage altitudeGraph;
|
||||||
private Transform mapRanking;
|
private Transform mapRanking;
|
||||||
private Text mapId;
|
private Text mapId;
|
||||||
private Text downloadText { get; set; }
|
private Text downloadText;
|
||||||
private Transform ui;
|
private Transform ui;
|
||||||
private MapRoute route;
|
|
||||||
|
|
||||||
protected float process = 0;//0-100 %
|
|
||||||
|
|
||||||
|
private VideoGameManager manager { get; set; }
|
||||||
|
private MapRoute route;
|
||||||
|
private ARDownloader downloader;
|
||||||
|
private CancellationTokenSource cancelToken { get; set; }
|
||||||
private bool startBtnLock = false;
|
private bool startBtnLock = false;
|
||||||
|
private bool downloading = false;
|
||||||
|
private float total = 1f;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@ -104,31 +103,12 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
processText.text = $"{(f).ToString("#0")}%";
|
processText.text = $"{(f).ToString("#0")}%";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
download = transform.Find("Panel/Download").gameObject;
|
download = transform.Find("Panel/Download").gameObject;
|
||||||
watch = transform.Find("Panel/Watch").gameObject;
|
watch = transform.Find("Panel/Watch").gameObject;
|
||||||
|
|
||||||
UIManager.AddEvent(watch, UnityEngine.EventSystems.EventTriggerType.PointerClick, WatchHandler);
|
UIManager.AddEvent(watch, UnityEngine.EventSystems.EventTriggerType.PointerClick, WatchHandler);
|
||||||
canvasGroup = transform.GetComponent<CanvasGroup>();
|
canvasGroup = transform.GetComponent<CanvasGroup>();
|
||||||
|
|
||||||
var fileName = route.FileName;// "12067924_720p.mp4";
|
|
||||||
var url = route.Url; //@"http://192.168.0.97:6031/12067924_720p.mp4";
|
|
||||||
var path = PFConstants.VideoFolder;
|
|
||||||
var filepath = path + "/" + fileName;
|
|
||||||
|
|
||||||
if (File.Exists(filepath))
|
|
||||||
{
|
|
||||||
watch.SetActive(true);
|
|
||||||
slider.value = 100;
|
|
||||||
download.gameObject.SetActive(false);
|
|
||||||
manager.SetMedia(filepath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
watch.SetActive(false);
|
|
||||||
//检查本地文件是否存在 如果存在直接设置mediaPlayer 否则显示下载按钮
|
|
||||||
UIManager.AddEvent(download.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, DownloadAsync);
|
|
||||||
}
|
|
||||||
#region
|
#region
|
||||||
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
level = panel.transform.Find("level/Text").GetComponent<Text>();
|
||||||
rideNum = panel.transform.Find("RideNum").GetComponent<Text>();
|
rideNum = panel.transform.Find("RideNum").GetComponent<Text>();
|
||||||
@ -177,9 +157,35 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
{
|
{
|
||||||
panel.transform.Find("RideTip").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
panel.transform.Find("RideTip").GetComponent<CanvasGroup>().DOFade(0, 0.5f);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
UIManager.AddEvent(download.gameObject, EventTriggerType.PointerClick, DownloadAsync);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
downloadText = rideNow.GetComponentInChildren<Text>();//视频下载进度text
|
||||||
|
|
||||||
|
CheckUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void CheckUpdate()
|
||||||
|
{
|
||||||
|
downloader = new ARDownloader(route);
|
||||||
|
var showDownload = await downloader.CheckAllAsync();
|
||||||
|
var isContinue = App.routeResult != null;
|
||||||
|
|
||||||
|
watch.SetActive(!showDownload && !isContinue);
|
||||||
|
download.gameObject.SetActive(showDownload);
|
||||||
|
|
||||||
|
if (!showDownload)
|
||||||
|
{
|
||||||
|
InitializeVideo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeVideo()
|
||||||
|
{
|
||||||
|
var path = PFConstants.VideoFolder + "/" + route.FileName;
|
||||||
|
slider.value = 100;
|
||||||
|
manager.SetMedia(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void InitGameObjectData()
|
protected void InitGameObjectData()
|
||||||
@ -267,18 +273,14 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
},false,true);
|
},false,true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool downloading = false;
|
|
||||||
private CancellationTokenSource cancelToken;
|
|
||||||
private async void DownloadAsync(BaseEventData baseEvent)
|
private async void DownloadAsync(BaseEventData baseEvent)
|
||||||
{
|
{
|
||||||
if (downloading)
|
if (downloading) return;
|
||||||
return;
|
ResetDownload();
|
||||||
|
await StartDownloading();
|
||||||
beforeDownload();
|
|
||||||
await startDownloading();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beforeDownload()
|
private void ResetDownload()
|
||||||
{
|
{
|
||||||
downloading = true;
|
downloading = true;
|
||||||
download.SetActive(false);
|
download.SetActive(false);
|
||||||
@ -287,45 +289,47 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
downloadText.text = "0%";
|
downloadText.text = "0%";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task startDownloading()
|
private async Task StartDownloading()
|
||||||
{
|
{
|
||||||
var route = manager.mapRoute;
|
slider.maxValue = downloader.Total * 100;
|
||||||
var path = PFConstants.VideoFolder;
|
if(downloader.IsVideoDownloaded)
|
||||||
|
await downloader.DownLoadVideoAsync(Progress.Create<float>(HandleProgress));
|
||||||
|
if(downloader.IsARRouteDownloaded)
|
||||||
|
await downloader.DownLoadARRouteAsync(Progress.Create<float>(HandleProgress));
|
||||||
|
if(downloader.IsARDataDownloaded)
|
||||||
|
await downloader.DownLoadARDataAsync(Progress.Create<float>(HandleProgress));
|
||||||
|
|
||||||
var localPath = PFConstants.ARFolder;
|
//cancelToken = new CancellationTokenSource();
|
||||||
var arDataPath = route.ARConfig;
|
//CompleteDownLoad();
|
||||||
var videoRoute = route.VideoRoute;
|
|
||||||
var dataPath = $"{localPath}/{route.Id}";
|
|
||||||
|
|
||||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
|
||||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
|
||||||
|
|
||||||
cancelToken = new CancellationTokenSource();
|
|
||||||
|
|
||||||
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
|
|
||||||
await Loom.DownloadToFileAsync(videoRoute, $"{dataPath}/route-{route.Id}.json");
|
|
||||||
var res = await Loom.DownloadToFileAsync(route.Url, $"{path}/{route.FileName}",this,cancelToken);
|
|
||||||
if (res.isDone)
|
|
||||||
{
|
|
||||||
var filepath = $"{PFConstants.VideoFolder}/{route.FileName}";
|
|
||||||
manager.SetMedia(filepath);
|
|
||||||
|
|
||||||
rideNow.enabled = true;
|
|
||||||
rideNow.interactable = true;
|
|
||||||
|
|
||||||
downloadText.text = App.GetLocalString("Ride Now");
|
|
||||||
downloading = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Report(float value)
|
private void HandleProgress(float value)
|
||||||
{
|
{
|
||||||
if (cancelToken.IsCancellationRequested)
|
if (cancelToken != null && cancelToken.IsCancellationRequested)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
slider.value += (float)Math.Round(value * 100, 0);
|
||||||
|
Debug.Log(value);
|
||||||
|
|
||||||
slider.value = value < 1 ? (float)Math.Round(value * 100, 0) : 100;
|
var progress = slider.value / slider.maxValue * 100;
|
||||||
downloadText.text = slider.value.ToString(CultureInfo.InvariantCulture) + "%";
|
downloadText.text = progress.ToString(CultureInfo.InvariantCulture) + "%";
|
||||||
|
|
||||||
|
var isComplete = slider.value == slider.maxValue;
|
||||||
|
if (isComplete)
|
||||||
|
CompleteDownLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CompleteDownLoad()
|
||||||
|
{
|
||||||
|
var filepath = $"{PFConstants.VideoFolder}/{route.FileName}";
|
||||||
|
manager.SetMedia(filepath);
|
||||||
|
watch.GetComponent<Button>().enabled = true;
|
||||||
|
rideNow.enabled = true;
|
||||||
|
rideNow.interactable = true;
|
||||||
|
downloadText.text = App.GetLocalString("Ride Now");
|
||||||
|
downloading = false;
|
||||||
|
}
|
||||||
|
|
||||||
//进入观察模式
|
//进入观察模式
|
||||||
private void WatchHandler(BaseEventData data)
|
private void WatchHandler(BaseEventData data)
|
||||||
{
|
{
|
||||||
@ -360,20 +364,27 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
CancelDownload();
|
||||||
UIManager.ShowConfirm("Tips", "CancelDownloadConfirm",
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
cancelToken?.Cancel();
|
|
||||||
SceneManager.LoadSceneAsync("MainScene");
|
|
||||||
UIManager.CloseConfirm();
|
|
||||||
},
|
|
||||||
2,
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
UIManager.CloseConfirm();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void CancelDownload()
|
||||||
|
{
|
||||||
|
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
|
||||||
|
|
||||||
|
UIManager.ShowConfirm("Tips", "CancelDownloadConfirm",
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
cancelToken?.Cancel();
|
||||||
|
SceneManager.LoadSceneAsync("MainScene");
|
||||||
|
UIManager.CloseConfirm();
|
||||||
|
},
|
||||||
|
2,
|
||||||
|
() =>
|
||||||
|
{
|
||||||
|
UIManager.CloseConfirm();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async void DrawMapRouteAsync(int routeId, int type = 0)
|
private async void DrawMapRouteAsync(int routeId, int type = 0)
|
||||||
{
|
{
|
||||||
var result = await ConfigHelper.mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
var result = await ConfigHelper.mapApi.GetMapLoadingCoverageUrl(routeId, type);
|
||||||
@ -391,6 +402,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
Utils.DisplayImageAysnc(StartCoroutine, mapRouteImage, url, DowloadCallBack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DowloadCallBack(string url, RawImage rawImage)
|
private void DowloadCallBack(string url, RawImage rawImage)
|
||||||
{
|
{
|
||||||
if (!App.TextureCache.ContainsKey(url))
|
if (!App.TextureCache.ContainsKey(url))
|
||||||
|
|||||||
@ -68,7 +68,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
if (manager != null)
|
if (manager != null && manager.GetMapRoute() != null)
|
||||||
{
|
{
|
||||||
mapName.text = manager.GetMapRoute().Name;
|
mapName.text = manager.GetMapRoute().Name;
|
||||||
if (manager.CurrentPlayer != null)
|
if (manager.CurrentPlayer != null)
|
||||||
|
|||||||
@ -62,7 +62,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
public GameObject videoPlayer;
|
public GameObject videoPlayer;
|
||||||
public GameObject target;
|
public GameObject target;
|
||||||
public int CurrentUserId { get; set; }
|
public int CurrentUserId { get; set; }
|
||||||
|
|
||||||
|
|
||||||
protected override void Awake()
|
protected override void Awake()
|
||||||
{
|
{
|
||||||
@ -119,34 +118,49 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
yield return null;
|
yield return null;
|
||||||
videoLoading.Init();//初始化loading页面
|
videoLoading.Init();//初始化loading页面
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update()
|
private float tcpTimer = 0f;
|
||||||
|
private void FixedUpdate()
|
||||||
{
|
{
|
||||||
timer -= Time.deltaTime;
|
if (cyclingController == null)
|
||||||
while (timer <= 0)
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (cyclingController == null)
|
timer -= Time.deltaTime;
|
||||||
return;
|
tcpTimer -= Time.deltaTime;
|
||||||
|
while (timer <= 0)
|
||||||
try
|
|
||||||
{
|
{
|
||||||
cyclingController.Run(null);//发送数据到tcp
|
TickTimer();
|
||||||
|
|
||||||
var onlineRiders = cyclingController.riders;
|
|
||||||
CreateOnlineUser(onlineRiders); //解析tcp返回数据
|
|
||||||
|
|
||||||
if (isStart)
|
|
||||||
{
|
|
||||||
ComputePlayerRuntimeData();
|
|
||||||
ticks++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
|
while (tcpTimer <= 0)
|
||||||
{
|
{
|
||||||
Debug.Log(e.Message);
|
MillTimer();
|
||||||
}
|
}
|
||||||
timer += 1f;
|
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log(e.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TickTimer()
|
||||||
|
{
|
||||||
|
if (isStart)
|
||||||
|
{
|
||||||
|
ComputePlayerRuntimeData();
|
||||||
|
ticks++;
|
||||||
|
}
|
||||||
|
timer +=1f;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MillTimer()
|
||||||
|
{
|
||||||
|
cyclingController.Run(null);//发送数据到tcp
|
||||||
|
var onlineRiders = cyclingController.riders;
|
||||||
|
CreateOnlineUser(onlineRiders); //解析tcp返回数据
|
||||||
|
tcpTimer += 0.2f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//计算骑手的数据
|
//计算骑手的数据
|
||||||
@ -302,7 +316,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
//移除退出的选手
|
//移除退出的选手
|
||||||
private void RemovePlayers(List<BaseRider> list)
|
private void RemovePlayers(List<BaseRider> list)
|
||||||
{
|
{
|
||||||
|
|
||||||
var players = FindObjectsOfType<OnlineVideoPlayer>();
|
var players = FindObjectsOfType<OnlineVideoPlayer>();
|
||||||
foreach (var item in players)
|
foreach (var item in players)
|
||||||
{
|
{
|
||||||
@ -371,10 +384,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
//开始游戏
|
//开始游戏
|
||||||
public void StartGame()
|
public void StartGame()
|
||||||
{
|
{
|
||||||
//if (startTime != DateTime.MinValue)
|
startTime = UIManager.Now.GetDateTime();
|
||||||
{
|
|
||||||
startTime = UIManager.Now.GetDateTime();
|
|
||||||
}
|
|
||||||
isStart = true;
|
isStart = true;
|
||||||
}
|
}
|
||||||
//骑行是否开始
|
//骑行是否开始
|
||||||
@ -445,7 +455,6 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
}
|
}
|
||||||
return mapRoute;
|
return mapRoute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void ShowUpRemainTime(double remain)
|
public void ShowUpRemainTime(double remain)
|
||||||
{
|
{
|
||||||
@ -477,18 +486,22 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
|
|
||||||
RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction<BaseEventData> unityAction)
|
||||||
{
|
{
|
||||||
UIManager.AddEvent(sender, eventType, unityAction);
|
UIManager.AddEvent(sender, eventType, unityAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetCountryImageByCode(string code)
|
public Texture GetCountryImageByCode(string code)
|
||||||
{
|
{
|
||||||
return UIManager.Instance.loginRegOptions.GetCountryImage(code);
|
return UIManager.Instance.loginRegOptions.GetCountryImage(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetCountryImageByName(string name)
|
public Texture GetCountryImageByName(string name)
|
||||||
{
|
{
|
||||||
return UIManager.Instance.loginRegOptions.GetCountryImageByName(name);
|
return UIManager.Instance.loginRegOptions.GetCountryImageByName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2d Along(double endDistance)
|
public Vector2d Along(double endDistance)
|
||||||
{
|
{
|
||||||
if (mapData != null)
|
if (mapData != null)
|
||||||
@ -504,6 +517,7 @@ namespace Assets.Scripts.Scenes.VideoRide
|
|||||||
return new Vector2d(0, 0);
|
return new Vector2d(0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
App.gameRoomDetail = null;
|
App.gameRoomDetail = null;
|
||||||
|
|||||||
@ -17,48 +17,55 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
//private readonly MapWorkoutService service = new MapWorkoutService();
|
//private readonly MapWorkoutService service = new MapWorkoutService();
|
||||||
|
|
||||||
public UserResultModel CurrentUser { get; set; }
|
public UserResultModel CurrentUser { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属人ID
|
/// 所属人ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int BelongUserId
|
public int BelongUserId
|
||||||
{
|
{
|
||||||
get
|
get { return App.CurrentUser.Id; }
|
||||||
{
|
|
||||||
return App.CurrentUser.Id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 记录是否完毕
|
/// 记录是否完毕
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsCompleted { get; set; }
|
public bool IsCompleted { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否需要计算排名
|
/// 是否需要计算排名
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsNeedRanking { get; set; }
|
public bool IsNeedRanking { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 骑行记录索引(用于中断骑行,继续骑行)
|
/// 骑行记录索引(用于中断骑行,继续骑行)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ContinueIndex { get; set; }
|
public int ContinueIndex { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 骑行状态
|
/// 骑行状态
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public CyclingStateEnum CyclingState { get; set; }
|
public CyclingStateEnum CyclingState { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 赛事Id
|
/// 赛事Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Competitionid { get; set; }
|
public int Competitionid { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前已经骑行的距离(表示用户现在在的距离,并不是实际骑的距离)
|
/// 当前已经骑行的距离(表示用户现在在的距离,并不是实际骑的距离)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double EndDistance { get; set; }
|
public double EndDistance { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 上次骑行的距离
|
/// 上次骑行的距离
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double PreDistance { get; set; }
|
public double PreDistance { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 继续骑行记录标志
|
/// 继续骑行记录标志
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ContinueMark { get; set; }
|
public string ContinueMark { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 厂商Id
|
/// 厂商Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -67,14 +74,17 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
public string ManufacturerName { get; set; }
|
public string ManufacturerName { get; set; }
|
||||||
|
|
||||||
public int? AntModelId { get; set; }
|
public int? AntModelId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 骑行数据
|
/// 骑行数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<TargetData> RiderDatas = new List<TargetData>();
|
public List<TargetData> RiderDatas = new List<TargetData>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前路线
|
/// 当前路线
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Route CurrentRoute { get; set; }
|
public Route CurrentRoute { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 骑行记录Id
|
/// 骑行记录Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -88,14 +98,17 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
/// 当前给骑行台发送数据的模式
|
/// 当前给骑行台发送数据的模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SendDataMode SendDataMode { get; set; }
|
public SendDataMode SendDataMode { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 临时使用的坡度
|
/// 临时使用的坡度
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double SlopeGrade { get; set; }
|
public double SlopeGrade { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 临时使用的海拔
|
/// 临时使用的海拔
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double Elevation { get; set; }
|
public double Elevation { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前路书开始的距离
|
/// 当前路书开始的距离
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -108,6 +121,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
public int? LastFrame { get; set; }
|
public int? LastFrame { get; set; }
|
||||||
|
|
||||||
public int RoomId { get; set; }
|
public int RoomId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否已经保存成功
|
/// 是否已经保存成功
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -123,25 +137,25 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
|
|
||||||
public RouteResultParam selectParam { get; set; }
|
public RouteResultParam selectParam { get; set; }
|
||||||
|
|
||||||
public int SaveWithLocalRecordAysnc(CyclingModel cyclingModel, RouteResultParam selectParam, string imageName,string recordId,string path)
|
public int SaveWithLocalRecordAysnc(CyclingModel cyclingModel, RouteResultParam selectParam, string imageName,
|
||||||
|
string recordId, string path)
|
||||||
{
|
{
|
||||||
Saved = true;
|
Saved = true;
|
||||||
Dictionary<MapInterruptRecord, List<string>> recordData = new Dictionary<MapInterruptRecord, List<string>>();
|
var recordData = new Dictionary<MapInterruptRecord, List<string>>();
|
||||||
if (RiderDatas.Count <= 0)
|
if (RiderDatas.Count <= 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
string newFileName = Guid.NewGuid().ToString();
|
|
||||||
int FTP = Helper.GetFtp();
|
var newFileName = Guid.NewGuid().ToString();
|
||||||
double NP = Helper.GetNP(RiderDatas);
|
var FTP = Helper.GetFtp();
|
||||||
|
var NP = Helper.GetNP(RiderDatas);
|
||||||
//强度
|
//强度
|
||||||
double IF = NP / FTP;
|
var IF = NP / FTP;
|
||||||
//训练量
|
//训练量
|
||||||
double TSS = (RiderDatas.Count * NP * IF) / (FTP * 3600) * 100;
|
var TSS = (RiderDatas.Count * NP * IF) / (FTP * 3600) * 100;
|
||||||
var averagePower = Helper.AveragePower(RiderDatas);
|
var averagePower = Helper.AveragePower(RiderDatas);
|
||||||
|
|
||||||
// AntManufacturer manufacturer = service.GetAntManufacturer(ManufacturerId).data;
|
|
||||||
//var recordId = Guid.NewGuid().ToString();
|
|
||||||
var ticks = RiderDatas.Last().Ticks;
|
var ticks = RiderDatas.Last().Ticks;
|
||||||
var interruptRecord = new MapInterruptRecord
|
var interruptRecord = new MapInterruptRecord
|
||||||
{
|
{
|
||||||
@ -151,17 +165,15 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
TotalDistance = CurrentRoute.RouteInstance.Distance,
|
TotalDistance = CurrentRoute.RouteInstance.Distance,
|
||||||
UserId = BelongUserId,
|
UserId = BelongUserId,
|
||||||
RecordFileName = newFileName + ".txt",
|
RecordFileName = newFileName + ".txt",
|
||||||
Ftp = FTP,//FTP设置
|
Ftp = FTP,
|
||||||
IF = Math.Round(IF, 2),
|
IF = Math.Round(IF, 2),
|
||||||
Kj = RiderDatas.Sum(a => a._Power) / 1000,//消耗
|
Kj = RiderDatas.Sum(a => a._Power) / 1000, //消耗
|
||||||
Tss = Math.Round(TSS, 2),
|
Tss = Math.Round(TSS, 2),
|
||||||
EndDistance = EndDistance,
|
EndDistance = EndDistance,
|
||||||
IsCompleted = IsCompleted,
|
IsCompleted = IsCompleted,
|
||||||
|
NormalizedPower = Math.Floor(NP), //标准化功率
|
||||||
//TrainingTime = TimeHelper.FormatSeconds(RiderDatas.Last().Ticks),//训练时间
|
AveragePower = averagePower, //平均功率
|
||||||
NormalizedPower = Math.Floor(NP),//标准化功率
|
MaxPower = RiderDatas.Max(a => a._Power), //最大功率
|
||||||
AveragePower = averagePower,//平均功率
|
|
||||||
MaxPower = RiderDatas.Max(a => a._Power),//最大功率
|
|
||||||
WeightKg = Math.Round(averagePower / App.CurrentUser.Weight, 2),
|
WeightKg = Math.Round(averagePower / App.CurrentUser.Weight, 2),
|
||||||
Weight = App.CurrentUser.Weight,
|
Weight = App.CurrentUser.Weight,
|
||||||
BicycleWeight = App.CurrentUser.BicycleWeight,
|
BicycleWeight = App.CurrentUser.BicycleWeight,
|
||||||
@ -169,14 +181,14 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
ContinueIndex = ContinueIndex,
|
ContinueIndex = ContinueIndex,
|
||||||
IsDelete = false,
|
IsDelete = false,
|
||||||
MapCompetitionId = Competitionid,
|
MapCompetitionId = Competitionid,
|
||||||
ManufacturerName = ManufacturerName,//manufacturer == null ? "" : manufacturer.Name,
|
ManufacturerName = ManufacturerName,
|
||||||
DeviceNumber = DeviceNumber,
|
DeviceNumber = DeviceNumber,
|
||||||
IsRanking = IsNeedRanking,
|
IsRanking = IsNeedRanking,
|
||||||
CurrentRouteStartDistance = CurrentRouteStartDistance,
|
CurrentRouteStartDistance = CurrentRouteStartDistance,
|
||||||
ManufacturerId = ManufacturerId,
|
ManufacturerId = ManufacturerId,
|
||||||
AntModelId = AntModelId,
|
AntModelId = AntModelId,
|
||||||
StartTime = StartTime,
|
StartTime = StartTime,
|
||||||
CreateTime = EndTime, //StartTime.AddSeconds(ticks),
|
CreateTime = EndTime,
|
||||||
Ticks = ticks,
|
Ticks = ticks,
|
||||||
Mode = cyclingModel.ToString(),
|
Mode = cyclingModel.ToString(),
|
||||||
Param = Newtonsoft.Json.JsonConvert.SerializeObject(selectParam),
|
Param = Newtonsoft.Json.JsonConvert.SerializeObject(selectParam),
|
||||||
@ -185,10 +197,10 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
LastFrame = LastFrame,
|
LastFrame = LastFrame,
|
||||||
RoomId = RoomId
|
RoomId = RoomId
|
||||||
};
|
};
|
||||||
//var range = new MapSpeedRange().GetSpeedRange(RiderDatas, CurrentRoute.RouteInstance.Distance);
|
|
||||||
interruptRecord.SpeedRange = null; //JsonConvert.SerializeObject(range);
|
|
||||||
|
|
||||||
double process = Math.Round((EndDistance - interruptRecord.CurrentRouteStartDistance) / CurrentRoute.RouteInstance.Distance, 2);
|
interruptRecord.SpeedRange = null;
|
||||||
|
|
||||||
|
var process = Math.Round((EndDistance - interruptRecord.CurrentRouteStartDistance) / CurrentRoute.RouteInstance.Distance, 2);
|
||||||
interruptRecord.Progress = process > 1 ? 1 : process;
|
interruptRecord.Progress = process > 1 ? 1 : process;
|
||||||
|
|
||||||
var cadences = RiderDatas.Where(a => a._Cadence.HasValue && a._Cadence.Value > 0);
|
var cadences = RiderDatas.Where(a => a._Cadence.HasValue && a._Cadence.Value > 0);
|
||||||
@ -196,19 +208,16 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
{
|
{
|
||||||
interruptRecord.AverageCadence = Math.Round(cadences.Average(a => a._Cadence.GetValueOrDefault(0)));
|
interruptRecord.AverageCadence = Math.Round(cadences.Average(a => a._Cadence.GetValueOrDefault(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
interruptRecord.MaxCadence = Math.Round(RiderDatas.Max(a => a._Cadence.GetValueOrDefault(0)));
|
interruptRecord.MaxCadence = Math.Round(RiderDatas.Max(a => a._Cadence.GetValueOrDefault(0)));
|
||||||
interruptRecord.AverageHeartRate = Math.Round(RiderDatas.Average(a => a._HeartRate.GetValueOrDefault(0)));
|
interruptRecord.AverageHeartRate = Math.Round(RiderDatas.Average(a => a._HeartRate.GetValueOrDefault(0)));
|
||||||
interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0));
|
interruptRecord.MaxHeartRate = RiderDatas.Max(a => a._HeartRate.GetValueOrDefault(0));
|
||||||
//service.CreateRecordCyclingData(interruptRecord);
|
|
||||||
//保存骑行记录txt
|
|
||||||
|
|
||||||
//var path = Helper.GetDataDir("MapWorkoutRecords" + "/" + interruptRecord.Id);
|
|
||||||
//var path = PFConstants.MapWorkoutRecordFolder + "/" + interruptRecord.Id;
|
|
||||||
var files = new List<string>();
|
var files = new List<string>();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var fname = path + "/" + newFileName + ".txt";
|
var fileName = path + "/" + newFileName + ".txt";
|
||||||
using (var fs = new FileInfo(fname).OpenWrite())
|
using (var fs = new FileInfo(fileName).OpenWrite())
|
||||||
{
|
{
|
||||||
var stream = new StreamWriter(fs);
|
var stream = new StreamWriter(fs);
|
||||||
stream.BaseStream.Seek(0, SeekOrigin.End);
|
stream.BaseStream.Seek(0, SeekOrigin.End);
|
||||||
@ -218,13 +227,15 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
}
|
}
|
||||||
stream.Flush();
|
stream.Flush();
|
||||||
stream.Close();
|
stream.Close();
|
||||||
files.Add(fname);
|
files.Add(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//图片
|
//图片
|
||||||
if (!string.IsNullOrEmpty(imageName))
|
if (!string.IsNullOrEmpty(imageName))
|
||||||
{
|
{
|
||||||
files.Add(imageName);
|
files.Add(imageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//持久化序列化对象
|
//持久化序列化对象
|
||||||
var recordString = JsonConvert.SerializeObject(interruptRecord);
|
var recordString = JsonConvert.SerializeObject(interruptRecord);
|
||||||
var recordFilePath = path + "/" + "record" + ".txt";
|
var recordFilePath = path + "/" + "record" + ".txt";
|
||||||
@ -235,48 +246,44 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
|||||||
Helper.DelectDir(path);
|
Helper.DelectDir(path);
|
||||||
Debug.Log(ex.Message);
|
Debug.Log(ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
recordData.Add(interruptRecord, files);
|
recordData.Add(interruptRecord, files);
|
||||||
return SaveDataAysnc(recordData, path);
|
return SaveDataAysnc(recordData, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 保存数据
|
/// 保存数据
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="base64Image"></param>
|
/// <param name="base64Image"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int SaveDataAysnc(Dictionary<MapInterruptRecord, List<string>> data,string path)
|
public int SaveDataAysnc(Dictionary<MapInterruptRecord, List<string>> data, string path)
|
||||||
{
|
{
|
||||||
if (data != null && data.Count > 0)
|
if (data == null || data.Count <= 0) return -1;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
//var path = Helper.GetDataDir("MapWorkoutRecords");
|
var record = data.FirstOrDefault();
|
||||||
//Task.Run(() => {
|
var service = new MapInterruptRecordApi();
|
||||||
try
|
var result = service.Add(record.Key, record.Value);
|
||||||
{
|
|
||||||
var record = data.FirstOrDefault();
|
|
||||||
MapInterruptRecordApi service = new MapInterruptRecordApi();
|
|
||||||
var result = service.Add(record.Key, record.Value);
|
|
||||||
|
|
||||||
if (result.result)
|
if (result.result)
|
||||||
|
{
|
||||||
|
if (Directory.Exists(path))
|
||||||
{
|
{
|
||||||
//删除文件
|
Helper.DelectDir(path);
|
||||||
|
|
||||||
if (Directory.Exists(path))
|
|
||||||
{
|
|
||||||
Helper.DelectDir(path);
|
|
||||||
}
|
|
||||||
//});
|
|
||||||
return result.data.RankingId;
|
|
||||||
}
|
}
|
||||||
}
|
return result.data.RankingId;
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.Log(e.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.Log(e.Message);
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public class TempRecordData
|
public class TempRecordData
|
||||||
{
|
{
|
||||||
public int RoomId { get; set; }
|
public int RoomId { get; set; }
|
||||||
|
|||||||
@ -26,6 +26,18 @@ namespace Assets.Scenes.Ride.Scripts
|
|||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static string CreateFileIfNotExsit(string path)
|
||||||
|
{
|
||||||
|
if (!File.Exists(path))
|
||||||
|
{
|
||||||
|
File.CreateText(path);
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public double Distance(Vector2d from, Vector2d to)
|
public double Distance(Vector2d from, Vector2d to)
|
||||||
{
|
{
|
||||||
var pt1 = Turf.Point(new double[] { from.x, from.y });
|
var pt1 = Turf.Point(new double[] { from.x, from.y });
|
||||||
|
|||||||
@ -1,14 +1,6 @@
|
|||||||
using Assets.Scenes.Ride.Scripts;
|
using Cysharp.Threading.Tasks;
|
||||||
using Assets.Scripts;
|
using Assets.AR;
|
||||||
using Assets.Scripts.Apis.Models;
|
using Assets.Core;
|
||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using PolyAndCode.UI;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@ -36,24 +28,49 @@ class GameRoomDownLoad : MonoBehaviour
|
|||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string RouteName { get; set; }
|
public string RouteName { get; set; }
|
||||||
private string FileUrl { get; set; }
|
private string FileUrl { get; set; }
|
||||||
|
|
||||||
|
private float _videoProgress;
|
||||||
|
|
||||||
|
public float VideoProgress
|
||||||
|
{
|
||||||
|
get => _videoProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_videoProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _dataProgress = 0f;
|
||||||
|
public float DataProgress
|
||||||
|
{
|
||||||
|
get => _dataProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_dataProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _routeProgress = 0f;
|
||||||
|
public float RouteProgress
|
||||||
|
{
|
||||||
|
get => _routeProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_routeProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, DownloadClick);
|
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, Download_Click);
|
||||||
UIManager.AddEvent(backBtn, EventTriggerType.PointerClick, CancelClick);
|
UIManager.AddEvent(backBtn, EventTriggerType.PointerClick, CancelClick);
|
||||||
|
|
||||||
UIManager.AddEvent(runInbackBtn, EventTriggerType.PointerClick, (d) =>
|
UIManager.AddEvent(runInbackBtn, EventTriggerType.PointerClick, (d) =>
|
||||||
{
|
{
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
downLoadList.SetActive(true);
|
downLoadList.SetActive(true);
|
||||||
//var content = downLoadList.transform.Find("Viewport/Content");
|
|
||||||
//var list = FindObjectsOfType<GameRoomDownloadTask>();
|
|
||||||
////新增
|
|
||||||
//var obj = list.Where(c => c.RoomId == RoomId).FirstOrDefault();
|
|
||||||
//if (obj == null)
|
|
||||||
//{
|
|
||||||
// var newtask = Instantiate(downLoadTask, content);
|
|
||||||
// newtask.GetComponent<GameRoomDownloadTask>().Init(RoomId, FileName,gameObject);
|
|
||||||
//}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
UIManager.AddEvent(enterBtn, EventTriggerType.PointerClick, (ee) =>
|
UIManager.AddEvent(enterBtn, EventTriggerType.PointerClick, (ee) =>
|
||||||
@ -69,22 +86,17 @@ class GameRoomDownLoad : MonoBehaviour
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private ARDownloader _downloader;
|
||||||
{
|
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName,ARDownloader downloader)
|
||||||
//if (!string.IsNullOrEmpty(FileName) && Loom.DownloadStack.ContainsKey(FileName))
|
|
||||||
//{
|
|
||||||
// processing(Loom.DownloadStack[FileName]);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Init(int Id, string fileName, string url, GameRoomListController gameRoomListController, string routeName)
|
|
||||||
{
|
{
|
||||||
RoomId = Id;
|
RoomId = Id;
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
RouteName = routeName;
|
RouteName = routeName;
|
||||||
FileUrl = url;
|
FileUrl = url;
|
||||||
manager = gameRoomListController;
|
manager = gameRoomListController;
|
||||||
|
_downloader = downloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ComeIntoStep2(string fileName, string routeName)
|
public void ComeIntoStep2(string fileName, string routeName)
|
||||||
{
|
{
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
@ -101,42 +113,47 @@ class GameRoomDownLoad : MonoBehaviour
|
|||||||
step3.SetActive(false);
|
step3.SetActive(false);
|
||||||
downloadSlider.value = 0f;
|
downloadSlider.value = 0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CancelClick(BaseEventData data)
|
private void CancelClick(BaseEventData data)
|
||||||
{
|
{
|
||||||
Reset();
|
Reset();
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
private void processing(float p)
|
|
||||||
{
|
private async void Download_Click(BaseEventData baseEventData)
|
||||||
downloadSlider.value = p;
|
|
||||||
|
|
||||||
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
|
||||||
{
|
|
||||||
Loom.DownloadStack.Add(FileName, new Assets.Core.DownloadInfo(FileName, RouteName, p));
|
|
||||||
}
|
|
||||||
|
|
||||||
Loom.DownloadStack[FileName].Process = p;
|
|
||||||
|
|
||||||
if (p >= 1)
|
|
||||||
{
|
|
||||||
Loom.DownloadStack.Remove(FileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async void DownloadClick(BaseEventData baseEventData)
|
|
||||||
{
|
{
|
||||||
step2.SetActive(true);
|
step2.SetActive(true);
|
||||||
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
step2.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||||
|
|
||||||
var filepath = PFConstants.VideoFolder + "/" + FileName;
|
downloadSlider.maxValue = _downloader.Total * 100;
|
||||||
await Loom.DownloadToFileAsync(FileUrl, filepath, Progress.Create<float>(x => {
|
|
||||||
processing(x);
|
if(_downloader.IsVideoDownloaded)
|
||||||
if (x >= 1)
|
await _downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
|
||||||
{
|
if(_downloader.IsARRouteDownloaded)
|
||||||
downloadSlider.value = 100;
|
await _downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
|
||||||
step3.SetActive(true);
|
if(_downloader.IsARDataDownloaded)
|
||||||
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
await _downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
|
private void ComputeProgress()
|
||||||
|
{
|
||||||
|
//update progress
|
||||||
|
var progress = (_videoProgress + _routeProgress + _dataProgress) / _downloader.Total;
|
||||||
|
downloadSlider.value = progress * 100;
|
||||||
|
|
||||||
|
//update download info
|
||||||
|
if (!Loom.DownloadStack.ContainsKey(FileName) )
|
||||||
|
{
|
||||||
|
Loom.DownloadStack.Add(FileName, new DownloadInfo(FileName, RouteName,progress));
|
||||||
|
}
|
||||||
|
Loom.DownloadStack[FileName].Process = progress;
|
||||||
|
|
||||||
|
if (progress >= 1)
|
||||||
|
{
|
||||||
|
Loom.DownloadStack.Remove(FileName);
|
||||||
|
downloadSlider.value = 100;
|
||||||
|
step3.SetActive(true);
|
||||||
|
step3.transform.Find("RouteName").GetComponent<Text>().text = RouteName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,25 +1,25 @@
|
|||||||
using Assets.AR;
|
using System;
|
||||||
using Assets.Scenes.Ride.Scripts;
|
|
||||||
using Assets.Scripts;
|
using Assets.Scripts;
|
||||||
using Assets.Scripts.Apis;
|
using Assets.Scripts.Apis;
|
||||||
using Assets.Scripts.Apis.Models;
|
using Assets.Scripts.Apis.Models;
|
||||||
using Cysharp.Threading.Tasks;
|
using Cysharp.Threading.Tasks;
|
||||||
using DG.Tweening;
|
using DG.Tweening;
|
||||||
using System;
|
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Assets.AR;
|
||||||
|
using Assets.Core;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using UnityEngine.SceneManagement;
|
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
|
||||||
public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler, IPointerUpHandler
|
||||||
{
|
{
|
||||||
|
private GameObject downloadBtn;
|
||||||
|
private GameObject downloading;
|
||||||
|
private GameObject downloadTxt;
|
||||||
|
|
||||||
public class PropNames
|
public class PropNames
|
||||||
{
|
{
|
||||||
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
public static List<string> icons = new List<string> { "icon1", "icon2", "icon3" };
|
||||||
@ -29,27 +29,66 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
{ true,"#ffffff"},{false,"#5c5c6e" }
|
{ true,"#ffffff"},{false,"#5c5c6e" }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool isModal = false;
|
public bool isModal = false;
|
||||||
float width;
|
float width;
|
||||||
float height;
|
float height;
|
||||||
GameRoomListController listController;
|
|
||||||
|
|
||||||
void Awake()
|
|
||||||
{
|
|
||||||
width = this.GetComponent<RectTransform>().rect.width;
|
|
||||||
height = this.GetComponent<RectTransform>().rect.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Start()
|
|
||||||
{
|
|
||||||
listController = FindObjectOfType<GameRoomListController>();
|
|
||||||
}
|
|
||||||
|
|
||||||
float? localY = null;
|
float? localY = null;
|
||||||
MapRoute map;
|
MapRoute map;
|
||||||
Dictionary<string, Texture> caches;
|
Dictionary<string, Texture> caches;
|
||||||
private MapRouteAreaItem area = null;
|
private MapRouteAreaItem area = null;
|
||||||
Slider slider;
|
Slider slider;
|
||||||
|
GameRoomListController listController;
|
||||||
|
NearRouteModel model { get; set; }
|
||||||
|
|
||||||
|
private ARDownloader downloader { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
private float _videoProgress;
|
||||||
|
|
||||||
|
public float VideoProgress
|
||||||
|
{
|
||||||
|
get => _videoProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_videoProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _dataProgress = 0f;
|
||||||
|
public float DataProgress
|
||||||
|
{
|
||||||
|
get => _dataProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_dataProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float _routeProgress = 0f;
|
||||||
|
public float RouteProgress
|
||||||
|
{
|
||||||
|
get => _routeProgress;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_routeProgress = value;
|
||||||
|
ComputeProgress();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
width = this.GetComponent<RectTransform>().rect.width;
|
||||||
|
height = this.GetComponent<RectTransform>().rect.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
listController = FindObjectOfType<GameRoomListController>();
|
||||||
|
}
|
||||||
|
|
||||||
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
|
public void Initial(MapRoute myMap, Dictionary<string, Texture> caches, MapRouteAreaItem area = null)
|
||||||
{
|
{
|
||||||
if (caches != null)
|
if (caches != null)
|
||||||
@ -63,30 +102,14 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
transform.GetComponent<Button>().onClick.RemoveAllListeners();
|
||||||
transform.GetComponent<Button>().onClick.AddListener(Ride);
|
transform.GetComponent<Button>().onClick.AddListener(Ride);
|
||||||
}
|
}
|
||||||
var downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
downloadBtn = transform.Find("DownLoadModal/DownLoad").gameObject;
|
||||||
var downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
downloading = transform.Find("DownLoadModal/Downloading").gameObject;
|
||||||
var downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
downloadTxt = transform.Find("DownLoadModal/Text").gameObject;
|
||||||
slider = transform.Find("DownLoadModal/Slider").GetComponent<Slider>();
|
slider = transform.Find("DownLoadModal/Slider").GetComponent<Slider>();
|
||||||
|
|
||||||
var fileName = map.FileName;
|
ShowDownloadModal();
|
||||||
var path = PFConstants.VideoFolder;
|
|
||||||
var filepath = path + "/" + fileName;
|
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick,Download_Click);
|
||||||
transform.Find("DownLoadModal").gameObject.SetActive(map.EnableAR && !File.Exists(filepath));
|
|
||||||
UIManager.AddEvent(downloadBtn, EventTriggerType.PointerClick, async (e) =>
|
|
||||||
{
|
|
||||||
downloadBtn.SetActive(false);
|
|
||||||
downloading.SetActive(true);
|
|
||||||
downloadTxt.SetActive(false);
|
|
||||||
slider.gameObject.SetActive(true);
|
|
||||||
var progress = Progress.Create<float>(x =>
|
|
||||||
{
|
|
||||||
Loom.DownloadStack[map.FileName].Process = x;
|
|
||||||
slider.value = x;
|
|
||||||
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
|
|
||||||
transform.Find("DownLoadModal").gameObject.SetActive(x!=1);
|
|
||||||
});
|
|
||||||
await Loom.DownloadLoadARDataAndVideo(map, progress);
|
|
||||||
});
|
|
||||||
|
|
||||||
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
transform.Find("Name").GetComponent<Text>().text = myMap.Name;
|
||||||
transform.Find("IdContainer/Text").GetComponent<Text>().text = $"#{myMap.Id}";
|
transform.Find("IdContainer/Text").GetComponent<Text>().text = $"#{myMap.Id}";
|
||||||
@ -104,16 +127,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D && !myMap.EnableAR);
|
tabContainer.Find("3d").gameObject.SetActive(myMap.Enable3D && !myMap.EnableAR);
|
||||||
tabContainer.Find("AR").gameObject?.SetActive(myMap.EnableAR);
|
tabContainer.Find("AR").gameObject?.SetActive(myMap.EnableAR);
|
||||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(myMap.CountryCode);
|
||||||
//if (!isModal)
|
|
||||||
//{
|
|
||||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.RemoveAllListeners();
|
|
||||||
// transform.Find("CollectImg").GetComponent<Button>().onClick.AddListener(Collect);
|
|
||||||
//}
|
|
||||||
//transform.Find("CollectImg").Find("Image").GetComponent<Image>().sprite =
|
|
||||||
// UIManager.Instance.collectDict[myMap.IsFavorite];
|
|
||||||
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
||||||
//transform.Find("CollectImg").gameObject.SetActive(false);
|
|
||||||
#endif
|
|
||||||
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
transform.Find("BtnInfo").GetComponent<Button>().onClick.AddListener(Info);
|
||||||
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
transform.Find("BtnRide").GetComponent<Button>().onClick.AddListener(Ride);
|
||||||
|
|
||||||
@ -126,7 +140,45 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
transform.Find("BtnContinue").gameObject.SetActive(isRecent);
|
transform.Find("BtnContinue").gameObject.SetActive(isRecent);
|
||||||
transform.Find("BtnReride").gameObject.SetActive(isRecent);
|
transform.Find("BtnReride").gameObject.SetActive(isRecent);
|
||||||
transform.Find("MapHBImg").gameObject.SetActive(!isRecent);
|
transform.Find("MapHBImg").gameObject.SetActive(!isRecent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async void Download_Click(BaseEventData data)
|
||||||
|
{
|
||||||
|
downloadBtn.SetActive(false);
|
||||||
|
downloading.SetActive(true);
|
||||||
|
downloadTxt.SetActive(false);
|
||||||
|
slider.gameObject.SetActive(true);
|
||||||
|
|
||||||
|
slider.maxValue = downloader.Total * 100;
|
||||||
|
if(downloader.IsVideoDownloaded)
|
||||||
|
await downloader.DownLoadVideoAsync(Progress.Create<float>(x => VideoProgress = x));
|
||||||
|
if(downloader.IsARRouteDownloaded)
|
||||||
|
await downloader.DownLoadARRouteAsync(Progress.Create<float>(x=> RouteProgress = x));
|
||||||
|
if(downloader.IsARDataDownloaded)
|
||||||
|
await downloader.DownLoadARDataAsync(Progress.Create<float>(x=> DataProgress = x));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ComputeProgress()
|
||||||
|
{
|
||||||
|
//update progress
|
||||||
|
var progress = (_videoProgress + _routeProgress + _dataProgress) / downloader.Total;
|
||||||
|
slider.value = progress * 100;
|
||||||
|
//update download info
|
||||||
|
if(!Loom.DownloadStack.ContainsKey(map.FileName))
|
||||||
|
Loom.DownloadStack.Add(map.FileName, new DownloadInfo(map.FileName,map.Name,0, map.Url));
|
||||||
|
Loom.DownloadStack[map.FileName].Process = progress;
|
||||||
|
//refresh slider
|
||||||
|
LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)this.slider.transform);
|
||||||
|
transform.Find("DownLoadModal").gameObject.SetActive(progress != 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//显示下载面板
|
||||||
|
private async void ShowDownloadModal()
|
||||||
|
{
|
||||||
|
if(!map.EnableAR) return;
|
||||||
|
downloader = new ARDownloader(map);
|
||||||
|
var showDownload = await downloader.CheckAllAsync();
|
||||||
|
transform.Find("DownLoadModal").gameObject.SetActive(showDownload);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Ride()
|
private void Ride()
|
||||||
@ -206,7 +258,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
|
transform.Find("Shadow").GetComponent<Image>().DOFade(1, 0.3f);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
void SetActive4Button(bool b)
|
private void SetActive4Button(bool b)
|
||||||
{
|
{
|
||||||
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
transform.Find("MapHBImg").gameObject.SetActive(!b);
|
||||||
transform.Find("BtnInfo").gameObject.SetActive(b);
|
transform.Find("BtnInfo").gameObject.SetActive(b);
|
||||||
@ -228,7 +280,7 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
|
transform.Find("MapHBImg").GetComponent<RawImage>().color = Utils.HexToColorHtml(
|
||||||
PropNames.colorDict[isFav]);
|
PropNames.colorDict[isFav]);
|
||||||
}
|
}
|
||||||
async void Collect()
|
private async void Collect()
|
||||||
{
|
{
|
||||||
JsonResult<object> r;
|
JsonResult<object> r;
|
||||||
//transform.Find("CollectImg").GetComponent<Button>().enabled = false;
|
//transform.Find("CollectImg").GetComponent<Button>().enabled = false;
|
||||||
@ -256,7 +308,6 @@ public class GameRoomMapItem : MonoBehaviour, IPointerExitHandler, IPointerEnter
|
|||||||
UIManager.ShowAlert("WARNING", r.errMsg);
|
UIManager.ShowAlert("WARNING", r.errMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NearRouteModel model { get; set; }
|
|
||||||
|
|
||||||
public void Show(Vector3 position, NearRouteModel model)
|
public void Show(Vector3 position, NearRouteModel model)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,8 +9,9 @@ using UnityEngine;
|
|||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
using Assets.Scenes.Ride.Scripts.Model;
|
using Assets.Scenes.Ride.Scripts.Model;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
|
|
||||||
public class GameRoomDetailController : PFUIPanel
|
public class GameRoomDetailController : PFUIPanel,IProgress<float>
|
||||||
{
|
{
|
||||||
public Text versionText;
|
public Text versionText;
|
||||||
public RawImage Avatar;
|
public RawImage Avatar;
|
||||||
@ -27,12 +28,10 @@ public class GameRoomDetailController : PFUIPanel
|
|||||||
public Text bestTabName;
|
public Text bestTabName;
|
||||||
public Text bestTabTimer;
|
public Text bestTabTimer;
|
||||||
public RawImage bestTabHead;
|
public RawImage bestTabHead;
|
||||||
|
|
||||||
public GameObject readyBtn;
|
public GameObject readyBtn;
|
||||||
public GameObject startBtn;
|
public GameObject startBtn;
|
||||||
public GameObject quitBtn;
|
public GameObject quitBtn;
|
||||||
public GameObject cancelBtn;
|
public GameObject cancelBtn;
|
||||||
|
|
||||||
public GameObject d2;
|
public GameObject d2;
|
||||||
public GameObject d3;
|
public GameObject d3;
|
||||||
public GameObject ar;
|
public GameObject ar;
|
||||||
@ -40,68 +39,80 @@ public class GameRoomDetailController : PFUIPanel
|
|||||||
public GameRoomModel GameRoom { get; set; }
|
public GameRoomModel GameRoom { get; set; }
|
||||||
public DateTime? StartTime { get; set; }
|
public DateTime? StartTime { get; set; }
|
||||||
public int Status { get; set; }
|
public int Status { get; set; }
|
||||||
|
|
||||||
private bool isQuit = false;
|
private bool isQuit = false;
|
||||||
|
private bool DataSourceChanged { get; set; }
|
||||||
|
float timer = 0f;
|
||||||
|
private bool isOwner { get; set; } = true;
|
||||||
|
private MapRoute route { get; set; }
|
||||||
|
|
||||||
protected override void Start()
|
protected override void Start()
|
||||||
{
|
{
|
||||||
base.Start();
|
base.Start();
|
||||||
UIManager.AddBackHandler((e) =>
|
UIManager.AddBackHandler(QuitGameRoom);
|
||||||
{
|
|
||||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
|
||||||
App.gameRoomDetail = null;
|
|
||||||
});
|
|
||||||
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
transform.Find("MainNav").GetComponent<MainNav>().ShowBack();
|
||||||
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
Utils.DisplayHead(Avatar, App.CurrentUser.WxHeadImg);
|
||||||
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
||||||
|
UIManager.AddEvent(startBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,StartRide);
|
||||||
|
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,Ready);
|
||||||
|
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,CancelReady);
|
||||||
|
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick,LeaveGameRoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LeaveGameRoom(BaseEventData data)
|
||||||
|
{
|
||||||
|
if (Status == 1)
|
||||||
{
|
{
|
||||||
var list = GameRoom.RoomPlayerList;
|
Utils.showToast(gameObject, App.GetLocalString("CancelReadyToQuit"));
|
||||||
var notReady = list.Where(c => c.Status == 0 && c.IsOwner == false).Any();
|
return;
|
||||||
if (notReady)
|
}
|
||||||
{
|
App.gameRoomDetail = null;
|
||||||
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
isQuit = true;
|
||||||
}
|
MapUDPService.SendGameRoomKick(GameRoom.RoomId, App.CurrentUser.Id, App.CurrentUser.Id);
|
||||||
else
|
UIManager.ShowGameRoomListPanel();
|
||||||
{
|
}
|
||||||
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
|
||||||
}
|
private void CancelReady(BaseEventData data)
|
||||||
});
|
{
|
||||||
//准备
|
Status = 0;
|
||||||
UIManager.AddEvent(readyBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
readyBtn.SetActive(true);
|
||||||
|
cancelBtn.SetActive(false);
|
||||||
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Ready(BaseEventData data)
|
||||||
|
{
|
||||||
|
Status = 1;
|
||||||
|
readyBtn.SetActive(false);
|
||||||
|
cancelBtn.SetActive(true);
|
||||||
|
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void StartRide(BaseEventData data)
|
||||||
|
{
|
||||||
|
var list = GameRoom.RoomPlayerList;
|
||||||
|
var notReady = list.Any(c => c.Status == 0 && c.IsOwner == false);
|
||||||
|
if (notReady)
|
||||||
{
|
{
|
||||||
Status = 1;
|
Utils.showToast(gameObject, App.GetLocalString("have to wait for all ready!"));
|
||||||
readyBtn.SetActive(false);
|
}
|
||||||
cancelBtn.SetActive(true);
|
else
|
||||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
|
||||||
});
|
|
||||||
//取消准备
|
|
||||||
UIManager.AddEvent(cancelBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
|
||||||
{
|
{
|
||||||
Status = 0;
|
MapUDPService.SendGameRoomStartTime(App.gameRoomDetail.RoomId, App.CurrentUser.Id);
|
||||||
readyBtn.SetActive(true);
|
}
|
||||||
cancelBtn.SetActive(false);
|
}
|
||||||
MapUDPService.SendGameRoomReadyStatus(App.gameRoomDetail.RoomId, App.CurrentUser.Id, Status);
|
|
||||||
});
|
private void QuitGameRoom(string e)
|
||||||
//退出
|
{
|
||||||
UIManager.AddEvent(quitBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
|
MapUDPService.SendGameRoomKick(GameRoom.RoomId,App.CurrentUser.Id,App.CurrentUser.Id);
|
||||||
{
|
App.gameRoomDetail = null;
|
||||||
if (Status == 1)
|
|
||||||
{
|
|
||||||
Utils.showToast(gameObject, App.GetLocalString("CancelReadyToQuit"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
App.gameRoomDetail = null;
|
|
||||||
isQuit = true;
|
|
||||||
MapUDPService.SendGameRoomKick(GameRoom.RoomId, App.CurrentUser.Id, App.CurrentUser.Id);
|
|
||||||
UIManager.ShowGameRoomListPanel();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Show()
|
public override void Show()
|
||||||
{
|
{
|
||||||
base.Show();
|
base.Show();
|
||||||
Init();
|
Initialize();
|
||||||
}
|
}
|
||||||
private bool DataSourceChanged { get; set; }
|
|
||||||
private void ListenerHandler(List<ReceiveMsgModel> message)
|
private void ListenerHandler(List<ReceiveMsgModel> message)
|
||||||
{
|
{
|
||||||
var detail = message.FirstOrDefault();
|
var detail = message.FirstOrDefault();
|
||||||
@ -113,22 +124,24 @@ public class GameRoomDetailController : PFUIPanel
|
|||||||
GameRoom = null;
|
GameRoom = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GameRoom = detail.RoomList.Where(c => c.RoomId == GameRoom.RoomId).FirstOrDefault();
|
|
||||||
|
GameRoom = detail.RoomList.FirstOrDefault(c => c.RoomId == GameRoom.RoomId);
|
||||||
if (GameRoom != null)
|
if (GameRoom != null)
|
||||||
{
|
{
|
||||||
DataSourceChanged = true;
|
DataSourceChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float timer = 0f;
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
TcpHandler();
|
TcpHandler();
|
||||||
}
|
}
|
||||||
private void Init()
|
|
||||||
|
private void Initialize()
|
||||||
{
|
{
|
||||||
DataSourceChanged = false;
|
DataSourceChanged = false;
|
||||||
App.Model = "GameRoom";
|
App.Model = "GameRoom";
|
||||||
versionText.text = "V"+App.AppVersion.ToString();
|
versionText.text = "V"+App.AppVersion;
|
||||||
MapUDPService.MessageListener = ListenerHandler;
|
MapUDPService.MessageListener = ListenerHandler;
|
||||||
GameRoom = App.gameRoomDetail;
|
GameRoom = App.gameRoomDetail;
|
||||||
|
|
||||||
@ -150,17 +163,13 @@ public class GameRoomDetailController : PFUIPanel
|
|||||||
distanceText.text = $"{Math.Round(GameRoom.Distance, 1)}KM";
|
distanceText.text = $"{Math.Round(GameRoom.Distance, 1)}KM";
|
||||||
eleText.text = $"{Math.Round(GameRoom.TotalClimb, 0)}M";
|
eleText.text = $"{Math.Round(GameRoom.TotalClimb, 0)}M";
|
||||||
slopeText.text = $"{Math.Round(GameRoom.AverageGrade, 1)}%";
|
slopeText.text = $"{Math.Round(GameRoom.AverageGrade, 1)}%";
|
||||||
//查询某线路最佳
|
|
||||||
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
RenderBestPlayer();
|
||||||
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
|
||||||
{
|
|
||||||
bestTab.SetActive(true);
|
|
||||||
bestTabName.text = result.data.BestNickName;
|
|
||||||
bestTabTimer.text = result.data.BestTotalTime;
|
|
||||||
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
|
||||||
}
|
|
||||||
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
|
||||||
|
|
||||||
|
GetMapRoute();
|
||||||
|
|
||||||
|
Utils.DisplayHead(altitudeGraph, GameRoom.AltitudeGraph);
|
||||||
|
|
||||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||||
foreach (var item in playerList)
|
foreach (var item in playerList)
|
||||||
{
|
{
|
||||||
@ -174,94 +183,126 @@ public class GameRoomDetailController : PFUIPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private bool isOwner { get; set; } = true;
|
|
||||||
private void TcpHandler()
|
private void GetMapRoute()
|
||||||
{
|
{
|
||||||
if (DataSourceChanged)
|
var result = ConfigHelper.mapApi.GetById(GameRoom.MapRouteId);
|
||||||
|
if (result != null && result.result)
|
||||||
{
|
{
|
||||||
//房间被销毁了返回房间列表
|
this.route = result.data;
|
||||||
if (GameRoom == null)
|
|
||||||
{
|
|
||||||
Debug.Log("GameRoom == null");
|
|
||||||
UIManager.ShowGameRoomListPanel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
|
||||||
var list = GameRoom.RoomPlayerList;
|
|
||||||
//自己是否是房主
|
|
||||||
var mine = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
|
||||||
if (mine != null && isOwner != mine.IsOwner)
|
|
||||||
{
|
|
||||||
isOwner = mine.IsOwner;
|
|
||||||
readyBtn.SetActive(!isOwner);
|
|
||||||
startBtn.SetActive(isOwner);
|
|
||||||
cancelBtn.SetActive(!isOwner);
|
|
||||||
}
|
|
||||||
//新增/更新
|
|
||||||
foreach (var item in list)
|
|
||||||
{
|
|
||||||
var userName =item.Name;
|
|
||||||
var headurl = item.WxHeadImage;
|
|
||||||
var ftp = item.FTP;
|
|
||||||
var weight = item.Weight;
|
|
||||||
var sex = item.Sex;
|
|
||||||
var current = playerList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|
||||||
if (current == null)
|
|
||||||
{
|
|
||||||
var s = playerList.Where(c => c.UserId == 0 && c.NotUse == false).OrderBy(c => c.sort).FirstOrDefault();
|
|
||||||
if (s != null)
|
|
||||||
{
|
|
||||||
s.Init(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//删除
|
|
||||||
foreach (var item in playerList)
|
|
||||||
{
|
|
||||||
if (item.UserId != 0)
|
|
||||||
{
|
|
||||||
var current = list.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
|
||||||
if (current == null)
|
|
||||||
{
|
|
||||||
item.ShowInviteModal();
|
|
||||||
}
|
|
||||||
var myself = list.Where(c => c.UserId == App.CurrentUser.Id).FirstOrDefault();
|
|
||||||
//被移除房间/掉线
|
|
||||||
if (myself == null)
|
|
||||||
{
|
|
||||||
if (!isQuit)
|
|
||||||
{
|
|
||||||
Utils.showToast(gameObject, App.GetLocalString("you have been kicked out of the room"));
|
|
||||||
UIManager.ShowGameRoomListPanel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//收到服务器开始命令进入 loading页面
|
|
||||||
if (GameRoom.Status == 1)
|
|
||||||
{
|
|
||||||
//路线
|
|
||||||
App.RouteIdParam = GameRoom.MapRouteId;
|
|
||||||
App.MainSceneParam["Name"] = "GameRoomList";
|
|
||||||
if (GameRoom.EnableAR)
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("VideoPlay");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
SceneManager.LoadScene("Ride");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DataSourceChanged = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//查询某线路最佳
|
||||||
|
private void RenderBestPlayer()
|
||||||
|
{
|
||||||
|
var result = ConfigHelper.mapApi.GetMapBestInfo(GameRoom.MapRouteId);
|
||||||
|
if (result.result && !string.IsNullOrEmpty(result.data.BestNickName))
|
||||||
|
{
|
||||||
|
bestTab.SetActive(true);
|
||||||
|
bestTabName.text = result.data.BestNickName;
|
||||||
|
bestTabTimer.text = result.data.BestTotalTime;
|
||||||
|
Utils.DisplayHead(bestTabHead, result.data.BestWxHeadImg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TcpHandler()
|
||||||
|
{
|
||||||
|
if (!DataSourceChanged) return;
|
||||||
|
|
||||||
|
//房间被销毁了返回房间列表
|
||||||
|
if (GameRoom == null)
|
||||||
|
{
|
||||||
|
UIManager.ShowGameRoomListPanel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var playerList = FindObjectsOfType<GameRoomPlayerPanel>();
|
||||||
|
SetRoomOwner();
|
||||||
|
CreatePlayers(playerList);
|
||||||
|
RemovePlayers(playerList);
|
||||||
|
LoadScene();
|
||||||
|
DataSourceChanged = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
//自己是否是房主
|
||||||
|
private void SetRoomOwner()
|
||||||
|
{
|
||||||
|
var mine = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == App.CurrentUser.Id);
|
||||||
|
if (mine != null && isOwner != mine.IsOwner)
|
||||||
|
{
|
||||||
|
isOwner = mine.IsOwner;
|
||||||
|
readyBtn.SetActive(!isOwner);
|
||||||
|
startBtn.SetActive(isOwner);
|
||||||
|
cancelBtn.SetActive(!isOwner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//收到服务器开始命令进入 loading页面
|
||||||
|
private void LoadScene()
|
||||||
|
{
|
||||||
|
if (GameRoom.Status != 1) return;
|
||||||
|
|
||||||
|
App.RouteIdParam = GameRoom.MapRouteId;
|
||||||
|
App.MainSceneParam["Name"] = "GameRoomList";
|
||||||
|
|
||||||
|
SceneManager.LoadScene(GameRoom.EnableAR?"VideoPlay":"Ride");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreatePlayers(GameRoomPlayerPanel[] playerList)
|
||||||
|
{
|
||||||
|
foreach (var item in GameRoom.RoomPlayerList)
|
||||||
|
{
|
||||||
|
var userName = item.Name;
|
||||||
|
var headurl = item.WxHeadImage;
|
||||||
|
var ftp = item.FTP;
|
||||||
|
var weight = item.Weight;
|
||||||
|
var sex = item.Sex;
|
||||||
|
var current = playerList.Where(c => c.UserId == item.UserId).FirstOrDefault();
|
||||||
|
if (current == null)
|
||||||
|
{
|
||||||
|
var s = playerList.Where(c => c.UserId == 0 && c.NotUse == false).OrderBy(c => c.sort).FirstOrDefault();
|
||||||
|
if (s != null)
|
||||||
|
{
|
||||||
|
s.Init(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current.UpdatePlayer(item.UserId, userName, headurl, weight, ftp, item.IsOwner, item.Status,sex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RemovePlayers(GameRoomPlayerPanel[] playerList)
|
||||||
|
{
|
||||||
|
foreach (var item in playerList)
|
||||||
|
{
|
||||||
|
if (item.UserId == 0) continue;
|
||||||
|
|
||||||
|
var current = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == item.UserId);
|
||||||
|
if (current == null)
|
||||||
|
{
|
||||||
|
item.ShowInviteModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
//被移除房间/掉线
|
||||||
|
var myself = GameRoom.RoomPlayerList.FirstOrDefault(c => c.UserId == App.CurrentUser.Id);
|
||||||
|
if (myself == null && !isQuit )
|
||||||
|
{
|
||||||
|
Utils.showToast(gameObject, App.GetLocalString("you have been kicked out of the room"));
|
||||||
|
UIManager.ShowGameRoomListPanel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnDisable()
|
protected override void OnDisable()
|
||||||
{
|
{
|
||||||
App.Model = "";
|
App.Model = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Report(float value)
|
||||||
|
{
|
||||||
|
Debug.Log(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,10 +7,9 @@ using Assets.Scripts.UI.Control;
|
|||||||
using Assets.Scripts.UI.Prefab.MapList;
|
using Assets.Scripts.UI.Prefab.MapList;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using Assets.AR;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
@ -54,7 +53,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
private GameObject right;
|
private GameObject right;
|
||||||
private GameObject right2;
|
private GameObject right2;
|
||||||
|
|
||||||
|
|
||||||
private GameObject btn30;
|
private GameObject btn30;
|
||||||
private GameObject btn40;
|
private GameObject btn40;
|
||||||
private GameObject btn50;
|
private GameObject btn50;
|
||||||
@ -70,7 +68,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
private Transform enterRoomModal;
|
private Transform enterRoomModal;
|
||||||
private Transform cycingRoomModal;
|
private Transform cycingRoomModal;
|
||||||
private Transform resultRoomModal;
|
private Transform resultRoomModal;
|
||||||
|
|
||||||
private GameObject RoomRankItem;
|
private GameObject RoomRankItem;
|
||||||
|
|
||||||
private string RoomName;
|
private string RoomName;
|
||||||
@ -100,10 +97,8 @@ public class GameRoomListController : PFUIPanel
|
|||||||
GameObject _avatar;
|
GameObject _avatar;
|
||||||
|
|
||||||
private GameObject RoomCell { get; set; }
|
private GameObject RoomCell { get; set; }
|
||||||
|
|
||||||
//Dummy data List
|
//Dummy data List
|
||||||
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
private List<GameRoomModel> _list = new List<GameRoomModel>();
|
||||||
|
|
||||||
private string seachName = "";
|
private string seachName = "";
|
||||||
private bool ListChanged = false;
|
private bool ListChanged = false;
|
||||||
private bool CreateRoomSuccessed = false;
|
private bool CreateRoomSuccessed = false;
|
||||||
@ -162,7 +157,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
var g = Instantiate(RoomCell, _rectTransform);
|
var g = Instantiate(RoomCell, _rectTransform);
|
||||||
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
g.GetComponent<GameRoomCell>().ConfigureCell(item, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
List<GameRoomModel> list;
|
List<GameRoomModel> list;
|
||||||
private int Total { get; set; }
|
private int Total { get; set; }
|
||||||
@ -268,7 +262,13 @@ public class GameRoomListController : PFUIPanel
|
|||||||
CreateClicked = false;
|
CreateClicked = false;
|
||||||
UIManager.ShowGameRoomDetailPanel();
|
UIManager.ShowGameRoomDetailPanel();
|
||||||
}
|
}
|
||||||
//LOOM中取数据渲染下载当前下载进度
|
|
||||||
|
RenderDownloadTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
//LOOM中取数据渲染下载当前下载进度
|
||||||
|
private void RenderDownloadTask()
|
||||||
|
{
|
||||||
var downLoadList = transform.Find("DownLoadList").gameObject;
|
var downLoadList = transform.Find("DownLoadList").gameObject;
|
||||||
var list = Loom.DownloadStack.Where(c => c.Value.Process < 1);
|
var list = Loom.DownloadStack.Where(c => c.Value.Process < 1);
|
||||||
if (list.Count() > 0)
|
if (list.Count() > 0)
|
||||||
@ -736,24 +736,30 @@ public class GameRoomListController : PFUIPanel
|
|||||||
enterRoomModal.gameObject.SetActive(true);
|
enterRoomModal.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
//如果本地没有视频文件则弹窗下载否则直接进入房间
|
//如果本地没有视频文件则弹窗下载否则直接进入房间
|
||||||
public void ShowDownLoadConfirm()
|
public async void ShowDownLoadConfirm()
|
||||||
{
|
{
|
||||||
var fileName = GameRoom.FileName;
|
if(!GameRoom.EnableAR) return ;
|
||||||
var path = PFConstants.VideoFolder;
|
var result = ConfigHelper.mapApi.GetById(GameRoom.MapRouteId);
|
||||||
var filepath = path + "/" + fileName;
|
if (!result.result) return;
|
||||||
|
var route = result.data;
|
||||||
|
|
||||||
var download = transform.Find("DownloadPanel").gameObject;
|
var download = transform.Find("DownloadPanel").gameObject;
|
||||||
if (GameRoom.EnableAR && !File.Exists(filepath))
|
downloader = new ARDownloader(route);
|
||||||
|
var showDownload = await downloader.CheckAllAsync();
|
||||||
|
if (showDownload)
|
||||||
{
|
{
|
||||||
//查询fileUrl
|
GameRoom.FileUrl = route.Url;
|
||||||
GameRoom.FileUrl = ConfigHelper.GameRoomApi.GetMapVideoURL(GameRoom.MapRouteId).data;
|
|
||||||
download.SetActive(true);
|
download.SetActive(true);
|
||||||
download.GetComponent<GameRoomDownLoad>().Init(RoomId, GameRoom.FileName, GameRoom.FileUrl, this, GameRoom.MapRouteName);
|
download.GetComponent<GameRoomDownLoad>().Init(RoomId, GameRoom.FileName, GameRoom.FileUrl, this, GameRoom.MapRouteName,downloader);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GetInRoom();
|
GetInRoom();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ARDownloader downloader;
|
||||||
|
|
||||||
private GameRoomModel modelGameRoom { get; set; }
|
private GameRoomModel modelGameRoom { get; set; }
|
||||||
//private GameRoomModel modelGameRoom { get; set; }
|
//private GameRoomModel modelGameRoom { get; set; }
|
||||||
private Text CyclingTimer { get; set; }
|
private Text CyclingTimer { get; set; }
|
||||||
@ -788,7 +794,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowStatusModal(Transform tr,GameRoomModel data)
|
private void ShowStatusModal(Transform tr,GameRoomModel data)
|
||||||
{
|
{
|
||||||
tr.Find("Modal/Id").GetComponent<Text>().text = data.RoomId.ToString().PadLeft(7, '0');
|
tr.Find("Modal/Id").GetComponent<Text>().text = data.RoomId.ToString().PadLeft(7, '0');
|
||||||
@ -818,8 +823,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
UIManager.AddEvent(quit, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
UIManager.AddEvent(quit, EventTriggerType.PointerClick, (e) => { tr.gameObject.SetActive(false); });
|
||||||
tr.gameObject.SetActive(true);
|
tr.gameObject.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void GetInRoom()
|
public void GetInRoom()
|
||||||
{
|
{
|
||||||
//1.房间人数已经满了
|
//1.房间人数已经满了
|
||||||
@ -841,13 +844,11 @@ public class GameRoomListController : PFUIPanel
|
|||||||
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.RoomId,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
MapUDPService.SendJoinGameRoom(App.gameRoomDetail.RoomId,App.CurrentUser.Id,UIManager.Now.GetDateTime().ToUniversalTime());
|
||||||
UIManager.ShowGameRoomDetailPanel();
|
UIManager.ShowGameRoomDetailPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SelectRoom(GameRoomModel room)
|
public void SelectRoom(GameRoomModel room)
|
||||||
{
|
{
|
||||||
GameRoom = room;
|
GameRoom = room;
|
||||||
RoomId = GameRoom.RoomId;
|
RoomId = GameRoom.RoomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetRoomId()
|
public int GetRoomId()
|
||||||
{
|
{
|
||||||
return RoomId;
|
return RoomId;
|
||||||
@ -886,7 +887,6 @@ public class GameRoomListController : PFUIPanel
|
|||||||
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(map.CountryCode);
|
tabContainer.Find("Country").GetComponent<RawImage>().texture = UIManager.Instance.loginRegOptions.GetCountryImage(map.CountryCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
content.transform.DestroyChildren();
|
content.transform.DestroyChildren();
|
||||||
@ -894,14 +894,12 @@ public class GameRoomListController : PFUIPanel
|
|||||||
isEnd = false;
|
isEnd = false;
|
||||||
GetList();
|
GetList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onEndEdit()
|
private void onEndEdit()
|
||||||
{
|
{
|
||||||
var t = searchInput.GetComponent<InputField>().text;
|
var t = searchInput.GetComponent<InputField>().text;
|
||||||
ftname = t;
|
ftname = t;
|
||||||
Refresh();
|
Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DisplayMaps(List<MapRoute> list)
|
private void DisplayMaps(List<MapRoute> list)
|
||||||
{
|
{
|
||||||
if (map != null)
|
if (map != null)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ using System.Collections;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -171,7 +172,7 @@ public class Loom : MonoBehaviour
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, DownloadInfo> DownloadStack = new Dictionary<string, DownloadInfo>();
|
public static Dictionary<string, DownloadInfo> DownloadStack { get; set; } = new Dictionary<string, DownloadInfo>();
|
||||||
|
|
||||||
public static async Task DownloadLoadARDataAndVideo(MapRoute route,IProgress<float> progress)
|
public static async Task DownloadLoadARDataAndVideo(MapRoute route,IProgress<float> progress)
|
||||||
{
|
{
|
||||||
@ -184,7 +185,6 @@ public class Loom : MonoBehaviour
|
|||||||
var cancelToken = new CancellationTokenSource();
|
var cancelToken = new CancellationTokenSource();
|
||||||
var dataPath = $"{localPath}/{route.Id}";
|
var dataPath = $"{localPath}/{route.Id}";
|
||||||
|
|
||||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
|
||||||
Helper.CreateDirectoryIfNotExsit(dataPath);
|
Helper.CreateDirectoryIfNotExsit(dataPath);
|
||||||
|
|
||||||
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
|
await Loom.DownloadToFileAsync(arDataPath, $"{dataPath}/{route.Id}.json");
|
||||||
@ -206,9 +206,45 @@ public class Loom : MonoBehaviour
|
|||||||
};
|
};
|
||||||
|
|
||||||
var request = UnityWebRequest.Get(downloadUrl);
|
var request = UnityWebRequest.Get(downloadUrl);
|
||||||
request.method = UnityWebRequest.kHttpVerbGET;
|
|
||||||
request.downloadHandler = dh;
|
request.downloadHandler = dh;
|
||||||
|
request.method = UnityWebRequest.kHttpVerbGET;
|
||||||
|
|
||||||
return await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
return await request.SendWebRequest().ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// head request for file meta info such as etag.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="downloadUrl">download url</param>
|
||||||
|
/// <param name="fullPath">local path for storage</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async UniTask<UnityWebRequest> HeadFileAsync(string downloadUrl, string fullPath, IProgress<float> progress = null,CancellationTokenSource cancellation = default(CancellationTokenSource))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{ var etagFile = fullPath + ".etag";
|
||||||
|
var etag = string.Empty;
|
||||||
|
if (File.Exists(etagFile))
|
||||||
|
{
|
||||||
|
etag = File.ReadAllText(etagFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
var request = UnityWebRequest.Head(downloadUrl);
|
||||||
|
if(!string.IsNullOrEmpty(etag))
|
||||||
|
request.SetRequestHeader("If-None-Match", etag);
|
||||||
|
|
||||||
|
var result = await request.SendWebRequest();//.ToUniTask(progress, PlayerLoopTiming.Update, (cancellation?.Token ?? default(CancellationToken)));
|
||||||
|
|
||||||
|
if (result.responseCode != (long)HttpStatusCode.NotModified)
|
||||||
|
{
|
||||||
|
etag = result.GetResponseHeader("ETag");
|
||||||
|
File.WriteAllText(fullPath+".etag",etag);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user