部分代码重构

This commit is contained in:
lishuo 2023-05-15 15:11:50 +08:00
parent 431d128ad8
commit 191efae2dd
46 changed files with 214 additions and 209 deletions

View File

@ -69,11 +69,6 @@ namespace Assets.AR
} }
} }
protected override void Awake()
{
base.Awake();
}
public void Initialize(bool male, bool timeTrialBike) public void Initialize(bool male, bool timeTrialBike)
{ {
this.Initialize(male); this.Initialize(male);
@ -186,7 +181,7 @@ namespace Assets.AR
{ {
var manager = FindObjectOfType<VideoGameManager>(); var manager = FindObjectOfType<VideoGameManager>();
var map = manager.GetMapRoute(); var map = manager.GetMapRoute();
if(map.Id == 6296) if(map.Id == 6296)//TODO:这里写死溧阳AR骑行
Lane = -2f; Lane = -2f;
} }
} }

View File

@ -441,7 +441,8 @@
"Next Time":"下次再说", "Next Time":"下次再说",
"DontNeedDownload":"当前视频下载完成后,下次进入线路就不需要重复下载.", "DontNeedDownload":"当前视频下载完成后,下次进入线路就不需要重复下载.",
"Not In Use":"禁用", "Not In Use":"禁用",
"CancelReadyToQuit":"请取消准备后再退出!" "CancelReadyToQuit":"请取消准备后再退出!",
"GetCloseGate": "已产生第一名,比赛倒计时"
}, },
"en": { "en": {
"REMAINING": "REMAINING", "REMAINING": "REMAINING",
@ -878,6 +879,7 @@
"Next Time":"Next Time", "Next Time":"Next Time",
"DontNeedDownload":"The same AR route video does not need to be downloaded again next time", "DontNeedDownload":"The same AR route video does not need to be downloaded again next time",
"Not In Use":"Not In Use", "Not In Use":"Not In Use",
"CancelReadyToQuit":"please cancel ready status and click quit!" "CancelReadyToQuit":"please cancel ready status and click quit!",
"GetCloseGate": "CountDown to the Competition"
} }
} }

View File

@ -226,7 +226,8 @@ public static class App
//TcpAddress = new IPEndPoint(IPAddress.Parse("192.168.0.102"), 21001); //TcpAddress = new IPEndPoint(IPAddress.Parse("192.168.0.102"), 21001);
Debug.unityLogger.logEnabled = false; Debug.unityLogger.logEnabled = false;
#else #else
Host = "http://pf.juze.pro/";//"http://pf.juze.pro/"; //"http://192.168.0.102:5082/";// Host = "http://192.168.0.98:6662/";
// Host = "http://pf.juze.pro/";//"http://pf.juze.pro/"; //"http://192.168.0.102:5082/";//
//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);
#endif #endif

View File

@ -142,7 +142,7 @@ namespace Assets.Scripts.Devices.Ble
{ {
discoveredDevices[device.Peripheral.Address].SignalStrength = device.Rssi; discoveredDevices[device.Peripheral.Address].SignalStrength = device.Rssi;
discoveredDevices[device.Peripheral.Address].LastActiveTime = DateTime.Now; discoveredDevices[device.Peripheral.Address].LastActiveTime = DateTime.Now;
Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }"); //Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }");
} }
}); });
} }

View File

@ -3,12 +3,7 @@ using Mapbox.Unity.MeshGeneration.Data;
using Mapbox.Utils; using Mapbox.Utils;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
namespace Assets.Scripts.Scenes.VideoRide namespace Assets.Scripts.Scenes.VideoRide
{ {
@ -20,69 +15,79 @@ namespace Assets.Scripts.Scenes.VideoRide
Camera _minicamera; Camera _minicamera;
[SerializeField] [SerializeField]
GameObject _player; GameObject _player;
VideoGameManager cyclingCotroller;
public AbstractVideoPlayer playerController { get; set; }
GameObject _mipMapRoute; GameObject _mipMapRoute;
public RectTransform RectRoot { get; set; } public RectTransform RectRoot { get; set; }
TrailRenderer trail; TrailRenderer trail;
Transform uitransform { get; set; } Transform uitransform { get; set; }
void Start() private bool init { get; set; } = false;
private float timer { get; set; } = 0f;
private GameObject _mipMapPath;
private Material pathMaterial { get; set; }
VideoGameManager cyclingCotroller;
public AbstractVideoPlayer playerController { get; set; }
private void Start()
{ {
cyclingCotroller = FindObjectOfType<VideoGameManager>(); cyclingCotroller = FindObjectOfType<VideoGameManager>();
if (cyclingCotroller != null) if (cyclingCotroller != null)
{ {
playerController = cyclingCotroller.CurrentPlayer; playerController = cyclingCotroller.CurrentPlayer;
var mapdata = cyclingCotroller.GetMapData(); var map = cyclingCotroller.GetMapData();
//初始化map //初始化map
//var point = cyclingCotroller.GetCenterCoordinate(); if (_map != null && map != null)
if (_map != null && mapdata != null)
{ {
_map.OnInitialized += _map_OnInitialized; _map.OnInitialized += _map_OnInitialized;
_map.OnUpdated += _map_OnUpdated; _map.OnUpdated += _map_OnUpdated;
_map.Initialize(new Vector2d(mapdata.Center[0], mapdata.Center[1]), 12); _map.Initialize(new Vector2d(map.Center[0], map.Center[1]), 12);
var bbox = mapdata.Bbox; var bbox = map.Bbox;
var targetbounds = new Vector2dBounds(new Vector2d(bbox[1], bbox[0]), new Vector2d(bbox[3], bbox[2])); var bounds = new Vector2dBounds(new Vector2d(bbox[1], bbox[0]), new Vector2d(bbox[3], bbox[2]));
var screenBounds = GetScreenBounds(); var screenBounds = GetScreenBounds();
var z = SetZoomToFitBounds(targetbounds, screenBounds); var z = SetZoomToFitBounds(bounds, screenBounds);
} }
uitransform = cyclingCotroller.GetCanvasTransform(); uitransform = cyclingCotroller.GetCanvasTransform();
RectRoot = uitransform.Find("MiniMap/MiniMap").GetComponent<RectTransform>(); RectRoot = uitransform.Find("MiniMap/MiniMap").GetComponent<RectTransform>();
} }
pathMaterial = Resources.Load<Material>("UI/Material/2");
SetTrailRender();
}
//设置小地图上人物移动路径
private void SetTrailRender()
{
trail = transform.parent.Find("Sphere").GetComponent<TrailRenderer>(); trail = transform.parent.Find("Sphere").GetComponent<TrailRenderer>();
trail.startWidth = 5f; trail.startWidth = 5f;
trail.endWidth = 5f; trail.endWidth = 5f;
trail.startColor = new Color(0.9764706f, 0.1882353f, 0.5254902f, 1f); trail.startColor = new Color(0.9764706f, 0.1882353f, 0.5254902f, 1f);
trail.endColor = new Color(0.9764706f, 0.1882353f, 0.5254902f, 1f); trail.endColor = new Color(0.9764706f, 0.1882353f, 0.5254902f, 1f);
} }
float timer = 0f;
private void Update() private void Update()
{ {
if (cyclingCotroller.CurrentPlayer != null) if (cyclingCotroller.CurrentPlayer == null) return;
uitransform = cyclingCotroller.GetCanvasTransform();
var tr = uitransform.Find("MiniMap/MiniMap/arrow");
tr.SetSiblingIndex(9999);
var pos = _map.GeoToWorldPosition(cyclingCotroller.CurrentPlayer.currentlatLon);
pos.y += 15f;
_player.transform.localPosition = pos;
var vp2 = _minicamera.WorldToViewportPoint(_player.transform.localPosition);//将三维物体的世界坐标转换为视口坐标
((RectTransform)tr.transform).anchoredPosition = new Vector2((vp2.x * RectRoot.sizeDelta.x) - (RectRoot.sizeDelta.x * 0.5f), (vp2.y * RectRoot.sizeDelta.y) - (RectRoot.sizeDelta.y * 0.5f));
trail.enabled = cyclingCotroller.CurrentPlayer.power > 0;
timer += Time.deltaTime;
while (timer >= 1)
{ {
uitransform = cyclingCotroller.GetCanvasTransform(); CreateMiniPath();
var tr = uitransform.Find("MiniMap/MiniMap/arrow"); timer = 0;
tr.SetSiblingIndex(9999);
var pos = _map.GeoToWorldPosition(cyclingCotroller.CurrentPlayer.currentlatLon);
pos.y += 15f;
_player.transform.localPosition = pos;
Vector2 vp2 = _minicamera.WorldToViewportPoint(_player.transform.localPosition);//将三维物体的世界坐标转换为视口坐标
((RectTransform)tr.transform).anchoredPosition = new Vector2((vp2.x * RectRoot.sizeDelta.x) - (RectRoot.sizeDelta.x * 0.5f), (vp2.y * RectRoot.sizeDelta.y) - (RectRoot.sizeDelta.y * 0.5f));
trail.enabled = cyclingCotroller.CurrentPlayer.power > 0;
timer += Time.deltaTime;
while (timer >= 1)
{
CreateMiniPath();
timer = 0;
}
} }
} }
private bool init = false;
private void _map_OnInitialized() private void _map_OnInitialized()
{ {
init = true; init = true;
@ -94,10 +99,8 @@ namespace Assets.Scripts.Scenes.VideoRide
} }
}; };
} }
#region Camera
/// <summary> /// <summary>
/// https://github.com/mapbox/mapbox-unity-sdk/issues/1580 /// https://github.com/mapbox/mapbox-unity-sdk/issues/1580
/// </summary> /// </summary>
@ -123,6 +126,7 @@ namespace Assets.Scripts.Scenes.VideoRide
_map.UpdateMap(); _map.UpdateMap();
return (int)Math.Floor(zoom); return (int)Math.Floor(zoom);
} }
private Vector2dBounds GetScreenBounds() private Vector2dBounds GetScreenBounds()
{ {
var screenWidth = UnityEngine.Screen.width; var screenWidth = UnityEngine.Screen.width;
@ -135,76 +139,82 @@ namespace Assets.Scripts.Scenes.VideoRide
return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y)); return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y));
} }
#endregion
#region 线
private void _map_OnUpdated() private void _map_OnUpdated()
{ {
CreateMiniRoute(); CreateMiniRoute();
} }
void CreateMiniRoute()
private void CreateMiniRoute()
{
var dat = new List<Vector3>();
var mapData = cyclingCotroller.GetMapData();
if (mapData == null) return;
var count = mapData.List.Count;
var interval = Math.Max(Math.Ceiling(count / 100D), 1f);
for (var i = 0; i < mapData.List.Count; i++)
{
if (i % interval == 0)
{
var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
item.y += 1f;
dat.Add(item);
}
}
//创建小地图路线
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
CreateLineRender(feat);
}
private void CreateMiniPath()
{ {
var meshData = new MeshData();
var dat = new List<Vector3>(); var dat = new List<Vector3>();
var mapData = cyclingCotroller.GetMapData(); var mapData = cyclingCotroller.GetMapData();
if (mapData != null) if (mapData == null) return;
var count = mapData.List.Count;
var interval = Math.Max(Math.Ceiling(count / 100D), 1f);
for (int i = 0; i < mapData.List.Count; i++)
{ {
var count = mapData.List.Count; if (i % interval == 0)
var interval = Math.Max(Math.Ceiling(count / 100D), 1f);
for (int i = 0; i < mapData.List.Count; i++)
{ {
if (i % interval == 0) var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
item.y += 5f;
if (cyclingCotroller.CurrentPlayer.currentIndex >= i)
{ {
var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
item.y += 1f;
dat.Add(item); dat.Add(item);
} }
} }
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
CreateLineRender(feat);//创建小地图路线
} }
//创建路径
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
CreateRedLineRender(feat);
} }
void CreateMiniPath()
{
var dat = new List<Vector3>();
var mapData = cyclingCotroller.GetMapData();
if (mapData != null)
{
var count = mapData.List.Count;
var interval = Math.Max(Math.Ceiling(count / 100D), 1f);
for (int i = 0; i < mapData.List.Count; i++)
{
if (i % interval == 0)
{
var point = mapData.List[i].Point;
Vector3 item = _map.GeoToWorldPosition(new Vector2d(point[0], point[1]));
item.y += 5f;
if (cyclingCotroller.CurrentPlayer.currentIndex >= i)
{
dat.Add(item);
}
}
}
var feat = new VectorFeatureUnity();
feat.Points.Add(dat);
CreateRedLineRender(feat);//创建小地图路线
}
}
//创建小地图路线 //创建小地图路线
void CreateLineRender(VectorFeatureUnity feat) private void CreateLineRender(VectorFeatureUnity feat)
{ {
if (_mipMapRoute != null) if (_mipMapRoute != null)
{ {
_mipMapRoute.Destroy(); _mipMapRoute.Destroy();
} }
_mipMapRoute = new GameObject("MiniMapRoute");
_mipMapRoute.transform.parent = transform.parent;
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
lineRender.material = Instantiate(Resources.Load<Material>("UI/Material/1")); _mipMapRoute = new GameObject("MiniMapRoute")
{
transform =
{
parent = transform.parent
}
};
var lineRender = _mipMapRoute.AddComponent<LineRenderer>();
lineRender.material = Resources.Load<Material>("UI/Material/1");
var dat = feat.Points[0]; var dat = feat.Points[0];
lineRender.endColor = Color.white; lineRender.endColor = Color.white;
lineRender.startColor = Color.white; lineRender.startColor = Color.white;
@ -219,18 +229,23 @@ namespace Assets.Scripts.Scenes.VideoRide
_mipMapRoute.layer = 9; _mipMapRoute.layer = 9;
_map.gameObject.SetActive(false); _map.gameObject.SetActive(false);
} }
GameObject _mipMapPath;
void CreateRedLineRender(VectorFeatureUnity feat) private void CreateRedLineRender(VectorFeatureUnity feat)
{ {
if (_mipMapPath != null) if (_mipMapPath != null)
{ {
_mipMapPath.Destroy(); _mipMapPath.Destroy();
} }
_mipMapPath = new GameObject("MiniMapPath"); _mipMapPath = new GameObject("MiniMapPath")
_mipMapPath.transform.parent = transform.parent; {
transform =
{
parent = transform.parent
}
};
var lineRender = _mipMapPath.AddComponent<LineRenderer>(); var lineRender = _mipMapPath.AddComponent<LineRenderer>();
lineRender.material = Instantiate(Resources.Load<Material>("UI/Material/2")); lineRender.material = pathMaterial;
var dat = feat.Points[0]; var dat = feat.Points[0];
lineRender.endColor = Color.red; lineRender.endColor = Color.red;
lineRender.startColor = Color.red; lineRender.startColor = Color.red;
@ -244,6 +259,6 @@ namespace Assets.Scripts.Scenes.VideoRide
lineRender.loop = false; lineRender.loop = false;
_mipMapPath.layer = 9; _mipMapPath.layer = 9;
} }
#endregion
} }
} }

View File

@ -4,30 +4,17 @@ namespace Assets.Scripts.Scenes.VideoRide
{ {
public class OnlineVideoPlayer : AbstractVideoPlayer public class OnlineVideoPlayer : AbstractVideoPlayer
{ {
protected override void Start()
{
base.Start();
}
protected override void Update()
{
base.Update();
}
public override void ComputeAnimator()
{
base.ComputeAnimator();
}
public override void ComputeAnimatorSpeed()
{
base.ComputeAnimatorSpeed();
}
public override void CreateHeadImage() public override void CreateHeadImage()
{ {
base.CreateHeadImage(); base.CreateHeadImage();
if (Diff < 0) if (Diff < 0)
((RectTransform)head.transform).anchoredPosition = new Vector2(((RectTransform)head.transform).anchoredPosition.x, -800f); HideHeadRectTransform();
}
//隐藏其他玩家的头像
private void HideHeadRectTransform()
{
((RectTransform)head.transform).anchoredPosition = new Vector2(((RectTransform)head.transform).anchoredPosition.x, -800f);
} }
public override void SetPlayer(string name, double speed, double preDistance, double endDistance, double cadance, double heartRate, double wkg, int userId, double power, double currentPlayerDistance, int frame) public override void SetPlayer(string name, double speed, double preDistance, double endDistance, double cadance, double heartRate, double wkg, int userId, double power, double currentPlayerDistance, int frame)

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: bdac326eaff04872bcebc003689d480b
timeCreated: 1683888648

View File

@ -1,9 +1,6 @@
using PolyAndCode.UI; using PolyAndCode.UI;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -24,6 +21,7 @@ namespace Assets.Scripts.Scenes.VideoRide
public string Id; public string Id;
public string Rank; public string Rank;
public string Name; public string Name;
private float timer = 1f;
private VideoGameManager manager { get; set; } private VideoGameManager manager { get; set; }
private void Start() private void Start()
@ -31,7 +29,7 @@ namespace Assets.Scripts.Scenes.VideoRide
manager = FindObjectOfType<VideoGameManager>(); manager = FindObjectOfType<VideoGameManager>();
GetComponent<Button>().onClick.AddListener(ButtonListener); GetComponent<Button>().onClick.AddListener(ButtonListener);
} }
private float timer = 1f;
private void Update() private void Update()
{ {
timer -= Time.deltaTime; timer -= Time.deltaTime;
@ -42,7 +40,7 @@ namespace Assets.Scripts.Scenes.VideoRide
var riders = manager.cyclingController?.riders; var riders = manager.cyclingController?.riders;
if (riders != null) if (riders != null)
{ {
var current = riders.Where(c => c.UserId.ToString() == Id).FirstOrDefault(); var current = riders.FirstOrDefault(c => c.UserId.ToString() == Id);
if (current == null) if (current == null)
{ {
gameObject.SetActive(false); gameObject.SetActive(false);
@ -50,7 +48,6 @@ namespace Assets.Scripts.Scenes.VideoRide
} }
} }
} }
timer += 1f; timer += 1f;
} }
} }
@ -66,8 +63,8 @@ namespace Assets.Scripts.Scenes.VideoRide
genderLabel.text = contactInfo.Gender; genderLabel.text = contactInfo.Gender;
idLabel.text = contactInfo.id; idLabel.text = contactInfo.id;
powerLabel.text = contactInfo.Power.ToString("f0") + "W"; powerLabel.text = contactInfo.Power.ToString("f0") + "W";
//master.SetActive(manager.CurrentPlayer.UserId.ToString() == contactInfo.id);
} }
public void UpdateItem(string name,string gender,string id) public void UpdateItem(string name,string gender,string id)
{ {
nameLabel.text = name; nameLabel.text = name;
@ -75,6 +72,7 @@ namespace Assets.Scripts.Scenes.VideoRide
idLabel.text = id; idLabel.text = id;
master.SetActive(manager.CurrentPlayer?.UserId.ToString() == id); master.SetActive(manager.CurrentPlayer?.UserId.ToString() == id);
} }
private void ButtonListener() private void ButtonListener()
{ {
if(manager._aRMode == VideoGameManager.ARMode.INSPECT) if(manager._aRMode == VideoGameManager.ARMode.INSPECT)

View File

@ -1,10 +1,4 @@
using Assets.Scripts; using UnityEngine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
namespace Assets.Scripts.Scenes.VideoRide namespace Assets.Scripts.Scenes.VideoRide

View File

@ -1,16 +1,11 @@
using System; using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.EventSystems; using UnityEngine.EventSystems;
using DG.Tweening; using DG.Tweening;
using UnityEngine.UI; using UnityEngine.UI;
namespace Assets.Scripts.Scenes.VideoRide namespace Assets.Scripts.Scenes.VideoRide
{ {
class RankingScript: MonoBehaviour public class RankingScript: MonoBehaviour
{ {
GameObject Hide { get; set; } GameObject Hide { get; set; }
GameObject Show { get; set; } GameObject Show { get; set; }
@ -30,24 +25,29 @@ namespace Assets.Scripts.Scenes.VideoRide
Month = transform.Find("Head/Month").gameObject; Month = transform.Find("Head/Month").gameObject;
Week = transform.Find("Head/Week").gameObject; Week = transform.Find("Head/Week").gameObject;
Day = transform.Find("Head/Day").gameObject; Day = transform.Find("Head/Day").gameObject;
MonthTxt = transform.Find("Head/Month/Text").GetComponent<Text>(); MonthTxt = transform.Find("Head/Month/Text").GetComponent<Text>();
MonthTxt.color = Color.red; MonthTxt.color = Color.red;
WeekTxt = transform.Find("Head/Week/Text").GetComponent<Text>(); WeekTxt = transform.Find("Head/Week/Text").GetComponent<Text>();
DayTxt = transform.Find("Head/Day/Text").GetComponent<Text>(); DayTxt = transform.Find("Head/Day/Text").GetComponent<Text>();
manager = FindObjectOfType<VideoGameManager>(); manager = FindObjectOfType<VideoGameManager>();
Container = transform.Find("List/Viewport/Content");
Month.GetComponent<Text>();
UIManager.AddEvent(Hide, UnityEngine.EventSystems.EventTriggerType.PointerClick, Hidehandler); UIManager.AddEvent(Hide, UnityEngine.EventSystems.EventTriggerType.PointerClick, Hidehandler);
UIManager.AddEvent(Show, UnityEngine.EventSystems.EventTriggerType.PointerClick, Showhandler); UIManager.AddEvent(Show, UnityEngine.EventSystems.EventTriggerType.PointerClick, Showhandler);
UIManager.AddEvent(Month, UnityEngine.EventSystems.EventTriggerType.PointerClick, MonthClick); UIManager.AddEvent(Month, UnityEngine.EventSystems.EventTriggerType.PointerClick, MonthClick);
UIManager.AddEvent(Week, UnityEngine.EventSystems.EventTriggerType.PointerClick, WeekClick); UIManager.AddEvent(Week, UnityEngine.EventSystems.EventTriggerType.PointerClick, WeekClick);
UIManager.AddEvent(Day, UnityEngine.EventSystems.EventTriggerType.PointerClick, DayClick); UIManager.AddEvent(Day, UnityEngine.EventSystems.EventTriggerType.PointerClick, DayClick);
Container = transform.Find("List/Viewport/Content");
Month.GetComponent<Text>();
#if UNITY_EDITOR #if UNITY_EDITOR
UIManager.InitNow();//重置当前时间 UIManager.InitNow();//重置当前时间
#endif #endif
Refresh(); Refresh();
} }
//TODO: 重构
private void Refresh(string type = "month") private void Refresh(string type = "month")
{ {
return; return;

View File

@ -1,5 +1,4 @@
using UnityEngine; using UnityEngine.UI;
using UnityEngine.UI;
namespace Assets.Scripts.Scenes.VideoRide namespace Assets.Scripts.Scenes.VideoRide
{ {
@ -8,10 +7,11 @@ namespace Assets.Scripts.Scenes.VideoRide
public Slider PowerSlider; public Slider PowerSlider;
public Text PowerText; public Text PowerText;
private VideoGameManager manager; private VideoGameManager manager;
// Start is called before the first frame update
void Start() void Start()
{ {
manager = FindObjectOfType<VideoGameManager>(); manager = FindObjectOfType<VideoGameManager>();
//设置模拟功率
PowerSlider.onValueChanged.AddListener(e => PowerSlider.onValueChanged.AddListener(e =>
{ {
PowerText.text = e.ToString("f0") + "W"; PowerText.text = e.ToString("f0") + "W";

View File

@ -1,6 +1,4 @@
using PolyAndCode.UI; using PolyAndCode.UI;
using System;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -36,5 +34,4 @@ namespace Assets.Scripts.Scenes.VideoRide
} }
} }
} }
} }

View File

@ -13,14 +13,19 @@ namespace Assets.Scripts.Scenes.VideoRide
{ {
public class VideoUIManager : MonoBehaviour public class VideoUIManager : MonoBehaviour
{ {
private const float MAXPOWER = 450f;
private const float MAXPOWER_RATE = 600f;
private const float MAXHEARRATE = 200f;
private const float MAXWKG = 6f;
private const float MAX_HEART_RATIO = 0.9f;
GameObject ComputerPanel { get; set; }
GameObject WatchPanel { get; set; }
GameObject explosive { get; set; }
GameObject button; GameObject button;
GameObject remainTime; GameObject remainTime;
VideoGameManager manager; VideoGameManager manager;
VideoPlayer videoPlayer; VideoPlayer videoPlayer;
const float MAXPOWER = 450f;
const float MAXPOWER_RATE = 600f;
const float MAXHEARRATE = 200f;
const float MAXWKG = 6f;
Text infoText { get; set; } Text infoText { get; set; }
//ComputerPanel //ComputerPanel
Text power { get; set; } Text power { get; set; }
@ -54,19 +59,17 @@ namespace Assets.Scripts.Scenes.VideoRide
Image ftpImage { get; set; } Image ftpImage { get; set; }
Text wkg { get; set; } Text wkg { get; set; }
// Start is called before the first frame update private void Start()
void Start()
{ {
UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>()); UIManager.SetModalPanel(transform.Find("ModalPanel").GetComponent<PFUIPanel>());
manager = FindObjectOfType<VideoGameManager>(); manager = FindObjectOfType<VideoGameManager>();
Init(); Init();
} }
// Update is called once per frame
void Update() private void Update()
{ {
if (manager != null) if (manager != null)
{ {
mapName.text = manager.GetMapRoute().Name; mapName.text = manager.GetMapRoute().Name;
if (manager.CurrentPlayer != null) if (manager.CurrentPlayer != null)
{ {
@ -81,19 +84,25 @@ namespace Assets.Scripts.Scenes.VideoRide
SetSlopePanel(); SetSlopePanel();
ftpImage.fillAmount = (float)(manager.CurrentPlayer.wkg / MAXWKG); ftpImage.fillAmount = (float)(manager.CurrentPlayer.wkg / MAXWKG);
wkg.text = $"{manager.CurrentPlayer.wkg}w/kg"; wkg.text = $"{manager.CurrentPlayer.wkg}w/kg";
//心率过高的时候显示 SetHeartRateAlert();
if (manager.CurrentPlayer.UserId == App.CurrentUser.Id)
{
explosive.SetActive(ComputeHearRateRatio(manager.CurrentPlayer.heartRate ?? 0) > MAX_HEART_RATIO);
}
else
{
explosive.SetActive(false);
}
} }
} }
} }
//心率过高的时候显示
private void SetHeartRateAlert()
{
if (manager.CurrentPlayer.UserId == App.CurrentUser.Id)
{
explosive.SetActive(ComputeHearRateRatio(manager.CurrentPlayer.heartRate ?? 0) > MAX_HEART_RATIO);
}
else
{
explosive.SetActive(false);
}
}
//距离终点
public void ShowUpRemainTime(double remain) public void ShowUpRemainTime(double remain)
{ {
if (remain > 110) return; if (remain > 110) return;
@ -116,10 +125,9 @@ namespace Assets.Scripts.Scenes.VideoRide
} }
} }
private const float MAX_HEART_RATIO = 0.9f; // 220 - 年龄= 最大心率 ratio = heartRate /最大心率
private float ComputeHearRateRatio(int heartRate) private float ComputeHearRateRatio(int heartRate)
{ {
// 220 - 年龄= 最大心率 ratio = heartRate /最大心率
var age = DateTime.Now.Year - App.CurrentUser.Birthday?.Year; var age = DateTime.Now.Year - App.CurrentUser.Birthday?.Year;
if (DateTime.Now.Month - App.CurrentUser.Birthday?.Month > 0 && DateTime.Now.Day - App.CurrentUser.Birthday?.Day > 0) if (DateTime.Now.Month - App.CurrentUser.Birthday?.Month > 0 && DateTime.Now.Day - App.CurrentUser.Birthday?.Day > 0)
{ {
@ -143,9 +151,7 @@ namespace Assets.Scripts.Scenes.VideoRide
ComputerPanel.SetActive(true); ComputerPanel.SetActive(true);
} }
} }
GameObject ComputerPanel { get; set; }
GameObject WatchPanel { get; set; }
GameObject explosive { get; set; }
private void Init() private void Init()
{ {
remainTime = transform.Find("Panel/Remain").gameObject; remainTime = transform.Find("Panel/Remain").gameObject;
@ -242,7 +248,7 @@ namespace Assets.Scripts.Scenes.VideoRide
manager._viewMode = manager._viewMode == ViewMode.THIRD ? ViewMode.FIRST : ViewMode.THIRD; manager._viewMode = manager._viewMode == ViewMode.THIRD ? ViewMode.FIRST : ViewMode.THIRD;
if (manager._viewMode == ViewMode.FIRST) if (manager._viewMode == ViewMode.FIRST)
{ {
ftpPanel.SetActive(true); ftpPanel.SetActive(manager._aRMode != ARMode.INSPECT);
nearByScript.Hidehandler(null); nearByScript.Hidehandler(null);
rankingScript.Hidehandler(null); rankingScript.Hidehandler(null);
cameraImage.SetActive(true); cameraImage.SetActive(true);

View File

@ -3,10 +3,10 @@ using UnityEngine.UI;
namespace Assets.Scripts.Scenes.VideoRide namespace Assets.Scripts.Scenes.VideoRide
{ {
class WatchPanelScript:MonoBehaviour public class WatchPanelScript:MonoBehaviour
{ {
VideoGameManager manager { get; set; } private VideoGameManager manager { get; set; }
Text userName { get; set; } private Text userName { get; set; }
private void Start() private void Start()
{ {
manager = FindObjectOfType<VideoGameManager>(); manager = FindObjectOfType<VideoGameManager>();

View File

@ -37,26 +37,16 @@ namespace Assets.Scripts.Scenes.VideoRide
public CyclingModel cyclingModel { get; set; } public CyclingModel cyclingModel { get; set; }
public BaseCycling cyclingController { get; set; } public BaseCycling cyclingController { get; set; }
private double endDistance { get; set; } private double endDistance { get; set; }
GameObject infoPanel; private GameObject infoPanel;
GameObject Player; private GameObject Player;
GameObject Player_NV; private GameObject Player_NV;
GameObject OnlinePlayer; private GameObject OnlinePlayer;
GameObject OnlinePlayer_NV; private GameObject OnlinePlayer_NV;
private bool isStop { get; set; }
public enum ARMode private bool isStop { get; set; }
{
RIDE,
INSPECT
}
public enum ViewMode
{
THIRD,
FIRST,
}
VideoLoading videoLoading { get; set; } VideoLoading videoLoading { get; set; }
//当前是第一人称还是第三人称 //当前是第一人称还是第三人称
public ViewMode _viewMode { get; set; } public ViewMode _viewMode { get; set; }
//当前是观察者视角还是骑行者视角 //当前是观察者视角还是骑行者视角
@ -436,20 +426,24 @@ namespace Assets.Scripts.Scenes.VideoRide
{ {
if (cyclingController.recorderData == null || cyclingController.recorderData.Saved) if (cyclingController.recorderData == null || cyclingController.recorderData.Saved)
return; return;
Quit(); Quit();
cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime(); cyclingController.recorderData.EndTime = UIManager.Now.GetDateTime();
var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId; var path = PFConstants.MapWorkoutRecordFolder + "/" + recordId;
Assets.Scenes.Ride.Scripts.Helper.CreateDirectoryIfNotExsit(path); Helper.CreateDirectoryIfNotExsit(path);
string imageFileName = path + "/" + Guid.NewGuid().ToString() + ".png"; var imageFileName = path + "/" + Guid.NewGuid().ToString() + ".png";
Helper.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName); Helper.CaptureCamera(Camera.main, new Rect(Screen.width * 0f, Screen.height * 0f, Screen.width * 0.5f, Screen.height * 0.5f), imageFileName);
cyclingController.recorderData.StartTime = startTime; cyclingController.recorderData.StartTime = startTime;
cyclingController.recorderData.IsCompleted = totalDistance >= mapData.TotalDistance; cyclingController.recorderData.IsCompleted = totalDistance >= mapData.TotalDistance;
cyclingController.recorderData.EndDistance = totalDistance; cyclingController.recorderData.EndDistance = cyclingController.recorderData.IsCompleted ? mapData.TotalDistance : totalDistance;
cyclingController.recorderData.AntModelId = AntModelId; cyclingController.recorderData.AntModelId = AntModelId;
cyclingController.recorderData.ManufacturerId = ManufacturerId; cyclingController.recorderData.ManufacturerId = ManufacturerId;
cyclingController.recorderData.ManufacturerName = ManufacturerName; cyclingController.recorderData.ManufacturerName = ManufacturerName;
cyclingController.recorderData.DeviceNumber = DeviceNumber; cyclingController.recorderData.DeviceNumber = DeviceNumber;
cyclingController.recorderData.LastFrame = GetCurrentFrame(); cyclingController.recorderData.LastFrame = GetCurrentFrame();
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)
@ -483,5 +477,17 @@ namespace Assets.Scripts.Scenes.VideoRide
{ {
App.gameRoomDetail = null; App.gameRoomDetail = null;
} }
public enum ARMode
{
RIDE,
INSPECT
}
public enum ViewMode
{
THIRD,
FIRST,
}
} }
} }

View File

@ -10,6 +10,8 @@ namespace Assets.Scripts.Scenes.VideoRide
{ {
private bool isSingle = true; private bool isSingle = true;
VideoUIManager _uimanager; VideoUIManager _uimanager;
private bool gameRoomHandled { get; set; }
protected override void Start() protected override void Start()
{ {
base.Start(); base.Start();
@ -62,7 +64,7 @@ namespace Assets.Scripts.Scenes.VideoRide
//比人先完成触发关门时间 //比人先完成触发关门时间
HandleForGameRoom(); HandleForGameRoom();
} }
private bool gameRoomHandled { get; set; }
//房间倒计时保存 //房间倒计时保存
private void HandleForGameRoom() private void HandleForGameRoom()
{ {

View File

@ -1,10 +1,6 @@
using Assets.Scenes.Ride.Scripts; using Assets.Scenes.Ride.Scripts;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
namespace Assets.Scripts.Scenes namespace Assets.Scripts.Scenes
@ -13,11 +9,11 @@ namespace Assets.Scripts.Scenes
{ {
UnityEngine.Ping ping; UnityEngine.Ping ping;
bool isNetWorkLose = false; bool isNetWorkLose = false;
protected virtual void Awake() protected virtual void Awake()
{ {
Debug.Log("base scene awake");
Application.logMessageReceived += Application_logMessageReceived; Application.logMessageReceived += Application_logMessageReceived;
StopCoroutine("Ping"); StopCoroutine(Ping());
StartCoroutine(Ping()); StartCoroutine(Ping());
} }
@ -32,7 +28,6 @@ namespace Assets.Scripts.Scenes
private void Application_logMessageReceived(string condition, string stackTrace, LogType type) private void Application_logMessageReceived(string condition, string stackTrace, LogType type)
{ {
//Debug.Log("application log");
if (type == LogType.Error || type == LogType.Exception) if (type == LogType.Error || type == LogType.Exception)
{ {
string log = $"time:{ System.DateTime.Now.ToString() }\r\n"; string log = $"time:{ System.DateTime.Now.ToString() }\r\n";
@ -40,8 +35,6 @@ namespace Assets.Scripts.Scenes
log += $"msg:{ condition }\r\n"; log += $"msg:{ condition }\r\n";
log += $"stack trace:{ stackTrace }\r\n"; log += $"stack trace:{ stackTrace }\r\n";
System.IO.File.AppendAllText($"{PFConstants.LogFolder}\\{ System.DateTime.Now.ToString("yyyy-MM-dd") }.txt", log); System.IO.File.AppendAllText($"{PFConstants.LogFolder}\\{ System.DateTime.Now.ToString("yyyy-MM-dd") }.txt", log);
//Debug.Log(PFConstants.LogFolder);
} }
} }
@ -52,6 +45,12 @@ namespace Assets.Scripts.Scenes
} }
private void OnDestroy() private void OnDestroy()
{
Release();
}
//释放资源
private void Release()
{ {
var objAry = Resources.FindObjectsOfTypeAll<Material>(); var objAry = Resources.FindObjectsOfTypeAll<Material>();
@ -79,6 +78,7 @@ namespace Assets.Scripts.Scenes
UIManager.InitNow();//重置当前时间 UIManager.InitNow();//重置当前时间
} }
} }
protected virtual void Update() protected virtual void Update()
{ {
if (Application.internetReachability == NetworkReachability.NotReachable) if (Application.internetReachability == NetworkReachability.NotReachable)
@ -90,7 +90,6 @@ namespace Assets.Scripts.Scenes
{ {
isNetWorkLose = false; isNetWorkLose = false;
App.delayTime = ping.time; App.delayTime = ping.time;
//Debug.Log(App.delayTime);
ping.DestroyPing(); ping.DestroyPing();
ping = null; ping = null;
} }

View File

@ -56,7 +56,7 @@ namespace Assets.Scenes.Ride.Scripts
//显示倒计时面板信息 //显示倒计时面板信息
ShowCountDown(s.Item1, App.GetLocalString("Close Gate")); ShowCountDown(s.Item1, App.GetLocalString("Close Gate"));
#else #else
ShowCountDown(s.Item1, App.GetLocalString("Get The First Place. Close Gate")); ShowCountDown(s.Item1, App.GetLocalString("GetCloseGate"));
#endif #endif
} }
else if (s.Item1 >= 0) else if (s.Item1 >= 0)