2022-12-05 18:29:49 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using RenderHeads.Media.AVProVideo;
|
|
|
|
|
|
using Assets.Scripts.Scenes.VideoRide;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
using Assets.Scenes.Ride.Scripts.Model.RiderModels;
|
2023-03-10 14:22:41 +08:00
|
|
|
|
using UnityEngine.Assertions;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
|
|
|
|
|
|
namespace Assets.AR
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
public class ARTrainingController : ARLaneGameObjectsController
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
public MediaPlayer mediaPlayer;
|
|
|
|
|
|
private ARData aRData;
|
|
|
|
|
|
private RouteDetailData detail;
|
|
|
|
|
|
private VideoPointsSync videoPointsSync;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
private readonly List<ARLaneGameObject> collisionList = new List<ARLaneGameObject>();
|
|
|
|
|
|
ARVideoPlayerControl VideoPlayerControl;
|
|
|
|
|
|
ARLaneGameObject[] rides { get; set; }
|
|
|
|
|
|
public ARLaneGameObject mainRiderObject { get; set; }
|
2023-03-08 18:33:33 +08:00
|
|
|
|
public Light arLight;
|
|
|
|
|
|
private Light arBackLight { get; set; }
|
2023-01-31 18:22:15 +08:00
|
|
|
|
public CameraDistance RiderCameraDistance { get; set; }
|
|
|
|
|
|
public VideoPlayMode VideoControlMode { get; private set; }
|
2022-12-05 18:29:49 +08:00
|
|
|
|
private float autoCameraSwitchTimeCounter = 80f;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
float timers = 0f;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
private VideoGameManager manager;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
public int VisibleModels { get; private set; }
|
|
|
|
|
|
private int visibleModelsLimit = 20;
|
2023-03-10 14:22:41 +08:00
|
|
|
|
public int VisibleRiderTitlesLimit => this.VisibleModelsLimit + 10;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
public int VisibleModelsLimit
|
|
|
|
|
|
{
|
|
|
|
|
|
get => this.visibleModelsLimit;
|
|
|
|
|
|
set => this.visibleModelsLimit = Mathf.Clamp(value, 20, 100);
|
|
|
|
|
|
}
|
|
|
|
|
|
private Dictionary<int, VisibleRiderItem> visibleRiders = new Dictionary<int, VisibleRiderItem>();
|
|
|
|
|
|
private Dictionary<int, OnlineRiderModel> riders = new Dictionary<int, OnlineRiderModel>();
|
|
|
|
|
|
//private Dictionary<int, UIRect> riderNameViews { get; set; } //= new Dictionary<int, UIRect>();
|
|
|
|
|
|
//private Dictionary<int, RiderValueView> riderValueViews = new Dictionary<int, RiderValueView>();
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject BikerFemalePrefab => Resources.Load<GameObject>("UI/Prefab/AR/VidePlayer");
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject BikerMalePrefab => Resources.Load<GameObject>("UI/Prefab/AR/VidePlayer_NV");
|
|
|
|
|
|
|
|
|
|
|
|
private bool paused { get; set; }
|
2022-12-05 18:29:49 +08:00
|
|
|
|
|
|
|
|
|
|
protected override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Start();
|
|
|
|
|
|
this.arObjects.Clear();
|
|
|
|
|
|
manager = GetComponent<VideoGameManager>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Initialize(ARData arData, RouteDetailData routeDetailData)
|
|
|
|
|
|
{
|
|
|
|
|
|
//ar数据加载本地,本地没有就下载
|
2022-12-08 19:17:34 +08:00
|
|
|
|
this.aRData = arData;
|
|
|
|
|
|
this.detail = routeDetailData;
|
2023-03-08 18:33:33 +08:00
|
|
|
|
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.RiderCameraDistance = AR.CameraDistance.Middle;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
videoPointsSync = new VideoPointsSync(detail.VideoPoints.Select(c => new VideoPoint()
|
|
|
|
|
|
{
|
|
|
|
|
|
Distance = (float)c.Distance,
|
|
|
|
|
|
Time = (float)c.VideoTime
|
|
|
|
|
|
}));
|
|
|
|
|
|
videoSync = videoPointsSync;
|
2023-03-08 18:33:33 +08:00
|
|
|
|
this.VideoPlayerControl = new ARVideoPlayerControl
|
|
|
|
|
|
{
|
|
|
|
|
|
VideoSyncSource = videoSync
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-02-07 18:35:16 +08:00
|
|
|
|
this.videoPlayer = mediaPlayer.gameObject.AddComponent<AVProVideoPlayer>();
|
2022-12-05 18:29:49 +08:00
|
|
|
|
this.videoPlayer.videoPlayer = mediaPlayer;
|
2023-03-08 18:33:33 +08:00
|
|
|
|
|
2022-12-05 18:29:49 +08:00
|
|
|
|
SetArRoute(new ARRoute(aRData.Route), videoSync, videoPlayer);
|
2023-03-08 18:33:33 +08:00
|
|
|
|
|
2022-12-05 18:29:49 +08:00
|
|
|
|
this.VideoPlayerControl.VideoFrameOffset = this.Route.VideoFrameOffset;
|
|
|
|
|
|
this.VideoPlayerControl.Route = Route;
|
|
|
|
|
|
this.VideoPlayerControl.SetVideoPlayer(videoPlayer);
|
2023-03-08 18:33:33 +08:00
|
|
|
|
|
2023-01-31 18:22:15 +08:00
|
|
|
|
rides = FindObjectsOfType<ARLaneGameObject>();
|
2022-12-05 18:29:49 +08:00
|
|
|
|
SetUpLight();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
|
{
|
2023-03-10 14:22:41 +08:00
|
|
|
|
if (videoPlayer == null ) return;
|
|
|
|
|
|
|
2022-12-05 18:29:49 +08:00
|
|
|
|
timers -= Time.deltaTime;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
while (timers <= 0)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
2023-03-10 14:22:41 +08:00
|
|
|
|
UpdateRiders();
|
|
|
|
|
|
RemoveRiders();
|
2023-03-08 18:33:33 +08:00
|
|
|
|
timers += 0.2f;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
}
|
2023-03-10 14:22:41 +08:00
|
|
|
|
|
2023-01-31 18:22:15 +08:00
|
|
|
|
if (mainRiderObject == null || Route == null)
|
|
|
|
|
|
{
|
2023-03-10 14:22:41 +08:00
|
|
|
|
videoPlayer.Pause();
|
2022-12-08 19:17:34 +08:00
|
|
|
|
return;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
}
|
2023-03-10 14:22:41 +08:00
|
|
|
|
|
2023-04-28 20:23:37 +08:00
|
|
|
|
PlayFrameDistance();
|
2023-03-08 18:33:33 +08:00
|
|
|
|
VideoPlayerControl.UpdateVideoPlayRate(mainRiderObject.PreSpeed, mainRiderObject.Distance);
|
2023-04-28 20:23:37 +08:00
|
|
|
|
FrameIndexDistanceCorrection = this.VideoPlayerControl.FrameIndexDistanceCorrection;
|
|
|
|
|
|
UpdateCameraFollowDistance();
|
2023-03-10 14:22:41 +08:00
|
|
|
|
|
2022-12-05 18:29:49 +08:00
|
|
|
|
base.Update();
|
2023-04-28 20:23:37 +08:00
|
|
|
|
UpdateRidersVisibility();
|
|
|
|
|
|
UpdateRidersLean();
|
|
|
|
|
|
UpdateBackLight();
|
|
|
|
|
|
SetUpVideoControlMode();
|
|
|
|
|
|
UpdateRemainingTime();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 处理人物快倒计时
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdateRemainingTime()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (mainRiderObject == null) return;
|
|
|
|
|
|
var remainingDistance = Math.Round(manager.GetMapRoute().Distance * 1000f - mainRiderObject.Distance);
|
|
|
|
|
|
manager.ShowUpRemainTime(remainingDistance);
|
2023-03-10 14:22:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 更新骑行者的实时数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void UpdateRiders()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var dic in manager.rideObjs)
|
|
|
|
|
|
{
|
|
|
|
|
|
var item = dic.Value;
|
|
|
|
|
|
if (!this.arObjects.Contains(item))
|
|
|
|
|
|
this.arObjects.Add(item);
|
|
|
|
|
|
if (!this.riderObjects.ContainsKey(item.UserId))
|
|
|
|
|
|
this.riderObjects.Add(item.UserId, item);
|
|
|
|
|
|
|
|
|
|
|
|
item.PreSpeed = item.Speed;
|
|
|
|
|
|
item.Speed = (float)dic.Key.OnlineSpeed;
|
|
|
|
|
|
item.DeltaDistance = (float)(dic.Key.EndDistance - dic.Key.PreDistance);
|
|
|
|
|
|
item.Route = Route;
|
|
|
|
|
|
item.VideoSync = videoPointsSync;
|
|
|
|
|
|
item.IsAtFinish = dic.Key.EndDistance >= manager.GetMapRoute().Distance*1000f;
|
|
|
|
|
|
|
|
|
|
|
|
if (dic.Key.UserId != manager.CurrentUserId) continue;
|
|
|
|
|
|
mainRiderObject = item;
|
|
|
|
|
|
//如果速度为0就停止播放视频
|
|
|
|
|
|
if (item.DeltaDistance == 0 || item.Speed == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
item.DeltaDistance = 0;
|
|
|
|
|
|
videoPlayer.Pause();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
videoPlayer.Resume();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 移除不可见的骑行者
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void RemoveRiders()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.arObjects.RemoveAll(c => !manager.rideObjs.Select(m => m.Key.UserId.ToString()).Contains(c.UserId.ToString()));
|
|
|
|
|
|
|
|
|
|
|
|
var keys = riderObjects.Keys.ToList();
|
2023-04-18 17:10:48 +08:00
|
|
|
|
foreach (var item in keys.Where(item => manager.rideObjs.Keys.All(c => c.UserId != item)))
|
2023-03-10 14:22:41 +08:00
|
|
|
|
{
|
2023-04-18 17:10:48 +08:00
|
|
|
|
riderObjects.Remove(item);
|
2023-03-10 14:22:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 将每秒的距离转换为每帧的距离
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void PlayFrameDistance()
|
|
|
|
|
|
{
|
|
|
|
|
|
var delta = Time.deltaTime;
|
|
|
|
|
|
foreach (var obj in this.riderObjects.Values.Where(obj => obj.DeltaDistance != 0))
|
|
|
|
|
|
{
|
|
|
|
|
|
obj.Distance = Mathf.Lerp(obj.Distance, obj.Distance + obj.DeltaDistance, delta);
|
|
|
|
|
|
obj.RouteDistance = Mathf.Lerp(obj.RouteDistance, obj.RouteDistance + obj.DeltaDistance, delta);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置camera的跟随距离
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void SetUpVideoControlMode()
|
|
|
|
|
|
{
|
2022-12-05 18:29:49 +08:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.F))
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.SetVideoControlMode(VideoPlayMode.Front);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
if (Input.GetKeyDown(KeyCode.P))
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.SetVideoControlMode(VideoPlayMode.AutoPanorama);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
if (!Input.GetKeyDown(KeyCode.B))
|
|
|
|
|
|
return;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.SetVideoControlMode(VideoPlayMode.Rear);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
}
|
2023-03-10 14:22:41 +08:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置光线
|
|
|
|
|
|
/// </summary>
|
2022-12-05 18:29:49 +08:00
|
|
|
|
private void SetUpLight()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.arLight.type = LightType.Directional;
|
|
|
|
|
|
this.arLight.transform.rotation = Quaternion.Euler(90f, 0.0f, 0.0f);
|
2023-03-08 18:33:33 +08:00
|
|
|
|
this.arLight.shadows = LightShadows.Soft;
|
|
|
|
|
|
this.arLight.shadowStrength = 1f;
|
|
|
|
|
|
|
2023-03-10 14:22:41 +08:00
|
|
|
|
var gameObject2 = new GameObject("ARBackLight");
|
2022-12-05 18:29:49 +08:00
|
|
|
|
gameObject2.layer = this.gameObject.layer;
|
|
|
|
|
|
gameObject2.transform.SetParent(this.transform);
|
|
|
|
|
|
this.arBackLight = gameObject2.AddComponent<Light>();
|
|
|
|
|
|
this.arBackLight.type = LightType.Directional;
|
|
|
|
|
|
this.arBackLight.transform.rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
this.arBackLight.shadows = LightShadows.None;
|
|
|
|
|
|
this.arBackLight.intensity = 0.5f;
|
|
|
|
|
|
}
|
2023-03-10 14:22:41 +08:00
|
|
|
|
|
2023-01-31 18:22:15 +08:00
|
|
|
|
public void SetVideoControlMode(VideoPlayMode mode)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (mode == this.VideoControlMode)
|
|
|
|
|
|
return;
|
|
|
|
|
|
if (!this.AR360Version)
|
2023-01-31 18:22:15 +08:00
|
|
|
|
mode = VideoPlayMode.Front;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
this.VideoControlMode = mode;
|
|
|
|
|
|
this.autoCameraSwitchTimeCounter = 80f;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
if (mode == VideoPlayMode.AutoPanorama)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
return;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.videoPlayer.IntendedRear = mode == VideoPlayMode.Rear;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
//更新摄像机的位置
|
|
|
|
|
|
private void UpdateCameraFollowDistance()
|
|
|
|
|
|
{
|
2023-03-08 18:33:33 +08:00
|
|
|
|
var cameraFollowDistance = GetCameraFollowDistance(this.RiderCameraDistance);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
this.VideoPlayerControl.CameraFollowDistance = cameraFollowDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
//人物是否显示
|
2023-02-20 18:31:59 +08:00
|
|
|
|
protected override bool IsObjectActive(ARGameObject arObject)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var flag = base.IsObjectActive(arObject);
|
2023-03-08 18:33:33 +08:00
|
|
|
|
if (arObject != this.mainRiderObject)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
return flag;
|
|
|
|
|
|
if ((double)this.VideoPlayerControl.CameraFollowDistance > 0.0 || this.AR360Version)
|
|
|
|
|
|
return flag;
|
|
|
|
|
|
return flag && (double)this.VideoPlayerControl.CameraDistanceError > 5.0;
|
|
|
|
|
|
}
|
|
|
|
|
|
//获取摄像机的位置
|
2023-01-31 18:22:15 +08:00
|
|
|
|
public static float GetCameraFollowDistance(CameraDistance distance)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
switch (distance)
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
case AR.CameraDistance.FirstPerson:
|
2022-12-05 18:29:49 +08:00
|
|
|
|
return 0.0f;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
case AR.CameraDistance.Near:
|
2022-12-08 19:17:34 +08:00
|
|
|
|
return 1.5f;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
case AR.CameraDistance.Middle:
|
2023-04-28 20:23:37 +08:00
|
|
|
|
return 8f;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
case AR.CameraDistance.Far:
|
2022-12-05 18:29:49 +08:00
|
|
|
|
return 10f;
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new ArgumentException("Unknown rider's camera distance.");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-12-08 19:17:34 +08:00
|
|
|
|
//添加骑手
|
|
|
|
|
|
public void AddRider(OnlineRiderModel rider)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (this.riders.ContainsKey(rider.UserId))
|
|
|
|
|
|
return;
|
|
|
|
|
|
this.riders.Add(rider.UserId, rider);
|
|
|
|
|
|
}
|
|
|
|
|
|
//移除骑手
|
|
|
|
|
|
public void RemoveRider(int riderId)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!this.riders.ContainsKey(riderId))
|
|
|
|
|
|
return;
|
|
|
|
|
|
this.riders.Remove(riderId);
|
|
|
|
|
|
this.DestroyRider(riderId);
|
|
|
|
|
|
this.DestroyRiderTitle(riderId);
|
|
|
|
|
|
}
|
|
|
|
|
|
//创建人物
|
2023-01-31 18:22:15 +08:00
|
|
|
|
private AbstractRenderer CreateRiderModel(OnlineRiderModel rider, float lane)
|
2022-12-08 19:17:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
GameObject gameObject;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
PlayerRenderer riderModel;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (rider.Sex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject = UnityEngine.Object.Instantiate<GameObject>(this.BikerMalePrefab);
|
|
|
|
|
|
gameObject.name = "RiderMale " + rider.UserId.ToString();
|
2023-01-31 18:22:15 +08:00
|
|
|
|
riderModel = gameObject.AddComponent<PlayerRenderer>();
|
2022-12-08 19:17:34 +08:00
|
|
|
|
riderModel.Initialize(true, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
gameObject = UnityEngine.Object.Instantiate<GameObject>(this.BikerFemalePrefab);
|
|
|
|
|
|
gameObject.name = "RiderFemale " + rider.UserId.ToString();
|
2023-01-31 18:22:15 +08:00
|
|
|
|
riderModel = gameObject.AddComponent<PlayerRenderer>();
|
2022-12-08 19:17:34 +08:00
|
|
|
|
riderModel.Initialize(false, false);
|
|
|
|
|
|
}
|
|
|
|
|
|
gameObject.transform.parent = this.transform;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
gameObject.transform.position = ARGameObjectsController.DefaultObjectPosition;
|
2023-03-08 18:33:33 +08:00
|
|
|
|
//gameObject.layer = 9;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
riderModel.Route = this.Route;
|
|
|
|
|
|
riderModel.VideoSync = this.videoSync;
|
|
|
|
|
|
//riderModel.VideoPlayer = this.videoPlayer;
|
|
|
|
|
|
//riderModel.ColorUser = rider.UserColor;
|
|
|
|
|
|
//riderModel.ColorSkin = rider.SkinColor;
|
|
|
|
|
|
// ModelTexturesList modelTextures = this.GetModelTextures(rider.JerseyId);
|
|
|
|
|
|
//riderModel.JerseyTexture = modelTextures.JerseyTexture;
|
|
|
|
|
|
//riderModel.HelmTexture = modelTextures.HelmTexture;
|
|
|
|
|
|
//riderModel.BikeTexture = modelTextures.BikeTexture;
|
|
|
|
|
|
if ((double)lane != -1.0)
|
|
|
|
|
|
riderModel.Lane = lane;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.riderObjects.Add(rider.UserId, (ARLaneGameObject)riderModel);
|
|
|
|
|
|
this.arObjects.Add((ARGameObject)riderModel);
|
2022-12-08 19:17:34 +08:00
|
|
|
|
//是否
|
|
|
|
|
|
if (this.IsMainRider(rider))
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.mainRiderObject = (ARLaneGameObject)riderModel;
|
|
|
|
|
|
return (AbstractRenderer)riderModel;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-31 18:22:15 +08:00
|
|
|
|
private ARLaneGameObject CreateRiderObject(OnlineRiderModel rider, float lane)
|
2022-12-08 19:17:34 +08:00
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
ARLaneGameObject riderObject = new GameObject("RiderObject " + rider.UserId.ToString())
|
2022-12-08 19:17:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
transform = {
|
|
|
|
|
|
parent = this.transform
|
|
|
|
|
|
},
|
2023-03-08 18:33:33 +08:00
|
|
|
|
//layer = 9
|
2023-01-31 18:22:15 +08:00
|
|
|
|
}.AddComponent<ARLaneGameObject>();
|
2022-12-08 19:17:34 +08:00
|
|
|
|
riderObject.Route = this.Route;
|
|
|
|
|
|
riderObject.VideoSync = this.videoSync;
|
|
|
|
|
|
//riderObject.VideoPlayer = this.videoPlayer;
|
|
|
|
|
|
if ((double)lane != -1.0)
|
|
|
|
|
|
riderObject.Lane = lane;
|
|
|
|
|
|
this.riderObjects.Add(rider.UserId, riderObject);
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.arObjects.Add((ARGameObject)riderObject);
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (this.IsMainRider(rider))
|
|
|
|
|
|
this.mainRiderObject = riderObject;
|
|
|
|
|
|
return riderObject;
|
|
|
|
|
|
}
|
|
|
|
|
|
//销毁骑手
|
|
|
|
|
|
private void DestroyRider(int riderId)
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
ARLaneGameObject arLaneObject;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (!this.riderObjects.TryGetValue(riderId, out arLaneObject))
|
|
|
|
|
|
return;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.arObjects.Remove((ARGameObject)arLaneObject);
|
2022-12-08 19:17:34 +08:00
|
|
|
|
this.riderObjects.Remove(riderId);
|
|
|
|
|
|
if ((UnityEngine.Object)arLaneObject == (UnityEngine.Object)this.mainRiderObject)
|
2023-01-31 18:22:15 +08:00
|
|
|
|
this.mainRiderObject = (ARLaneGameObject)null;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
UnityEngine.Object.Destroy((UnityEngine.Object)arLaneObject.gameObject);
|
|
|
|
|
|
}
|
|
|
|
|
|
//创建骑行人员头顶的名字
|
|
|
|
|
|
private void CreateRiderTitle(OnlineRiderModel rider)
|
|
|
|
|
|
{
|
|
|
|
|
|
//RiderNameView riderNameView = UIRect.Create<RiderNameView>(this.transform, "Name " + rider.Id.ToString());
|
|
|
|
|
|
//riderNameView.RectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
|
|
//riderNameView.gameObject.layer = 9;
|
|
|
|
|
|
//riderNameView.NameLabel.Font = Fonts.WorkSansBlack;
|
|
|
|
|
|
//riderNameView.SetName(rider.NameShort);
|
|
|
|
|
|
//switch (rider)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
//{
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// case GhostRider _:
|
|
|
|
|
|
// riderNameView.SetAvatarResourceIcon(AvatarView.IconType.Ghost);
|
|
|
|
|
|
// riderNameView.SetAvatarBorderColor(rider.UserColor);
|
|
|
|
|
|
// riderNameView.SetAvatarBorderWidth(2f);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// case StravaRider stravaRider:
|
|
|
|
|
|
// switch (stravaRider.EffortType)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
// {
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// case EffortType.Kom:
|
|
|
|
|
|
// riderNameView.SetAvatarResourceIcon(AvatarView.IconType.StravaKom);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// case EffortType.Qom:
|
|
|
|
|
|
// riderNameView.SetAvatarResourceIcon(AvatarView.IconType.StravaQom);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// case EffortType.Pr:
|
|
|
|
|
|
// riderNameView.SetAvatarResourceIcon(AvatarView.IconType.StravaPr);
|
|
|
|
|
|
// break;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
// }
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// riderNameView.SetAvatarBorderColor(Color.clear);
|
|
|
|
|
|
// riderNameView.SetAvatarBorderWidth(0.0f);
|
|
|
|
|
|
// break;
|
|
|
|
|
|
// default:
|
|
|
|
|
|
// riderNameView.SetAvatarUrl(rider.AvatarUrl);
|
|
|
|
|
|
// riderNameView.SetAvatarBorderColor(rider.UserColor);
|
|
|
|
|
|
// riderNameView.SetAvatarBorderWidth(2f);
|
|
|
|
|
|
// break;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
//}
|
2022-12-08 19:17:34 +08:00
|
|
|
|
//riderNameView.BackgroundColor = this.GetRiderTitleBackgroundColor(rider);
|
|
|
|
|
|
//riderNameView.SetCornerRadius(float.MaxValue);
|
|
|
|
|
|
//riderNameView.TrimSize();
|
|
|
|
|
|
//this.riderNameViews.Add(rider.Id, (UIRect)riderNameView);
|
|
|
|
|
|
//if (rider is StravaRider)
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//RiderValueView riderValueView = UIRect.Create<RiderValueView>(this.transform, "Value " + rider.Id.ToString());
|
|
|
|
|
|
//riderValueView.RectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
|
|
//riderValueView.gameObject.layer = 9;
|
|
|
|
|
|
//this.riderValueViews.Add(rider.Id, riderValueView);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void CreateRiderTitleObject(OnlineRiderModel rider)
|
|
|
|
|
|
{
|
|
|
|
|
|
//UIRect uiRect = UIRect.Create<UIRect>(this.transform, "TitleObject " + rider.Id.ToString());
|
|
|
|
|
|
//uiRect.Size = new Vector2(150f, 26f);
|
|
|
|
|
|
//uiRect.RectTransform.pivot = new Vector2(0.5f, 0.5f);
|
|
|
|
|
|
//uiRect.gameObject.layer = 9;
|
|
|
|
|
|
//uiRect.AddComponent<Canvas>().renderMode = RenderMode.WorldSpace;
|
|
|
|
|
|
//uiRect.AddComponent<BoxCollider>().size = (Vector3)uiRect.Size;
|
|
|
|
|
|
//this.riderNameViews.Add(rider.Id, uiRect);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void DestroyRiderTitle(int riderId)
|
|
|
|
|
|
{
|
|
|
|
|
|
//UIRect uiRect;
|
|
|
|
|
|
//if (this.riderNameViews.TryGetValue(riderId, out uiRect))
|
2022-12-05 18:29:49 +08:00
|
|
|
|
//{
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// this.riderNameViews.Remove(riderId);
|
|
|
|
|
|
// UnityEngine.Object.Destroy((UnityEngine.Object)uiRect.gameObject);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
//}
|
2022-12-08 19:17:34 +08:00
|
|
|
|
//RiderValueView riderValueView;
|
|
|
|
|
|
//if (!this.riderValueViews.TryGetValue(riderId, out riderValueView))
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//this.riderValueViews.Remove(riderId);
|
|
|
|
|
|
//UnityEngine.Object.Destroy((UnityEngine.Object)riderValueView.gameObject);
|
2022-12-05 18:29:49 +08:00
|
|
|
|
}
|
2022-12-08 19:17:34 +08:00
|
|
|
|
private void UpdateRidersVisibility()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!this.videoPlayer.Initialized)
|
|
|
|
|
|
return;
|
|
|
|
|
|
this.UpdateVisibleRiders();
|
|
|
|
|
|
return;
|
|
|
|
|
|
//删除当前道路上应该消失的骑手
|
|
|
|
|
|
foreach (int num in this.riderObjects.Keys.ToArray<int>())
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!this.visibleRiders.ContainsKey(num))
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
ARLaneGameObject riderObject = this.riderObjects[num];
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (!riderObject.IsAtFinish || (double)riderObject.VisibilityLevel <= 0.0)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.DestroyRider(num);
|
|
|
|
|
|
this.DestroyRiderTitle(num);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//新增应该显示的骑手
|
|
|
|
|
|
foreach (VisibleRiderItem visibleRiderItem in this.visibleRiders.Values)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rider = visibleRiderItem.Rider;
|
|
|
|
|
|
bool showModel = visibleRiderItem.ShowModel;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
ARLaneGameObject arLaneObject;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
//二次检查
|
|
|
|
|
|
if (this.riderObjects.TryGetValue(rider.UserId, out arLaneObject))
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
if (arLaneObject is AbstractRenderer)
|
2022-12-08 19:17:34 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (!showModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
float lane = arLaneObject.Lane;
|
|
|
|
|
|
this.DestroyRider(rider.UserId);
|
|
|
|
|
|
this.CreateRiderObject(rider, lane);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (showModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
float lane = arLaneObject.Lane;
|
|
|
|
|
|
this.DestroyRider(rider.UserId);
|
|
|
|
|
|
this.CreateRiderModel(rider, lane);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (showModel)
|
|
|
|
|
|
this.CreateRiderModel(rider, visibleRiderItem.Lane);
|
|
|
|
|
|
else
|
|
|
|
|
|
this.CreateRiderObject(rider, visibleRiderItem.Lane);
|
|
|
|
|
|
this.CreateRiderTitleObject(rider);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private void UpdateVisibleRiders()
|
|
|
|
|
|
{
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var visibilityModels = ARGameObject.MaxDistanceVisibilityModels;
|
|
|
|
|
|
var visibilityDistance = this.MaximumVisibilityDistance;
|
|
|
|
|
|
var routeDistance = this.CameraDistance;
|
|
|
|
|
|
var flag = this.AllowStartOrder && (double)routeDistance < 200.0;
|
|
|
|
|
|
var num1 = flag ? visibilityModels : visibilityDistance;
|
|
|
|
|
|
var a1 = this.videoPlayer.IsRear ? visibilityDistance : 1f;
|
|
|
|
|
|
var riderTitlesLimit = this.VisibleRiderTitlesLimit;
|
|
|
|
|
|
var a2 = 5;
|
|
|
|
|
|
|
|
|
|
|
|
var num2 = Mathf.Max(a1, this.GetOvertakingThreshold(routeDistance) + 1f);
|
|
|
|
|
|
var distance1 = routeDistance - num2;
|
|
|
|
|
|
var distance2 = routeDistance + num1;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
float num3;
|
|
|
|
|
|
if (flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
num3 = this.StartRegionRouteWidth;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var videoFrameAtDistance1 = this.videoSync.GetVideoFrameAtDistance(distance1);
|
|
|
|
|
|
var videoFrameAtDistance2 = this.videoSync.GetVideoFrameAtDistance(distance2);
|
2022-12-08 19:17:34 +08:00
|
|
|
|
num3 = (float)(0.5 * ((double)(this.Route.GetLeftSideOffset(videoFrameAtDistance1) + this.Route.GetRightSideOffset(videoFrameAtDistance1)) + (double)(this.Route.GetLeftSideOffset(videoFrameAtDistance2) + this.Route.GetRightSideOffset(videoFrameAtDistance2))));
|
|
|
|
|
|
}
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var num4 = num3 / 0.7f;
|
|
|
|
|
|
var num5 = this.paused ? 0.0f : 0.5f;
|
|
|
|
|
|
var maxLane = Math.Max(0.0f, num4 - num5);
|
|
|
|
|
|
var visibleRiderItemList1 = new List<VisibleRiderItem>();
|
|
|
|
|
|
var visibleRiderItemList2 = new List<VisibleRiderItem>();
|
|
|
|
|
|
|
2022-12-08 19:17:34 +08:00
|
|
|
|
var routeRiders = this.riders.Values;
|
2023-02-20 18:31:59 +08:00
|
|
|
|
|
2022-12-08 19:17:34 +08:00
|
|
|
|
foreach (var rider in routeRiders)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!rider.IsFinished)
|
|
|
|
|
|
{
|
2023-02-20 18:31:59 +08:00
|
|
|
|
float modelRouteDistance = this.GetRouteDistance(0, (float)rider.RouteDistance);
|
2022-12-08 19:17:34 +08:00
|
|
|
|
float num6 = modelRouteDistance - routeDistance;
|
|
|
|
|
|
if (this.IsMultilap)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((double)modelRouteDistance + this.lapLength >= (double)distance1 && (double)modelRouteDistance + this.lapLength <= (double)distance2)
|
|
|
|
|
|
num6 = modelRouteDistance + (float)this.lapLength - routeDistance;
|
|
|
|
|
|
else if ((double)modelRouteDistance - this.lapLength >= (double)distance1 && (double)modelRouteDistance - this.lapLength <= (double)distance2)
|
|
|
|
|
|
num6 = modelRouteDistance - (float)this.lapLength - routeDistance;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ((double)num6 > -(double)num2 && (double)num6 < (double)num1)
|
|
|
|
|
|
{
|
|
|
|
|
|
float num7 = -1f;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
ARLaneGameObject laneObject;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (this.riderObjects.TryGetValue(rider.UserId, out laneObject))
|
|
|
|
|
|
{
|
|
|
|
|
|
if ((double)laneObject.Lane > (double)num4)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.IsMainRider(rider))
|
|
|
|
|
|
{
|
|
|
|
|
|
laneObject.Lane = num4;
|
|
|
|
|
|
laneObject.DeltaLane = 0.0f;
|
|
|
|
|
|
this.UpdateRiderCurvature(laneObject, 0.0f, Time.deltaTime);
|
|
|
|
|
|
this.UpdateLaneChangingDirection(laneObject, 0.0f, Time.deltaTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
num7 = this.GetLane((float)rider.RouteDistance, modelRouteDistance);
|
|
|
|
|
|
if ((double)num7 > (double)maxLane)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.IsMainRider(rider))
|
|
|
|
|
|
num7 = num4;
|
|
|
|
|
|
else
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
VisibleRiderItem visibleRiderItem = new VisibleRiderItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
Rider = rider,
|
|
|
|
|
|
DeltaDistance = num6,
|
|
|
|
|
|
ModelDistance = modelRouteDistance,
|
|
|
|
|
|
Lane = num7
|
|
|
|
|
|
};
|
|
|
|
|
|
if ((double)num6 < 0.0)
|
|
|
|
|
|
visibleRiderItemList1.Add(visibleRiderItem);
|
|
|
|
|
|
else
|
|
|
|
|
|
visibleRiderItemList2.Add(visibleRiderItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
visibleRiderItemList1.Sort((Comparison<VisibleRiderItem>)((p1, p2) => p2.DeltaDistance.CompareTo(p1.DeltaDistance)));
|
|
|
|
|
|
visibleRiderItemList2.Sort((Comparison<VisibleRiderItem>)((p1, p2) => p1.DeltaDistance.CompareTo(p2.DeltaDistance)));
|
|
|
|
|
|
this.RemoveRidersOutside(visibleRiderItemList1, maxLane);
|
|
|
|
|
|
this.RemoveRidersOutside(visibleRiderItemList2, maxLane);
|
|
|
|
|
|
this.PrioritizeRider(visibleRiderItemList1, (Predicate<VisibleRiderItem>)(i => this.IsMainRider(i.Rider)));
|
|
|
|
|
|
this.PrioritizeRider(visibleRiderItemList2, (Predicate<VisibleRiderItem>)(i => this.IsMainRider(i.Rider)));
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var visibleRiderItemList3 = new List<VisibleRiderItem>();
|
2022-12-08 19:17:34 +08:00
|
|
|
|
if (!this.videoPlayer.IsRear)
|
|
|
|
|
|
{
|
|
|
|
|
|
int num8 = Mathf.Min(a2, visibleRiderItemList1.Count);
|
|
|
|
|
|
for (int index = 0; index < num8; ++index)
|
|
|
|
|
|
visibleRiderItemList3.Add(visibleRiderItemList1[index]);
|
|
|
|
|
|
int num9 = Mathf.Min(riderTitlesLimit - num8, visibleRiderItemList2.Count);
|
|
|
|
|
|
for (int index = 0; index < num9; ++index)
|
|
|
|
|
|
visibleRiderItemList3.Add(visibleRiderItemList2[index]);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
int num10 = Mathf.Min(a2, visibleRiderItemList2.Count);
|
|
|
|
|
|
for (int index = 0; index < num10; ++index)
|
|
|
|
|
|
visibleRiderItemList3.Add(visibleRiderItemList2[index]);
|
|
|
|
|
|
int num11 = Mathf.Min(riderTitlesLimit - num10, visibleRiderItemList1.Count);
|
|
|
|
|
|
for (int index = 0; index < num11; ++index)
|
|
|
|
|
|
visibleRiderItemList3.Add(visibleRiderItemList1[index]);
|
|
|
|
|
|
}
|
|
|
|
|
|
int num12 = 0;
|
|
|
|
|
|
this.visibleRiders.Clear();
|
|
|
|
|
|
foreach (VisibleRiderItem visibleRiderItem in visibleRiderItemList3)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rider = visibleRiderItem.Rider;
|
|
|
|
|
|
float num13 = Mathf.Abs(visibleRiderItem.DeltaDistance);
|
|
|
|
|
|
if ((double)num13 < (double)visibilityModels - 5.0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (num12 < this.VisibleModelsLimit)
|
|
|
|
|
|
{
|
|
|
|
|
|
visibleRiderItem.ShowModel = true;
|
|
|
|
|
|
this.visibleRiders.Add(rider.UserId, visibleRiderItem);
|
|
|
|
|
|
++num12;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if ((double)num13 < (double)visibilityDistance - 5.0 && this.visibleRiders.Count < this.VisibleRiderTitlesLimit)
|
|
|
|
|
|
{
|
|
|
|
|
|
visibleRiderItem.ShowModel = false;
|
|
|
|
|
|
this.visibleRiders.Add(rider.UserId, visibleRiderItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
this.VisibleModels = num12;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PrioritizeRider(
|
|
|
|
|
|
List<VisibleRiderItem> list,
|
|
|
|
|
|
Predicate<VisibleRiderItem> predicate)
|
|
|
|
|
|
{
|
|
|
|
|
|
int index = list.FindIndex(predicate);
|
|
|
|
|
|
if (index == -1)
|
|
|
|
|
|
return;
|
2023-02-20 18:31:59 +08:00
|
|
|
|
var visibleRiderItem = list[index];
|
2022-12-08 19:17:34 +08:00
|
|
|
|
list.RemoveAt(index);
|
|
|
|
|
|
list.Insert(0, visibleRiderItem);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void RemoveRidersOutside(
|
|
|
|
|
|
List<VisibleRiderItem> sortedList,
|
|
|
|
|
|
float maxLane)
|
|
|
|
|
|
{
|
|
|
|
|
|
VisibleRiderItem visibleRiderItem = (VisibleRiderItem)null;
|
|
|
|
|
|
foreach (VisibleRiderItem sorted in sortedList)
|
|
|
|
|
|
{
|
|
|
|
|
|
//排除当前骑行的主人公和分区组长
|
|
|
|
|
|
if ((double)sorted.Lane != -1.0 && !this.IsMainRider(sorted.Rider))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (visibleRiderItem == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
visibleRiderItem = sorted;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
float routeDistance1 = (float)visibleRiderItem.Rider.RouteDistance;
|
|
|
|
|
|
float routeDistance2 = (float)sorted.Rider.RouteDistance;
|
2023-01-31 18:22:15 +08:00
|
|
|
|
float collisionParameter = ARLaneGameObjectsController.GetCollisionParameter(routeDistance1, routeDistance2, this.GetOvertakingThreshold(routeDistance1));
|
2022-12-08 19:17:34 +08:00
|
|
|
|
sorted.Lane += collisionParameter;
|
|
|
|
|
|
if ((double)sorted.Lane > (double)maxLane)
|
|
|
|
|
|
sorted.Lane = float.MaxValue;
|
|
|
|
|
|
else
|
|
|
|
|
|
visibleRiderItem = sorted;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
sortedList.RemoveAll((Predicate<VisibleRiderItem>)(i => (double)i.Lane == 3.4028234663852886E+38));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool IsMainRider(OnlineRiderModel rider) => rider.IsSelf;
|
|
|
|
|
|
|
2022-12-05 18:29:49 +08:00
|
|
|
|
//更新骑手的偏移角度
|
|
|
|
|
|
private void UpdateRidersLean()
|
|
|
|
|
|
{
|
2023-01-31 18:22:15 +08:00
|
|
|
|
foreach (ARLaneGameObject riderObject in this.riderObjects.Values)
|
2022-12-05 18:29:49 +08:00
|
|
|
|
{
|
|
|
|
|
|
float num1 = this.Route.GetTrajectoryCurvature(riderObject.Frame) + riderObject.Curvature;
|
|
|
|
|
|
float z1;
|
|
|
|
|
|
if ((double)num1 == 0.0)
|
|
|
|
|
|
{
|
|
|
|
|
|
z1 = 0.0f;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
double speed = riderObject.Speed;
|
|
|
|
|
|
float f = 57.29578f * Mathf.Atan((float)(speed * speed * (double)num1 / 9.81));
|
|
|
|
|
|
float num2 = (double)f >= 0.0 ? 1f : -1f;
|
|
|
|
|
|
float num3 = Mathf.Abs(f);
|
|
|
|
|
|
if ((double)num3 > 20.0)
|
|
|
|
|
|
f = (float)((double)Mathf.Atan((float)(((double)num3 - 20.0) / 10.5)) * 10.5 + 20.0) * num2;
|
|
|
|
|
|
float num4 = Mathf.Clamp(f, -35f, 35f);
|
|
|
|
|
|
float z2 = riderObject.Lean.z;
|
|
|
|
|
|
z1 = Mathf.Clamp(num4, z2 - 60f * Time.deltaTime, z2 + 60f * Time.deltaTime);
|
|
|
|
|
|
}
|
|
|
|
|
|
float y = Mathf.Clamp(riderObject.LaneChangingDirection, -6f, 6f);
|
|
|
|
|
|
riderObject.Lean = new Vector3(0.0f, y, z1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//更新后背的光线
|
|
|
|
|
|
private void UpdateBackLight()
|
2023-03-08 18:33:33 +08:00
|
|
|
|
{
|
|
|
|
|
|
this.arBackLight.transform.position = this.UnityCamera.transform.position;
|
|
|
|
|
|
this.arBackLight.transform.rotation = this.UnityCamera.transform.rotation;
|
2022-12-05 18:29:49 +08:00
|
|
|
|
this.arLight.transform.rotation = this.Route.GetLightDirection(this.videoPlayer.CurrentFrame);
|
|
|
|
|
|
this.arLight.shadowStrength = this.Route.GetShadowIntensity(this.videoPlayer.CurrentFrame);
|
|
|
|
|
|
}
|
|
|
|
|
|
protected void LateUpdate() => this.UpdateRiderTitles();
|
|
|
|
|
|
|
|
|
|
|
|
private void UpdateRiderTitles()
|
|
|
|
|
|
{
|
|
|
|
|
|
//foreach (int key in this.riderNameViews.Keys)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// ARLaneObject riderObject = this.riderObjects[key];
|
|
|
|
|
|
// UIRect riderNameView = this.riderNameViews[key];
|
|
|
|
|
|
// RiderValueView riderValueView;
|
|
|
|
|
|
// this.riderValueViews.TryGetValue(key, out riderValueView);
|
|
|
|
|
|
// float num1 = Vector3.Distance(riderObject.transform.position, this.UnityCamera.transform.position);
|
|
|
|
|
|
// if (!riderObject.gameObject.activeSelf || (double)num1 > (double)this.MaximumVisibilityDistance || this.SelectedPanorama == null && (double)num1 < 3.0)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// riderNameView.Active = false;
|
|
|
|
|
|
// if ((UnityEngine.Object)riderValueView != (UnityEngine.Object)null)
|
|
|
|
|
|
// riderValueView.Active = false;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// else
|
|
|
|
|
|
// {
|
|
|
|
|
|
// riderNameView.Active = true;
|
|
|
|
|
|
// if ((UnityEngine.Object)riderValueView != (UnityEngine.Object)null)
|
|
|
|
|
|
// riderValueView.Active = (double)num1 < 30.0;
|
|
|
|
|
|
// float nameViewAlpha = this.GetNameViewAlpha(num1);
|
|
|
|
|
|
// if ((double)nameViewAlpha < 1.0)
|
|
|
|
|
|
// riderNameView.Alpha = nameViewAlpha;
|
|
|
|
|
|
// float t = this.GetValueViewAlpha(num1);
|
|
|
|
|
|
// if ((double)t < 1.0 && (UnityEngine.Object)riderValueView != (UnityEngine.Object)null)
|
|
|
|
|
|
// riderValueView.Alpha = t;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// //if (this.sportProfile == SportProfile.Running)
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // if ((UnityEngine.Object)riderValueView != (UnityEngine.Object)null)
|
|
|
|
|
|
// // riderValueView.Active = false;
|
|
|
|
|
|
// // t = 0.0f;
|
|
|
|
|
|
// //}
|
2022-12-05 18:29:49 +08:00
|
|
|
|
// Vector3 vector3 = 5f * this.uiScale * Mathf.Max(0.1f, this.SelectedPanorama != null ? 1f : this.GetDistanceScale(num1));
|
|
|
|
|
|
// Quaternion rotation = this.UnityCamera.transform.rotation;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
// //if (this.SelectedPanorama != null)
|
|
|
|
|
|
// //{
|
|
|
|
|
|
// // rotation = this.PanoramaCamera.transform.rotation;
|
|
|
|
|
|
// //}
|
|
|
|
|
|
// //else
|
2022-12-05 18:29:49 +08:00
|
|
|
|
// {
|
|
|
|
|
|
// if ((double)riderObject.Distance < (double)this.CameraDistance)
|
|
|
|
|
|
// rotation *= Quaternion.Euler(0.0f, 180f, 0.0f);
|
|
|
|
|
|
// if (this.videoPlayer.IsRear)
|
|
|
|
|
|
// rotation *= Quaternion.Euler(0.0f, 180f, 0.0f);
|
|
|
|
|
|
// }
|
|
|
|
|
|
// float num2 = Mathf.Lerp(-0.5f * this.Route.RiderScale, 0.6f * this.Route.RiderScale, Mathf.Clamp01(VTMath.Lerp(ARObject.MaxDistanceVisibilityModels - 5f, 1f, ARObject.MaxDistanceVisibilityModels, 0.0f, num1)));
|
|
|
|
|
|
// float num3 = 14f;
|
|
|
|
|
|
// float num4 = Mathf.Lerp(num2 + vector3.y * (0.5f * riderNameView.Height), num2 + vector3.y * (float)((double)num3 + 0.5 * (double)riderNameView.Height + 5.0), t);
|
|
|
|
|
|
// float num5 = -this.Route.RiderScale * riderObject.PositionOffset.y;
|
|
|
|
|
|
// riderNameView.transform.localScale = vector3;
|
|
|
|
|
|
// riderNameView.transform.position = riderObject.transform.position + rotation * new Vector3(0.0f, num4 + num5, 0.0f);
|
|
|
|
|
|
// riderNameView.transform.rotation = rotation;
|
|
|
|
|
|
// if ((UnityEngine.Object)riderValueView != (UnityEngine.Object)null)
|
|
|
|
|
|
// {
|
|
|
|
|
|
// float num6 = num2 + vector3.y * (0.5f * num3);
|
|
|
|
|
|
// riderValueView.transform.localScale = vector3;
|
|
|
|
|
|
// riderValueView.transform.position = riderObject.transform.position + rotation * new Vector3(0.0f, num6 + num5, 0.0f);
|
|
|
|
|
|
// riderValueView.transform.rotation = rotation;
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
|
|
//}
|
|
|
|
|
|
}
|
2022-12-09 16:45:54 +08:00
|
|
|
|
public void Pause() => this.paused = true;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
|
2022-12-09 16:45:54 +08:00
|
|
|
|
public void Resume() => this.paused = false;
|
2022-12-08 19:17:34 +08:00
|
|
|
|
|
|
|
|
|
|
private class VisibleRiderItem
|
|
|
|
|
|
{
|
|
|
|
|
|
public OnlineRiderModel Rider;
|
|
|
|
|
|
public float ModelDistance;
|
|
|
|
|
|
public float DeltaDistance;
|
|
|
|
|
|
public bool ShowModel;
|
|
|
|
|
|
public float Lane;
|
|
|
|
|
|
}
|
2022-12-05 18:29:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|