From bf48989a9c03a6f4b8cfb35daa3c7f6f2aac6c48 Mon Sep 17 00:00:00 2001 From: lishuo Date: Fri, 25 Mar 2022 09:57:30 +0800 Subject: [PATCH] =?UTF-8?q?ui=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UI/Prefab/AR/icon_paihang_PC.png | Bin 0 -> 392 bytes .../UI/Prefab/AR/icon_paihang_PC.png.meta | 128 + .../UI/Prefab/AR/icon_watching_PC.png | Bin 0 -> 922 bytes .../UI/Prefab/AR/icon_watching_PC.png.meta | 128 + Assets/Scenes/VideoPlay.unity | 6047 ++++++++++------- Assets/Scripts/Apis/Models/MapRoute.cs | 4 + .../Scenes/VideoRide/AbstractVideoPlayer.cs | 46 +- .../Scenes/VideoRide/InitMiniMapScript.cs | 245 + .../VideoRide/InitMiniMapScript.cs.meta | 11 + .../Scripts/Scenes/VideoRide/NearByScript.cs | 50 + .../Scenes/VideoRide/NearByScript.cs.meta | 11 + .../Scenes/VideoRide/NearVideoPlayerList.cs | 84 + .../VideoRide/NearVideoPlayerList.cs.meta | 11 + .../Scripts/Scenes/VideoRide/RankingScript.cs | 39 + .../Scenes/VideoRide/RankingScript.cs.meta | 11 + .../Scenes/VideoRide/VideoGameManager.cs | 126 +- .../Scripts/Scenes/VideoRide/VideoLoading.cs | 16 +- .../Scripts/Scenes/VideoRide/VideoPlayer.cs | 60 +- .../Scenes/VideoRide/VideoResultScript.cs | 178 + .../VideoRide/VideoResultScript.cs.meta | 11 + .../Scenes/VideoRide/VideoUIManager.cs | 250 +- 21 files changed, 4935 insertions(+), 2521 deletions(-) create mode 100644 Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png create mode 100644 Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png.meta create mode 100644 Assets/Resources/UI/Prefab/AR/icon_watching_PC.png create mode 100644 Assets/Resources/UI/Prefab/AR/icon_watching_PC.png.meta create mode 100644 Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs create mode 100644 Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta create mode 100644 Assets/Scripts/Scenes/VideoRide/NearByScript.cs create mode 100644 Assets/Scripts/Scenes/VideoRide/NearByScript.cs.meta create mode 100644 Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs create mode 100644 Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs.meta create mode 100644 Assets/Scripts/Scenes/VideoRide/RankingScript.cs create mode 100644 Assets/Scripts/Scenes/VideoRide/RankingScript.cs.meta create mode 100644 Assets/Scripts/Scenes/VideoRide/VideoResultScript.cs create mode 100644 Assets/Scripts/Scenes/VideoRide/VideoResultScript.cs.meta diff --git a/Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png b/Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png new file mode 100644 index 0000000000000000000000000000000000000000..4f9ee02a1d5f127a2808b1a9293a0ce32dcfd216 GIT binary patch literal 392 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEjKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(Jv>S}kx=|o>_x7@FyD$hTke`(rn5z!G~ zU=+Av);R0y&-Itz{>giL@Acd4y*}q(D=+>wC2+}gh2pmkyGj-xUpIZ--Ahb!{GVm$ zo4UJ%EIQ~>ZOzV>>sIA*Yr>1%AJ?qk)|>|0IJTqk8pA=W z;vH9Nyu9vt%Jwd{xt#F7RcERB8snGm+qRtV`+b*nxdH=|!UkI=`CSW~oYyLB_zemL MPgg&ebxsLQ0Bm-VCjbBd literal 0 HcmV?d00001 diff --git a/Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png.meta b/Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png.meta new file mode 100644 index 00000000..0280cabf --- /dev/null +++ b/Assets/Resources/UI/Prefab/AR/icon_paihang_PC.png.meta @@ -0,0 +1,128 @@ +fileFormatVersion: 2 +guid: b1659a9a675563e40b537157235848b1 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 11 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: -1 + aniso: -1 + mipBias: -100 + wrapU: 1 + wrapV: 1 + wrapW: -1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + applyGammaDecoding: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 1024 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 1024 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 1024 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Android + maxTextureSize: 1024 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/UI/Prefab/AR/icon_watching_PC.png b/Assets/Resources/UI/Prefab/AR/icon_watching_PC.png new file mode 100644 index 0000000000000000000000000000000000000000..3d2b4ecc05f6f3722b8076f0856249d08d42d533 GIT binary patch literal 922 zcmV;L17-Y)P)Px#L}ge>W=%~1DgXcg2mk?xX#fNO00031000^Q000001E2u_0{{R30RRC20H6W@ z1ONa40RR91D4+uX1ONa40RR91C;$Ke0D9(TtN;K51W80eR9Fe^mrqDkQ51)rv{X_o zoIps$g>Aw`f-4s-Bx(~uLgXqKTDhx5tJXn~1VK{ZDp$2h2%}9zfkB(dK!{cm78Dfp z7m=Xp`_LZPt9bNhwH#^E}AhODAk<>*DWM<`x|ThOYgMsZ8Kq+kge zS+ROAp<1Puo1{oP+^jL%YsTi_C>(&E3et~(#uO8i8w|8J)hLO*@E}t88UEu?_ajqG zC002h(Hy-EHAzA@JPlO)hHn;9jbUrW&cijh45wkYKPk2vRjz7SS;5im$47MnJ7C#X zzYI#eM>=#BY@8K;AHZ z)wD8iV^cQKGd2VJIrOIjG4P!Y#D-iSBl-RKRolvpo$Ien)DYO;$6I^@p#=OI^JNX= z0$ha+e*pbrq{aYawvKwxsgxF+_IJ05Zz3J_&%!?lzWl^UHed8}{vi7OP#yUgn*hz_ z%d(5#;S`>}?zw}iJ9FLOI%n-CXYkY+?8{!?$e>sELi;1|!+#C*;GY=(J`<;}_@J8@ z{fZgC>&E;iF`+-PdKmHJ5}kpPDJ(Pgk*u27uh_TYiSf&vO(v-*_+lSP?IV!HMO8FX zwaqX-1=>dH$r=H>{06aO+svXL7t~4C=KC0|gf?oOwY5a6n)=YNV;i;R)E%?F5ZDJV z!AjLpN5C|Euz}dx#FOm;y#TSJPIL9u@63xJp$IDw5*_@>WdVIB9ELM+3PxQibTy_} z<%C3YBwLir%k(6%3+{xfR($?-YZPBk1?jqi%|Wf}mTGrpY9G-tVwgqFSn% zx)sHG$mFM(PLCyMRa9dz)1=J=QG5~>KwoH9QLJ(%8=bT1C1x^RFi*l19D@DejzIm} w`5so`5iD^OZt%<{Ux9oD@)gKepurXR1HSJ|^(); @@ -48,15 +54,10 @@ namespace Assets.Scripts.Scenes.VideoRide ComputeNextSlope();//初始化坡度等 animator.Play("idle"); camera = Camera.main; - - //注解1 - //得到模型原始高度 - float size_y = GetComponent().bounds.size.y; - //得到模型缩放比例 - float scal_y = transform.localScale.y; - //它们的乘积就是高度 - currenPlayerHeight = (size_y * scal_y); - + + var GraphChart = manager.GetCanvasTransform().Find("GraphChart").gameObject; + chartDataSourceScript = GraphChart.GetComponent(); + graph = GraphChart.GetComponent(); } protected virtual void Update() @@ -68,12 +69,13 @@ namespace Assets.Scripts.Scenes.VideoRide { try { + ComputeNextSlope();//计算下一个坡度 + ComputePlayer();//计算人物属性 //animator.Play("touchHead"); if (manager.IsStart()) { ticks++; - ComputeNextSlope();//计算下一个坡度 - ComputePlayer();//计算人物属性 + Forward(); ComputeRecord(); ComputeVideo(); RayCastHit(); @@ -187,9 +189,6 @@ namespace Assets.Scripts.Scenes.VideoRide { preSpeed = speed; speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight); - distance = Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero); - totalDistance += distance; - currentlatLon = manager.Along(totalDistance); } else { @@ -198,6 +197,13 @@ namespace Assets.Scripts.Scenes.VideoRide } } + private void Forward() + { + distance = Math.Round(speed / 3600, 5, MidpointRounding.AwayFromZero); + totalDistance += distance; + currentlatLon = manager.Along(totalDistance); + } + protected virtual void ComputeVideo(){ } protected virtual void ComputeRecord() { } @@ -265,6 +271,10 @@ namespace Assets.Scripts.Scenes.VideoRide head.transform.position = playerScreenPos; } } + protected virtual void MoveGraphHead(bool init = false) + { + + } public void Destroy() { diff --git a/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs b/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs new file mode 100644 index 00000000..870e5090 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs @@ -0,0 +1,245 @@ +using Mapbox.Unity.Map; +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 +{ + public class InitMiniMapScript : MonoBehaviour + { + [SerializeField] + AbstractMap _map; + [SerializeField] + Camera _minicamera; + [SerializeField] + GameObject _player; + VideoGameManager cyclingCotroller; + public VideoPlayer playerController; + GameObject _mipMapRoute; + public RectTransform RectRoot;//rawImage + TrailRenderer trail; + Transform uitransform { get; set; } + void Start() + { + cyclingCotroller = FindObjectOfType(); + + if (cyclingCotroller != null) + { + var mapdata = cyclingCotroller.GetMapData(); + //初始化map + //var point = cyclingCotroller.GetCenterCoordinate(); + if (_map != null && mapdata != 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])); + var screenBounds = GetScreenBounds(); + var z = SetZoomToFitBounds(targetbounds, screenBounds); + } + uitransform = cyclingCotroller.GetCanvasTransform(); + RectRoot = uitransform.Find("MiniMap/MiniMap").GetComponent(); + } + + 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 = 0; + private void Update() + { + if (playerController != null) + { + var tr = uitransform.Find("MiniMap/MiniMap/arrow"); + tr.SetSiblingIndex(9999); + var pos = _map.GeoToWorldPosition(playerController.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 = playerController.power > 0; + } + timer += Time.deltaTime; + + while (timer >= 1) + { + CreateMiniPath(); + timer = 0; + } + } + void CreateMiniPath() + { + if (playerController == null) + return; + 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 (playerController.currentIndex >= i) + { + dat.Add(item); + } + } + } + var feat = new VectorFeatureUnity(); + feat.Points.Add(dat); + CreateRedLineRender(feat);//创建小地图路线 + } + } + + private bool init = false; + private void _map_OnInitialized() + { + init = true; + var visualizer = _map.MapVisualizer; + visualizer.OnMapVisualizerStateChanged += (s) => + { + if (s == ModuleState.Finished) + { + + } + }; + + } + + #region Camera 自适应 + /// + /// https://github.com/mapbox/mapbox-unity-sdk/issues/1580 + /// + /// 路线的边界 + /// 小地图边界 + private int SetZoomToFitBounds(Vector2dBounds targetBounds, Vector2dBounds screenBounds) + { + var targetLonDelta = targetBounds.East - targetBounds.West; + var targetLatDelta = targetBounds.North - targetBounds.South; + + var screenLonDelta = screenBounds.East - screenBounds.West; + var screenLatDelta = screenBounds.North - screenBounds.South; + + var zoomLatMultiplier = screenLatDelta / targetLatDelta; + var zoomLonMultiplier = screenLonDelta / targetLonDelta; + + var latZoom = Math.Log(zoomLatMultiplier, 2); + var lonZoom = Math.Log(zoomLonMultiplier, 2); + + var zoom = (float)(_map.Zoom + Math.Min(latZoom, lonZoom)); + + _map.SetZoom((float)Math.Floor(zoom)); + _map.UpdateMap(); + return (int)Math.Floor(zoom); + } + private Vector2dBounds GetScreenBounds() + { + var screenWidth = UnityEngine.Screen.width; + var screenHeight = UnityEngine.Screen.height; + + var sw_world = _minicamera.ViewportToWorldPoint(new Vector3(0.25f, 0.1f, 160)); + var sw = _map.WorldToGeoPosition(sw_world); + var ne_world = _minicamera.ViewportToWorldPoint(new Vector3(0.75f, 0.9f, 90)); + var ne = _map.WorldToGeoPosition(ne_world); + + return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y)); + } + #endregion + + #region 创建小地图路线 + private void _map_OnUpdated() + { + CreateMiniRoute(); + } + void CreateMiniRoute() + { + var meshData = new MeshData(); + 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 += 1f; + dat.Add(item); + } + } + var feat = new VectorFeatureUnity(); + feat.Points.Add(dat); + CreateLineRender(feat);//创建小地图路线 + } + } + //创建小地图路线 + void CreateLineRender(VectorFeatureUnity feat) + { + if (_mipMapRoute != null) + { + _mipMapRoute.Destroy(); + } + _mipMapRoute = new GameObject("MiniMapRoute"); + _mipMapRoute.transform.parent = transform; + var lineRender = _mipMapRoute.AddComponent(); + + lineRender.material = Instantiate(Resources.Load("UI/Material/1")); + var dat = feat.Points[0]; + lineRender.endColor = Color.white; + lineRender.startColor = Color.white; + //设置宽度 + lineRender.startWidth = 10f; + lineRender.endWidth = 10f; + lineRender.positionCount = dat.Count; + lineRender.SetPositions(feat.Points[0].ToArray()); + lineRender.numCornerVertices = 20; + lineRender.numCapVertices = 20; + lineRender.loop = false; + _mipMapRoute.layer = 9; + } + GameObject _mipMapPath; + void CreateRedLineRender(VectorFeatureUnity feat) + { + if (_mipMapPath != null) + { + _mipMapPath.Destroy(); + } + _mipMapPath = new GameObject("MiniMapPath"); + _mipMapPath.transform.parent = transform; + var lineRender = _mipMapPath.AddComponent(); + + lineRender.material = Instantiate(Resources.Load("UI/Material/2")); + var dat = feat.Points[0]; + lineRender.endColor = Color.red; + lineRender.startColor = Color.red; + //设置宽度 + lineRender.startWidth = 10f; + lineRender.endWidth = 10f; + lineRender.positionCount = dat.Count; + lineRender.SetPositions(feat.Points[0].ToArray()); + lineRender.numCornerVertices = 20; + lineRender.numCapVertices = 20; + lineRender.loop = false; + _mipMapPath.layer = 9; + } + #endregion + } +} diff --git a/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta b/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta new file mode 100644 index 00000000..e198c1c8 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/InitMiniMapScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8c536d01b43b2f643a86ef176910485a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Scenes/VideoRide/NearByScript.cs b/Assets/Scripts/Scenes/VideoRide/NearByScript.cs new file mode 100644 index 00000000..8201b5e0 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/NearByScript.cs @@ -0,0 +1,50 @@ +using Assets.Scenes.Ride.Scripts; +using DG.Tweening; +using UnityEngine; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace Assets.Scripts.Scenes.VideoRide +{ + public class NearByScript: MonoBehaviour + { + Text rideNum {get;set;} + Text btnRideNum { get; set; } + GameObject Hide { get; set; } + GameObject Show { get; set; } + private void Start() + { + rideNum = transform.Find("Head/RideNum/Number").GetComponent(); + btnRideNum = transform.Find("Head/Show/Panel/Number").GetComponent(); + Hide = transform.Find("Head/Hide").gameObject; + Show = transform.Find("Head/Show").gameObject; + UIManager.AddEvent(Hide, UnityEngine.EventSystems.EventTriggerType.PointerClick, Hidehandler); + UIManager.AddEvent(Show, UnityEngine.EventSystems.EventTriggerType.PointerClick, Showhandler); + } + private void Hidehandler(BaseEventData data) + { + transform.DOLocalMoveX(913, 1f).onComplete += () => { + Show.SetActive(true); + Hide.SetActive(false); + }; + } + private void Showhandler(BaseEventData data) + { + Show.SetActive(false); + Hide.SetActive(true); + transform.DOLocalMoveX(667.55f, 1f).onComplete += () => { + + }; + } + float timer = 1f; + private void Update() + { + timer -= Time.deltaTime; + while (timer < 0) { + rideNum.text = $"{MapUDPService.GetAllOnlineUserCount()}"; + btnRideNum.text = rideNum.text; + timer += 1f; + } + } + } +} diff --git a/Assets/Scripts/Scenes/VideoRide/NearByScript.cs.meta b/Assets/Scripts/Scenes/VideoRide/NearByScript.cs.meta new file mode 100644 index 00000000..2381dd76 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/NearByScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 626b431b9a468f94b89fce5f20a2cc36 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs b/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs new file mode 100644 index 00000000..c0e1add8 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs @@ -0,0 +1,84 @@ +using Assets.Scenes.Ride.Scripts; +using PolyAndCode.UI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace Assets.Scripts.Scenes.VideoRide +{ + public struct ContactInfo + { + public string Name; + public string Gender; + public string id; + } + class NearVideoPlayerList : MonoBehaviour, IRecyclableScrollRectDataSource + { + [SerializeField] + RecyclableScrollRect _recyclableScrollRect; + + [SerializeField] + private int _dataLength; + + //Dummy data List + private List _contactList = new List(); + + //Recyclable scroll rect's data source must be assigned in Awake. + private void Awake() + { + InitData(); + _recyclableScrollRect.DataSource = this; + } + + private void InitData() + { + if (_contactList != null) _contactList.Clear(); + var list = MapUDPService.GetOnlineUsers(App.RouteIdParam); + + foreach (var item in list) + { + ContactInfo obj = new ContactInfo(); + obj.Name = item.Name; + obj.Gender = DateTime.Now.Millisecond.ToString(); + obj.id = item.Id.ToString(); + _contactList.Add(obj); + } + } + float timer = 1f; + private void Update() + { + timer -= Time.deltaTime; + while (timer < 0) + { + InitData(); + timer += 1f; + } + } + + #region DATA-SOURCE + + /// + /// Data source method. return the list length. + /// + public int GetItemCount() + { + return _contactList.Count; + } + + /// + /// Data source method. Called for a cell every time it is recycled. + /// Implement this method to do the necessary cell configuration. + /// + public void SetCell(ICell cell, int index) + { + //Casting to the implemented Cell + var item = cell as ListItem; + item.ConfigureCell(_contactList[index], index); + } + + #endregion + } +} diff --git a/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs.meta b/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs.meta new file mode 100644 index 00000000..bf51939a --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/NearVideoPlayerList.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad9c66572ce69ea4fba3bc35e6db3d86 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Scenes/VideoRide/RankingScript.cs b/Assets/Scripts/Scenes/VideoRide/RankingScript.cs new file mode 100644 index 00000000..8ccfd758 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/RankingScript.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; +using UnityEngine.EventSystems; +using DG.Tweening; + +namespace Assets.Scripts.Scenes.VideoRide +{ + class RankingScript: MonoBehaviour + { + GameObject Hide { get; set; } + GameObject Show { get; set; } + private void Start() + { + Hide = transform.Find("Head/Hide").gameObject; + Show = transform.Find("Head/Show").gameObject; + UIManager.AddEvent(Hide, UnityEngine.EventSystems.EventTriggerType.PointerClick, Hidehandler); + UIManager.AddEvent(Show, UnityEngine.EventSystems.EventTriggerType.PointerClick, Showhandler); + } + private void Hidehandler(BaseEventData data) + { + transform.DOLocalMoveX(-913, 1f).onComplete+=()=> { + Show.SetActive(true); + Hide.SetActive(false); + }; + } + private void Showhandler(BaseEventData data) + { + Show.SetActive(false); + Hide.SetActive(true); + transform.DOLocalMoveX(-667, 1f).onComplete += () => { + + }; + } + } +} diff --git a/Assets/Scripts/Scenes/VideoRide/RankingScript.cs.meta b/Assets/Scripts/Scenes/VideoRide/RankingScript.cs.meta new file mode 100644 index 00000000..9a7f0504 --- /dev/null +++ b/Assets/Scripts/Scenes/VideoRide/RankingScript.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5125c2c61c26934d858b75fa9dfd187 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Scenes/VideoRide/VideoGameManager.cs b/Assets/Scripts/Scenes/VideoRide/VideoGameManager.cs index 51fa8519..64eaf380 100644 --- a/Assets/Scripts/Scenes/VideoRide/VideoGameManager.cs +++ b/Assets/Scripts/Scenes/VideoRide/VideoGameManager.cs @@ -15,6 +15,8 @@ using TurfCS; using UnityEngine; using DG.Tweening; using Assets.Scenes.Ride.Scripts.Model.RiderModels; +using UnityEngine.EventSystems; +using UnityEngine.Events; namespace Assets.Scripts.Scenes.VideoRide { @@ -26,7 +28,7 @@ namespace Assets.Scripts.Scenes.VideoRide private MediaPlayer mediaPlayer { get; set; } private bool isStart { get; set; } private Route route { get; set; } - private MapRoute mapRoute { get; set; } + public MapRoute mapRoute { get; set; } public RouteResultParam selectParamModel; public RouteResult routeResult; public string recordId { get; set; } @@ -38,9 +40,28 @@ namespace Assets.Scripts.Scenes.VideoRide public List slots = new List(); GameObject infoPanel; GameObject OnlinePlayer; + public enum ARMode + { + INSPECT, + RIDE + } + public enum ViewMode + { + THIRD, + FIRST, + } + //当前是观察者视角还是骑行者视角 + public ARMode _aRMode { get; set; } + //当前是第一人称还是第三人称 + public ViewMode _viewMode { get; set; } + + public int RankingId { get; set; } private async void Awake() { base.Awake(); +#if UNITY_EDITOR + App.RouteIdParam = 12353; +#endif mediaPlayer = FindObjectOfType(); //自动登录 if (App.CurrentUser == null) @@ -50,7 +71,6 @@ namespace Assets.Scripts.Scenes.VideoRide DeviceCache.Init(PFConstants.DeviceCacheFolder); //var check = CheckAnt();//初始化蓝牙设备 recordId = Guid.NewGuid().ToString(); - MapUDPService.Init();//初始化TCP MockDirection(); infoPanel = Resources.Load("UI/Prefab/Ride/OnlineInfoPanel"); OnlinePlayer = Resources.Load("UI/Prefab/OnlineVideoPlayer"); @@ -59,13 +79,12 @@ namespace Assets.Scripts.Scenes.VideoRide { InitSlots(); startTime = DateTime.Now;//UIManager.Now.GetDateTime(); - var videoPlayer = FindObjectOfType(); - var mapApi = ConfigHelper.mapApi; - const int routeId = 12353; - mapData = mapApi.GetData(routeId);//获取路书地理数据 - mapRoute = mapApi.GetById(routeId).data; + var routeId = App.RouteIdParam; + //获取路书 + GetMapRoute(); + GetMapData(); route = new Route(mapData, mapRoute); - CurrentPlayer = videoPlayer; + if (selectParamModel == null) { selectParamModel = new RouteResultParam @@ -96,13 +115,13 @@ namespace Assets.Scripts.Scenes.VideoRide Debug.Log($"当前在线人数:{ MapUDPService.GetAllOnlineUserCount()}"); CreateOnlineUser(onlineRiders); timer += 1f; - + } } private int offSet = 50; private int currentOnlineCount = 0; //创建当前线路其他选手 - private void CreateOnlineUser(List list) + private void CreateOnlineUser(List list) { var players = FindObjectsOfType(); var current = FindObjectOfType(); @@ -129,18 +148,60 @@ namespace Assets.Scripts.Scenes.VideoRide } else { - var diff = item.EndDistance - current.EndDistance; + //进来观察 看谁呢 依据谁未中心构建其他玩家 + var diff = item.EndDistance - 0;//CurrentPlayer.EndDistance; if (diff < offSet) { var obj = Instantiate(OnlinePlayer, transform); var online = obj.GetComponent(); Debug.Log($"{onlineRider.EndDistance}={item.Power}={onlineRider.PreDistance}"); - online.SetPlayer(onlineRider.EndDistance, item.Cadence, item.HeartRate,item.UserId); + online.SetPlayer(onlineRider.EndDistance, item.Cadence, item.HeartRate, item.UserId); obj.transform.DOMoveX(slots[currentOnlineCount], 1); currentOnlineCount++; } } } + + //随机选择当前骑行的人作为观察对象 + if (_aRMode == ARMode.INSPECT && CurrentPlayer == null) + { + var currentPlayer = players.FirstOrDefault(); + if (currentPlayer != null) + { + ChangePlayer(currentPlayer.UserId); + } + } + } + //设置当前是骑行模式还是观察模式 + public void SetCurrentMode(ARMode aRMode) + { + _aRMode = aRMode; + var videoPlayer = FindObjectOfType(); + if (_aRMode == ARMode.INSPECT) + { + videoPlayer?.gameObject.SetActive(false); + } + else + { + CurrentPlayer = videoPlayer; + } + } + //切换当前人物视角 + public void ChangeView() + { + var videoPlayer = FindObjectOfType(); + var currentPlayer = CurrentPlayer == null? videoPlayer.transform : CurrentPlayer.transform; + _viewMode = _viewMode == ViewMode.THIRD ? ViewMode.FIRST : ViewMode.THIRD; + if (_viewMode == ViewMode.FIRST) + { + currentPlayer.DOMoveZ(-0.1f, 0f); + currentPlayer.DOMoveY(-1.1f, 0f); + } + else + { + currentPlayer.DOMoveZ(4, 0f); + currentPlayer.DOMoveY(-1f, 0f); + } } //切换人物 public void ChangePlayer(int userId) @@ -258,9 +319,14 @@ namespace Assets.Scripts.Scenes.VideoRide { if (mediaPlayer != null) { - mediaPlayer.PlaybackRate = 1;//TODO:playbackRate; + mediaPlayer.PlaybackRate = playbackRate; mediaPlayer.Play(); } + if (startTime == null) + { + startTime = UIManager.Now.GetDateTime(); + } + isStart = true; } //暂停 public void Pause() @@ -289,11 +355,28 @@ namespace Assets.Scripts.Scenes.VideoRide { mediaPlayer?.Control.SeekToFrame(seq); } - //获取路书信息 + //获取路书gps信息 public MapDataModel GetMapData() { + if (mapData == null) + { + var mapApi = ConfigHelper.mapApi; + int routeId = App.RouteIdParam; + mapData = mapApi.GetData(routeId);//获取路书地理数据 + } return mapData; } + //获取路书信息 + public MapRoute GetMapRoute() + { + if (mapRoute == null) + { + var mapApi = ConfigHelper.mapApi; + int routeId = App.RouteIdParam; + mapRoute = mapApi.GetById(routeId).data; + } + return mapRoute; + } //保存骑行记录 public void Save(double totalDistance) { @@ -312,7 +395,20 @@ namespace Assets.Scripts.Scenes.VideoRide cyclingController.recorderData.ManufacturerName = ManufacturerName; cyclingController.recorderData.DeviceNumber = DeviceNumber; cyclingController.recorderData.LastFrame = GetCurrentFrame(); - var RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path); + RankingId = cyclingController.recorderData.SaveWithLocalRecordAysnc(cyclingModel, selectParamModel, imageFileName, recordId, path); + } + public void GetUIPanel() + { + + } + + public void AddEvent(GameObject sender, EventTriggerType eventType, UnityAction unityAction) + { + UIManager.AddEvent(sender, eventType, unityAction); + } + public Texture GetCountryImageByCode(string code) + { + return UIManager.Instance.loginRegOptions.GetCountryImage(code); } //截图 protected void CaptureCamera(Camera camera, Rect rect, string fileName) diff --git a/Assets/Scripts/Scenes/VideoRide/VideoLoading.cs b/Assets/Scripts/Scenes/VideoRide/VideoLoading.cs index 7671527e..1eade96e 100644 --- a/Assets/Scripts/Scenes/VideoRide/VideoLoading.cs +++ b/Assets/Scripts/Scenes/VideoRide/VideoLoading.cs @@ -7,6 +7,7 @@ using UnityEngine.Networking; using UnityEngine.UI; using DG.Tweening; using UnityEngine.SceneManagement; +using UnityEngine.EventSystems; namespace Assets.Scripts.Scenes.VideoRide { @@ -22,12 +23,14 @@ namespace Assets.Scripts.Scenes.VideoRide var button = transform.Find("Panel/Button").GetComponent