diff --git a/Assets/AR/PlayerRenderer.cs b/Assets/AR/PlayerRenderer.cs index d74e9d1e..88c7e738 100644 --- a/Assets/AR/PlayerRenderer.cs +++ b/Assets/AR/PlayerRenderer.cs @@ -69,11 +69,6 @@ namespace Assets.AR } } - protected override void Awake() - { - base.Awake(); - } - public void Initialize(bool male, bool timeTrialBike) { this.Initialize(male); @@ -186,7 +181,7 @@ namespace Assets.AR { var manager = FindObjectOfType(); var map = manager.GetMapRoute(); - if(map.Id == 6296) + if(map.Id == 6296)//TODO:这里写死溧阳AR骑行 Lane = -2f; } } diff --git a/Assets/Resources/UI/language.json b/Assets/Resources/UI/language.json index 8c74f012..a17d8080 100644 --- a/Assets/Resources/UI/language.json +++ b/Assets/Resources/UI/language.json @@ -441,7 +441,8 @@ "Next Time":"下次再说", "DontNeedDownload":"当前视频下载完成后,下次进入线路就不需要重复下载.", "Not In Use":"禁用", - "CancelReadyToQuit":"请取消准备后再退出!" + "CancelReadyToQuit":"请取消准备后再退出!", + "GetCloseGate": "已产生第一名,比赛倒计时" }, "en": { "REMAINING": "REMAINING", @@ -878,6 +879,7 @@ "Next Time":"Next Time", "DontNeedDownload":"The same AR route video does not need to be downloaded again next time", "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" } } diff --git a/Assets/Scripts/App.cs b/Assets/Scripts/App.cs index 96eaa755..ba6d800f 100644 --- a/Assets/Scripts/App.cs +++ b/Assets/Scripts/App.cs @@ -226,7 +226,8 @@ public static class App //TcpAddress = new IPEndPoint(IPAddress.Parse("192.168.0.102"), 21001); Debug.unityLogger.logEnabled = false; #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); TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 21001); #endif diff --git a/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs b/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs index 558dd132..58ab6987 100644 --- a/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs +++ b/Assets/Scripts/Devices/Ble/BleDeviceAdapter.cs @@ -142,7 +142,7 @@ namespace Assets.Scripts.Devices.Ble { discoveredDevices[device.Peripheral.Address].SignalStrength = device.Rssi; discoveredDevices[device.Peripheral.Address].LastActiveTime = DateTime.Now; - Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }"); + //Debug.Log($"设备{ device.Peripheral.Name }信号量:{ device.Rssi }"); } }); } diff --git a/Assets/Scripts/Scenes/VideoRide.meta b/Assets/Scripts/Scenes/AR.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide.meta rename to Assets/Scripts/Scenes/AR.meta diff --git a/Assets/Scripts/Scenes/VideoRide/AbstractVideoPlayer.cs b/Assets/Scripts/Scenes/AR/AbstractVideoPlayer.cs similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/AbstractVideoPlayer.cs rename to Assets/Scripts/Scenes/AR/AbstractVideoPlayer.cs diff --git a/Assets/Scripts/Scenes/VideoRide/AbstractVideoPlayer.cs.meta b/Assets/Scripts/Scenes/AR/AbstractVideoPlayer.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/AbstractVideoPlayer.cs.meta rename to Assets/Scripts/Scenes/AR/AbstractVideoPlayer.cs.meta diff --git a/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs b/Assets/Scripts/Scenes/AR/InitMiniMapScript.cs similarity index 59% rename from Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs rename to Assets/Scripts/Scenes/AR/InitMiniMapScript.cs index 946eb57d..c50deb73 100644 --- a/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs +++ b/Assets/Scripts/Scenes/AR/InitMiniMapScript.cs @@ -3,12 +3,7 @@ using Mapbox.Unity.MeshGeneration.Data; using Mapbox.Utils; using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; -using UnityEngine.UI; -using UnityEngine.Video; namespace Assets.Scripts.Scenes.VideoRide { @@ -20,69 +15,79 @@ namespace Assets.Scripts.Scenes.VideoRide Camera _minicamera; [SerializeField] GameObject _player; - VideoGameManager cyclingCotroller; - public AbstractVideoPlayer playerController { get; set; } + GameObject _mipMapRoute; public RectTransform RectRoot { get; set; } TrailRenderer trail; 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(); if (cyclingCotroller != null) { playerController = cyclingCotroller.CurrentPlayer; - var mapdata = cyclingCotroller.GetMapData(); + var map = cyclingCotroller.GetMapData(); //初始化map - //var point = cyclingCotroller.GetCenterCoordinate(); - if (_map != null && mapdata != null) + if (_map != null && map != null) { _map.OnInitialized += _map_OnInitialized; _map.OnUpdated += _map_OnUpdated; - _map.Initialize(new Vector2d(mapdata.Center[0], mapdata.Center[1]), 12); - var bbox = mapdata.Bbox; - var targetbounds = new Vector2dBounds(new Vector2d(bbox[1], bbox[0]), new Vector2d(bbox[3], bbox[2])); + _map.Initialize(new Vector2d(map.Center[0], map.Center[1]), 12); + var bbox = map.Bbox; + var bounds = new Vector2dBounds(new Vector2d(bbox[1], bbox[0]), new Vector2d(bbox[3], bbox[2])); var screenBounds = GetScreenBounds(); - var z = SetZoomToFitBounds(targetbounds, screenBounds); + var z = SetZoomToFitBounds(bounds, screenBounds); } uitransform = cyclingCotroller.GetCanvasTransform(); RectRoot = uitransform.Find("MiniMap/MiniMap").GetComponent(); } + pathMaterial = Resources.Load("UI/Material/2"); + SetTrailRender(); + } + //设置小地图上人物移动路径 + private void SetTrailRender() + { trail = transform.parent.Find("Sphere").GetComponent(); trail.startWidth = 5f; trail.endWidth = 5f; trail.startColor = 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() { - 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(); - var tr = uitransform.Find("MiniMap/MiniMap/arrow"); - 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; - } + CreateMiniPath(); + timer = 0; } } - - private bool init = false; private void _map_OnInitialized() { init = true; @@ -94,10 +99,8 @@ namespace Assets.Scripts.Scenes.VideoRide } }; - } - - #region Camera 自适应 + /// /// https://github.com/mapbox/mapbox-unity-sdk/issues/1580 /// @@ -123,6 +126,7 @@ namespace Assets.Scripts.Scenes.VideoRide _map.UpdateMap(); return (int)Math.Floor(zoom); } + private Vector2dBounds GetScreenBounds() { 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)); } - #endregion - #region 创建小地图路线 private void _map_OnUpdated() { CreateMiniRoute(); } - void CreateMiniRoute() + + private void CreateMiniRoute() + { + var dat = new List(); + + 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(); 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; - var interval = Math.Max(Math.Ceiling(count / 100D), 1f); - for (int i = 0; i < mapData.List.Count; i++) + if (i % interval == 0) { - 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); } } - var feat = new VectorFeatureUnity(); - feat.Points.Add(dat); - CreateLineRender(feat);//创建小地图路线 - } - } - - void CreateMiniPath() - { - var dat = new List(); - 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);//创建小地图路线 } + //创建路径 + var feat = new VectorFeatureUnity(); + feat.Points.Add(dat); + CreateRedLineRender(feat); } + //创建小地图路线 - void CreateLineRender(VectorFeatureUnity feat) + private void CreateLineRender(VectorFeatureUnity feat) { if (_mipMapRoute != null) { _mipMapRoute.Destroy(); } - _mipMapRoute = new GameObject("MiniMapRoute"); - _mipMapRoute.transform.parent = transform.parent; + + _mipMapRoute = new GameObject("MiniMapRoute") + { + transform = + { + parent = transform.parent + } + }; + var lineRender = _mipMapRoute.AddComponent(); - - lineRender.material = Instantiate(Resources.Load("UI/Material/1")); + lineRender.material = Resources.Load("UI/Material/1"); var dat = feat.Points[0]; lineRender.endColor = Color.white; lineRender.startColor = Color.white; @@ -219,18 +229,23 @@ namespace Assets.Scripts.Scenes.VideoRide _mipMapRoute.layer = 9; _map.gameObject.SetActive(false); } - GameObject _mipMapPath; - void CreateRedLineRender(VectorFeatureUnity feat) + + private void CreateRedLineRender(VectorFeatureUnity feat) { if (_mipMapPath != null) { _mipMapPath.Destroy(); } - _mipMapPath = new GameObject("MiniMapPath"); - _mipMapPath.transform.parent = transform.parent; + _mipMapPath = new GameObject("MiniMapPath") + { + transform = + { + parent = transform.parent + } + }; var lineRender = _mipMapPath.AddComponent(); - lineRender.material = Instantiate(Resources.Load("UI/Material/2")); + lineRender.material = pathMaterial; var dat = feat.Points[0]; lineRender.endColor = Color.red; lineRender.startColor = Color.red; @@ -244,6 +259,6 @@ namespace Assets.Scripts.Scenes.VideoRide lineRender.loop = false; _mipMapPath.layer = 9; } - #endregion + } } diff --git a/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta b/Assets/Scripts/Scenes/AR/InitMiniMapScript.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta rename to Assets/Scripts/Scenes/AR/InitMiniMapScript.cs.meta diff --git a/Assets/Scripts/Scenes/VideoRide/OnlineVideoPlayer.cs b/Assets/Scripts/Scenes/AR/OnlineVideoPlayer.cs similarity index 72% rename from Assets/Scripts/Scenes/VideoRide/OnlineVideoPlayer.cs rename to Assets/Scripts/Scenes/AR/OnlineVideoPlayer.cs index de065722..d5592780 100644 --- a/Assets/Scripts/Scenes/VideoRide/OnlineVideoPlayer.cs +++ b/Assets/Scripts/Scenes/AR/OnlineVideoPlayer.cs @@ -4,30 +4,17 @@ namespace Assets.Scripts.Scenes.VideoRide { 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() { base.CreateHeadImage(); 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) diff --git a/Assets/Scripts/Scenes/VideoRide/OnlineVideoPlayer.cs.meta b/Assets/Scripts/Scenes/AR/OnlineVideoPlayer.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/OnlineVideoPlayer.cs.meta rename to Assets/Scripts/Scenes/AR/OnlineVideoPlayer.cs.meta diff --git a/Assets/Scripts/Scenes/AR/UI.meta b/Assets/Scripts/Scenes/AR/UI.meta new file mode 100644 index 00000000..05f54595 --- /dev/null +++ b/Assets/Scripts/Scenes/AR/UI.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bdac326eaff04872bcebc003689d480b +timeCreated: 1683888648 \ No newline at end of file diff --git a/Assets/Scripts/Scenes/VideoRide/ElevationBarDataFeed.cs b/Assets/Scripts/Scenes/AR/UI/ElevationBarDataFeed.cs similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/ElevationBarDataFeed.cs rename to Assets/Scripts/Scenes/AR/UI/ElevationBarDataFeed.cs diff --git a/Assets/Scripts/Scenes/VideoRide/ElevationBarDataFeed.cs.meta b/Assets/Scripts/Scenes/AR/UI/ElevationBarDataFeed.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/ElevationBarDataFeed.cs.meta rename to Assets/Scripts/Scenes/AR/UI/ElevationBarDataFeed.cs.meta diff --git a/Assets/Scripts/Scenes/VideoRide/ExplosiveScript.cs b/Assets/Scripts/Scenes/AR/UI/ExplosiveScript.cs similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/ExplosiveScript.cs rename to Assets/Scripts/Scenes/AR/UI/ExplosiveScript.cs diff --git a/Assets/Scripts/Scenes/VideoRide/ExplosiveScript.cs.meta b/Assets/Scripts/Scenes/AR/UI/ExplosiveScript.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/ExplosiveScript.cs.meta rename to Assets/Scripts/Scenes/AR/UI/ExplosiveScript.cs.meta diff --git a/Assets/Scripts/Scenes/VideoRide/HeadScript.cs b/Assets/Scripts/Scenes/AR/UI/HeadScript.cs similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/HeadScript.cs rename to Assets/Scripts/Scenes/AR/UI/HeadScript.cs diff --git a/Assets/Scripts/Scenes/VideoRide/HeadScript.cs.meta b/Assets/Scripts/Scenes/AR/UI/HeadScript.cs.meta similarity index 100% rename from Assets/Scripts/Scenes/VideoRide/HeadScript.cs.meta rename to Assets/Scripts/Scenes/AR/UI/HeadScript.cs.meta diff --git a/Assets/Scripts/Scenes/VideoRide/ListItem.cs b/Assets/Scripts/Scenes/AR/UI/ListItem.cs similarity index 89% rename from Assets/Scripts/Scenes/VideoRide/ListItem.cs rename to Assets/Scripts/Scenes/AR/UI/ListItem.cs index 1fc1ce5b..2e3003c9 100644 --- a/Assets/Scripts/Scenes/VideoRide/ListItem.cs +++ b/Assets/Scripts/Scenes/AR/UI/ListItem.cs @@ -1,9 +1,6 @@ using PolyAndCode.UI; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; @@ -24,6 +21,7 @@ namespace Assets.Scripts.Scenes.VideoRide public string Id; public string Rank; public string Name; + private float timer = 1f; private VideoGameManager manager { get; set; } private void Start() @@ -31,7 +29,7 @@ namespace Assets.Scripts.Scenes.VideoRide manager = FindObjectOfType(); GetComponent