附近的人
This commit is contained in:
1 parent
725b510748
commit
2fcd9b23fa
94 files changed
+7063
-2007
No files matched your search
@@ -140,6 +140,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
protected virtual void Run()
|
||||
{
|
||||
ComputeNextSlope();//计算下一个坡度相关数据
|
||||
SendTcp();
|
||||
if (isStart)
|
||||
{
|
||||
ticks++;
|
||||
@@ -172,6 +173,10 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
isQuit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected virtual void SendTcp()
|
||||
{
|
||||
|
||||
}
|
||||
//计算功率 速度 当前骑行总里程(M)心率 踏频 等
|
||||
protected virtual void Compute()
|
||||
@@ -296,6 +301,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
while (t < 1)
|
||||
{
|
||||
t += Time.deltaTime;
|
||||
|
||||
Vector3 v = Vector3.Lerp(prePos, nextPos, t);
|
||||
Vector3 nextPosition = new Vector3((float)Math.Round(v.x, 2), (float)Math.Round(v.y, 2), (float)Math.Round(v.z, 2));
|
||||
if (!nextPosition.Equals(transform.localPosition))
|
||||
@@ -303,9 +309,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
transform.localPosition = nextPosition;
|
||||
//Camera.main.transform.localPosition = nextPosition;
|
||||
}
|
||||
|
||||
//控制海拔图的位置
|
||||
yield return null;
|
||||
yield return new WaitForEndOfFrame();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -38,18 +38,13 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
cyclingModel = CyclingModel.Single;
|
||||
//获取路书信息
|
||||
mapApi = new MapApi();
|
||||
RouteId = App.RouteIdParam;
|
||||
RouteId = App.RouteIdParam > 0? App.RouteIdParam : 376;
|
||||
//var result = GetTestData();
|
||||
MapDataModel result;
|
||||
if (RouteId > 0)
|
||||
{
|
||||
result = mapApi.GetData(RouteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GetTestData();
|
||||
}
|
||||
MapDataModel result = mapApi.GetData(RouteId);
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
var antConnected = CheckAnt();//初始化ant+设备
|
||||
#endif
|
||||
//if (!antConnected)
|
||||
//{
|
||||
// throw new Exception("请先连接设备");
|
||||
@@ -59,7 +54,7 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
|
||||
var param = mapApi.GetById(RouteId);
|
||||
mapRoute = GetNewInstace(RouteId);//获取一个路书所有的数据
|
||||
|
||||
MapUDPService.Init();
|
||||
switch (cyclingModel)
|
||||
{
|
||||
case CyclingModel.Single:
|
||||
@@ -113,7 +108,6 @@ public class CyclingController : DeviceServiceMonoBase
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
_device = devices.OrderByDescending(d => d.Sensor == SensorType.Trainer).First();
|
||||
if (_device != null && _device is IRequiresRiderWeight)
|
||||
{
|
||||
(_device as IRequiresRiderWeight).RiderWeight = 65;//TODO:PubCommData.CurrentUser.Weight;
|
||||
(_device as IRequiresRiderWeight).RiderWeight = 65;//TODO:App.CurrentUser.Weight;
|
||||
}
|
||||
ManufacturerId = _device.ManufacturerId;
|
||||
DeviceNumber = $"{ _device.DeviceNumber },{ _device.DeviceType }";
|
||||
@@ -103,7 +103,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
return false;
|
||||
}
|
||||
//if (PubCommData.CurrentUser.FTP <= 0)
|
||||
//if (App.CurrentUser.FTP <= 0)
|
||||
//{
|
||||
|
||||
// return false;
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
[RequireComponent(typeof(Image))]
|
||||
public class GradientBackGround : MonoBehaviour
|
||||
{
|
||||
public enum GradientType
|
||||
{
|
||||
None,
|
||||
Vertical,
|
||||
VerticalDown,
|
||||
Horizontal,
|
||||
Diagonal
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class GradientColorNode
|
||||
{
|
||||
[Range(0, 1)]
|
||||
public float ratio = 0;
|
||||
public Color color = Color.white;
|
||||
|
||||
public GradientColorNode(float _ratio, Color _color)
|
||||
{
|
||||
ratio = _ratio;
|
||||
color = _color;
|
||||
}
|
||||
}
|
||||
|
||||
private Image bgImage;
|
||||
|
||||
[SerializeField, Header("渐变方式")]
|
||||
private GradientType gradientType = GradientType.Vertical;
|
||||
|
||||
[SerializeField, Header("渐变曲线(0~1)")]
|
||||
private AnimationCurve gradientCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(1, 1));
|
||||
|
||||
[SerializeField, Header("渐变颜色")]
|
||||
private List<GradientColorNode> gradientColorNodeList = new List<GradientColorNode>() { new GradientColorNode(0, Color.white), new GradientColorNode(1, Color.black) };
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
bgImage = GetComponent<Image>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
SetGradientColor();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
//if (Input.GetKeyDown(KeyCode.Alpha1))
|
||||
//{
|
||||
// gradientType = GradientType.None;
|
||||
// SetGradientColor();
|
||||
//}
|
||||
//if (Input.GetKeyDown(KeyCode.Alpha2))
|
||||
//{
|
||||
// gradientType = GradientType.Vertical;
|
||||
// SetGradientColor();
|
||||
//}
|
||||
//if (Input.GetKeyDown(KeyCode.Alpha3))
|
||||
//{
|
||||
// gradientType = GradientType.Horizontal;
|
||||
// SetGradientColor();
|
||||
//}
|
||||
//if (Input.GetKeyDown(KeyCode.Alpha4))
|
||||
//{
|
||||
// gradientType = GradientType.Diagonal;
|
||||
// SetGradientColor();
|
||||
//}
|
||||
}
|
||||
|
||||
private void SetGradientColor()
|
||||
{
|
||||
//创建Texture2D
|
||||
Vector2Int imageSize = new Vector2Int(Screen.width, Screen.height);
|
||||
Texture2D texture2D = new Texture2D(imageSize.x, imageSize.y);
|
||||
//遍历像素点
|
||||
switch (gradientType)
|
||||
{
|
||||
case GradientType.Vertical:
|
||||
for (int y = 0; y < imageSize.y; y++)
|
||||
{
|
||||
Color pixelColor = GetColorByCurve(1.0f * y / imageSize.y);
|
||||
for (int x = 0; x < imageSize.x; x++)
|
||||
{
|
||||
texture2D.SetPixel(x, y, pixelColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GradientType.VerticalDown:
|
||||
for (int y = imageSize.y - 1; y > 0; y--)
|
||||
{
|
||||
Color pixelColor = GetColorByCurve(1.0f * y / imageSize.y);
|
||||
for (int x = imageSize.x - 1; x > 0; x--)
|
||||
{
|
||||
texture2D.SetPixel(x, y, pixelColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GradientType.Horizontal:
|
||||
for (int x = 0; x < imageSize.x; x++)
|
||||
{
|
||||
Color pixelColor = GetColorByCurve(1.0f * x / imageSize.x);
|
||||
for (int y = 0; y < imageSize.y; y++)
|
||||
{
|
||||
texture2D.SetPixel(x, y, pixelColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GradientType.Diagonal:
|
||||
for (int x = 0; x < imageSize.x; x++)
|
||||
{
|
||||
for (int y = 0; y < imageSize.y; y++)
|
||||
{
|
||||
Color pixelColor = GetColorByCurve(0.5f * x / imageSize.x + 0.5f * y / imageSize.y);
|
||||
texture2D.SetPixel(x, y, pixelColor);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (gradientColorNodeList.Count > 0)
|
||||
{
|
||||
Color pixelColor = gradientColorNodeList[0].color;
|
||||
for (int x = 0; x < imageSize.x; x++)
|
||||
{
|
||||
for (int y = 0; y < imageSize.y; y++)
|
||||
{
|
||||
texture2D.SetPixel(x, y, pixelColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
texture2D.Apply();
|
||||
//创建Sprite
|
||||
Sprite sprite = Sprite.Create(texture2D, new Rect(0, 0, imageSize.x, imageSize.y), new Vector2(0.5f, 0.5f));
|
||||
sprite.name = "GradientBg";
|
||||
if (bgImage != null)
|
||||
bgImage.sprite = sprite;
|
||||
}
|
||||
|
||||
private Color GetColorByCurve(float ratio)
|
||||
{
|
||||
for (int i = 1; i < gradientColorNodeList.Count; i++)
|
||||
{
|
||||
if (ratio < gradientColorNodeList[i].ratio)
|
||||
{
|
||||
float curveValue = (ratio - gradientColorNodeList[i - 1].ratio) / (gradientColorNodeList[i].ratio - gradientColorNodeList[i - 1].ratio);
|
||||
curveValue = gradientCurve.Evaluate(curveValue);
|
||||
return Color.Lerp(gradientColorNodeList[i - 1].color, gradientColorNodeList[i].color, curveValue);
|
||||
}
|
||||
}
|
||||
return Color.white;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96f78caa6b7570243a53bedbbb5f220c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,7 +30,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var mapdata = cyclingCotroller.GetMapData();
|
||||
//初始化map
|
||||
var point = cyclingCotroller.GetCenterCoordinate();
|
||||
if (_map != null)
|
||||
if (_map != null && mapdata !=null)
|
||||
{
|
||||
_map.OnInitialized += _map_OnInitialized;
|
||||
_map.OnUpdated += _map_OnUpdated;
|
||||
@@ -44,7 +44,10 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
_player.transform.localPosition = _map.GeoToWorldPosition(playerController.Nextlatlong);
|
||||
if (playerController != null)
|
||||
{
|
||||
_player.transform.localPosition = _map.GeoToWorldPosition(playerController.Nextlatlong);
|
||||
}
|
||||
}
|
||||
private bool init = false;
|
||||
private void _map_OnInitialized()
|
||||
@@ -86,7 +89,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var sw_world = _minicamera.ViewportToWorldPoint(new Vector3(0, 0, 180));
|
||||
var sw = _map.WorldToGeoPosition(sw_world);
|
||||
|
||||
var ne_world = _minicamera.ViewportToWorldPoint(new Vector3(0.6f, 0.6f, 180));
|
||||
var ne_world = _minicamera.ViewportToWorldPoint(new Vector3(0.6f, 1f, 180));
|
||||
var ne = _map.WorldToGeoPosition(ne_world);
|
||||
|
||||
return new Vector2dBounds(new Vector2d(sw.x, sw.y), new Vector2d(ne.x, ne.y));
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
/// 骑行函数(如果此方法不满足,可以在子类中重写此方法)
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
protected virtual void Run(TargetData targetData)
|
||||
public virtual void Run(TargetData targetData)
|
||||
{
|
||||
//将当前用户的位置发送到udf服务
|
||||
SendUserPositionToServer();
|
||||
|
||||
@@ -23,8 +23,8 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
this.IsRecord = true;
|
||||
recorderData = new RecorderDataModel()
|
||||
{
|
||||
CurrentUser = null,//TODO:PubCommData.CurrentUser,
|
||||
//BelongUserId = PubCommData.CurrentUser.Id,
|
||||
CurrentUser = App.CurrentUser,
|
||||
//BelongUserId = App.CurrentUser.Id,
|
||||
Competitionid = 0,
|
||||
ContinueIndex = 0,
|
||||
ContinueMark = Guid.NewGuid().ToString(),
|
||||
@@ -51,44 +51,41 @@ namespace Assets.Scenes.Ride.Scripts.Model.CyclingModels
|
||||
// recorderData.ContinueIndex = param.ContinueIndex.GetValueOrDefault(0);
|
||||
//}
|
||||
//recorderData.PreDistance = recorderData.EndDistance;
|
||||
//Rhino.PowerFun.Services.MapUDPService.Send(route.RouteInstance.Id, riders.First().UserId, route.Point.First());
|
||||
|
||||
|
||||
//riders = new List<BaseRider>();
|
||||
//TODO 附件的人列表加上自己
|
||||
//var rider = new OnlineRiderModel()
|
||||
//{
|
||||
// NickName = PubCommData.CurrentUser.Nickname,
|
||||
// UserId = PubCommData.CurrentUser.Id,
|
||||
// WxHeadImg = PubCommData.CurrentUser.WxHeadImg + "?t=1",
|
||||
// //Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]),
|
||||
// EndDistance = recorderData.EndDistance
|
||||
//};
|
||||
//rider.Point = _turfHelper.Along(rider.EndDistance);
|
||||
riders = new List<BaseRider>();
|
||||
var rider = new OnlineRiderModel()
|
||||
{
|
||||
NickName = App.CurrentUser.Nickname,
|
||||
UserId = App.CurrentUser.Id,
|
||||
WxHeadImg = App.CurrentUser.WxHeadImg + "?t=1",
|
||||
//Point = new GeoJSON.Net.Geometry.GeographicPosition(this.route.RouteInstance.Point[0], this.route.RouteInstance.Point[1]),
|
||||
EndDistance = recorderData.EndDistance
|
||||
};
|
||||
rider.Point = _turfHelper.Along(rider.EndDistance);
|
||||
|
||||
//riders.Add(rider);
|
||||
riders.Add(rider);
|
||||
#endregion
|
||||
}
|
||||
|
||||
protected override void Run(TargetData targetData)
|
||||
public override void Run(TargetData targetData)
|
||||
{
|
||||
#region TODO 获取在线用户
|
||||
//riders.RemoveAll(r => r.IsSelf == false);
|
||||
//var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id).Where(d => d.IsSelf == false)
|
||||
// .ToList();
|
||||
|
||||
//foreach (var item in onlineUsers)
|
||||
//{
|
||||
// riders.Add(new OnlineRiderModel()
|
||||
// {
|
||||
// NickName = item.Name,
|
||||
// UserId = item.Id,
|
||||
// WxHeadImg = item.HeadImage,
|
||||
// Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
// EndDistance = item.EndDistance,
|
||||
// PreDistance = item.PreDistance,
|
||||
// });
|
||||
//}
|
||||
riders.RemoveAll(r => r.IsSelf == false);
|
||||
var onlineUsers = MapUDPService.GetOnlineUsers(recorderData.CurrentRoute.RouteInstance.Id).Where(d => d.IsSelf == false)
|
||||
.ToList();
|
||||
foreach (var item in onlineUsers)
|
||||
{
|
||||
riders.Add(new OnlineRiderModel()
|
||||
{
|
||||
NickName = item.Name,
|
||||
UserId = item.Id,
|
||||
WxHeadImg = item.HeadImage,
|
||||
Point = new GeoJSON.Net.Geometry.GeographicPosition(item.Point[0], item.Point[1]),
|
||||
EndDistance = item.EndDistance,
|
||||
PreDistance = item.PreDistance,
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
base.Run(targetData);
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UserId == PubCommData.CurrentUser.Id;
|
||||
return this.UserId == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +276,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
|
||||
public class NearRiderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Headimage { get; set; }
|
||||
@@ -499,7 +500,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return Id == PubCommData.CurrentUser.Id;
|
||||
return Id == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
//private readonly MapWorkoutService service = new MapWorkoutService();
|
||||
|
||||
public t_user CurrentUser { get; set; }
|
||||
public UserResultModel CurrentUser { get; set; }
|
||||
/// <summary>
|
||||
/// 所属人ID
|
||||
/// </summary>
|
||||
@@ -147,8 +147,8 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
AveragePower = averagePower,//平均功率
|
||||
MaxPower = RiderDatas.Max(a => a._Power),//最大功率
|
||||
WeightKg = Math.Round(averagePower / 65, 2),
|
||||
Weight = 65, //PubCommData.CurrentUser.Weight,
|
||||
BicycleWeight =7, //PubCommData.CurrentUser.BicycleWeight,
|
||||
Weight = 65, //App.CurrentUser.Weight,
|
||||
BicycleWeight =7, //App.CurrentUser.BicycleWeight,
|
||||
ContinueMark = ContinueMark,
|
||||
ContinueIndex = ContinueIndex,
|
||||
IsDelete = false,
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace Assets.Scenes.Ride.Scripts.Model
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.UserId == PubCommData.CurrentUser.Id;
|
||||
return this.UserId == App.CurrentUser.Id;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class NearByHeadScript :MonoBehaviour
|
||||
{
|
||||
private Text Title;
|
||||
private Text OnlineUserNum;
|
||||
private void Start()
|
||||
{
|
||||
Title = transform.Find("Title").GetComponent<Text>();
|
||||
OnlineUserNum = transform.Find("OnlineUserNum").GetComponent<Text>();
|
||||
}
|
||||
float t = 1;
|
||||
private void Update()
|
||||
{
|
||||
t -= Time.deltaTime;
|
||||
while (t < 0)
|
||||
{
|
||||
OnlineUserNum.text = MapUDPService.GetNearRiderCount().ToString();
|
||||
t = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab770f3fae92ac1478b8a7c28eccb895
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,115 @@
|
||||
using Assets.Cyp.Common;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class NearByItemScript : MonoBehaviour
|
||||
{
|
||||
private RawImage Head;
|
||||
private RawImage Country;
|
||||
private Text Name;
|
||||
private Text Speed;
|
||||
private Text Distance;
|
||||
private Text Ratio;//功体比
|
||||
|
||||
private int _userId = 0;
|
||||
public int UserId { get { return _userId; } }
|
||||
private string _headUrl=string.Empty;
|
||||
private string _countryUrl = string.Empty;
|
||||
private string _name = string.Empty;
|
||||
private string _speed = string.Empty;
|
||||
private string _distance = string.Empty;
|
||||
private string _ratio = string.Empty;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Head = transform.Find("Head").GetComponent<RawImage>();
|
||||
Country = transform.Find("Country").GetComponent<RawImage>();
|
||||
Name = transform.Find("Name").GetComponent<Text>();
|
||||
Speed = transform.Find("Speed").GetComponent<Text>();
|
||||
Distance = transform.Find("Distance").GetComponent<Text>();
|
||||
Ratio = transform.Find("Ratio").GetComponent<Text>();
|
||||
}
|
||||
|
||||
public void setRatio(string ratio)
|
||||
{
|
||||
if (!_ratio.Equals(ratio))
|
||||
{
|
||||
Ratio.text = ratio;
|
||||
}
|
||||
}
|
||||
|
||||
public void setHead(string url)
|
||||
{
|
||||
if (!_headUrl.Equals(url))
|
||||
{
|
||||
StartCoroutine(DownloadImage(Head, url));
|
||||
var rect = ((RectTransform)Head.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Head.material = material;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DownloadImage(RawImage img, string MediaUrl)
|
||||
{
|
||||
if (!App.TextureCache.ContainsKey(MediaUrl))
|
||||
{
|
||||
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl);
|
||||
yield return request.SendWebRequest();
|
||||
if (request.isNetworkError || request.isHttpError)
|
||||
Debug.Log(request.error);
|
||||
else
|
||||
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
|
||||
|
||||
App.TextureCache.Add(MediaUrl, img.texture);
|
||||
}
|
||||
else
|
||||
{
|
||||
img.texture = App.TextureCache["MediaUrl"];
|
||||
}
|
||||
}
|
||||
|
||||
public void setCountry(string url)
|
||||
{
|
||||
if (!_countryUrl.Equals(url))
|
||||
{
|
||||
StartCoroutine(DownloadImage(Country, url));
|
||||
var rect = ((RectTransform)Country.transform).rect;
|
||||
Material material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
||||
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
||||
Country.material = material;
|
||||
}
|
||||
}
|
||||
public void setName(string name)
|
||||
{
|
||||
if (!_name.Equals(name))
|
||||
Name.text = name;
|
||||
}
|
||||
|
||||
public void setSpeed(string speed)
|
||||
{
|
||||
if (!_speed.Equals(speed))
|
||||
Speed.text = speed;
|
||||
}
|
||||
|
||||
public void setDistance(string distance)
|
||||
{
|
||||
if (!_distance.Equals(distance))
|
||||
Distance.text = distance;
|
||||
}
|
||||
|
||||
public void setUserId(int userId)
|
||||
{
|
||||
_userId = userId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44fc978b4005ef44da1bdb422373f314
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,133 @@
|
||||
using Assets.Scenes.Ride.Scripts.Model;
|
||||
using Assets.Scripts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class NearListFactory : MonoBehaviour
|
||||
{
|
||||
PlayerController playerController;
|
||||
private GameObject nearByItem;
|
||||
private GameObject nearByMajorItem;
|
||||
private GameObject scroll;
|
||||
GameObject body;
|
||||
|
||||
private int bufferSize = 0;
|
||||
private int pageIndex = 1;
|
||||
private int pageSize =7;
|
||||
|
||||
private int preNum = 0;//前面的数量
|
||||
private int offset = 8;//显示区域的数量
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playerController = FindObjectOfType<PlayerController>();
|
||||
nearByItem = Resources.Load<GameObject>("UI/Prefab/Ride/NearbyItem");
|
||||
nearByMajorItem = Resources.Load<GameObject>("UI/Prefab/Ride/NearbyMajorItem");
|
||||
Assert.IsNotNull(nearByItem);
|
||||
scroll = transform.parent.parent.gameObject;
|
||||
if (scroll != null)
|
||||
{
|
||||
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
}
|
||||
float t =1f;
|
||||
private void Update()
|
||||
{
|
||||
t -= Time.deltaTime;
|
||||
while (t < 0)
|
||||
{
|
||||
Utils.DestroyChildren(transform);
|
||||
var nearList = MapUDPService.GetNearRiderData(pageIndex, pageSize, new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y });
|
||||
|
||||
for (int i = 0; i < nearList.Count(); i++)
|
||||
{
|
||||
Create(nearList[i]);
|
||||
}
|
||||
t = 1;
|
||||
}
|
||||
}
|
||||
private void OnEndDrag(BaseEventData arg0)
|
||||
{
|
||||
var scrollrect = scroll.GetComponent<ScrollRect>();
|
||||
if (scrollrect.verticalNormalizedPosition <= 0)
|
||||
{
|
||||
Debug.Log(scrollrect.verticalNormalizedPosition);
|
||||
pageIndex++;
|
||||
//RefreshList();
|
||||
|
||||
}
|
||||
if (scrollrect.verticalNormalizedPosition >= 1)
|
||||
{
|
||||
pageIndex--;
|
||||
//RefreshList();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshList()
|
||||
{
|
||||
var nearList = MapUDPService.GetNearRiderData(pageIndex, pageSize, new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y });
|
||||
|
||||
for (int i = 0; i < nearList.Count(); i++)
|
||||
{
|
||||
if (bufferSize < pageSize)
|
||||
{
|
||||
Create(nearList[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateItem(nearList[i],i);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void Create(NearRiderModel item)
|
||||
{
|
||||
//创建
|
||||
GameObject prefabItem = item.IsSelf ? nearByMajorItem : nearByItem;
|
||||
GameObject newObj = (GameObject)Instantiate(prefabItem, transform);
|
||||
var nearByItemscript = newObj.GetComponent<NearByItemScript>();
|
||||
nearByItemscript.setUserId(item.Id);
|
||||
nearByItemscript.setName(item.Name);
|
||||
nearByItemscript.setRatio(item.KGWeight+"W/KG");
|
||||
nearByItemscript.setSpeed(item.Speed.ToString() + "KM/H");
|
||||
nearByItemscript.setHead(item.Headimage);
|
||||
nearByItemscript.setCountry(item.CountryImg);
|
||||
nearByItemscript.setDistance(item.Near.ToString() + "KM");
|
||||
bufferSize++;
|
||||
}
|
||||
|
||||
private void UpdateItem(NearRiderModel item,int index)
|
||||
{
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
var child = transform.GetChild(i);
|
||||
if (child != null)
|
||||
{
|
||||
NearByItemScript nearByItemscript = child.GetComponent<NearByItemScript>();
|
||||
if (nearByItemscript.UserId == item.Id)
|
||||
{
|
||||
nearByItemscript.setName(item.Name);
|
||||
nearByItemscript.setRatio(item.KGWeight + "W/KG");
|
||||
nearByItemscript.setSpeed(item.Speed.ToString() + "KM/H");
|
||||
//nearByItemscript.setHead(item.Headimage);
|
||||
//nearByItemscript.setCountry(item.CountryImg);
|
||||
nearByItemscript.setDistance(item.Near.ToString() + "KM");
|
||||
if (index != i)//重排序
|
||||
{
|
||||
child.SetSiblingIndex(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1422da55067b129428f0a2833db916b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -100,7 +100,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
/// </summary>
|
||||
private static void SendHeartbeat()
|
||||
{
|
||||
Send(0, PubCommData.CurrentUser.Id, new double[] { 0, 0 }, false, false, 0, true, 0);
|
||||
Send(0, App.CurrentUser.Id, new double[] { 0, 0 }, false, false, 0, true, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
if (MapUDPService._udpService == null) return;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Send(0, PubCommData.CurrentUser.Id, new double[] { 1, 1 }, true, isExit);
|
||||
Send(0, App.CurrentUser.Id, new double[] { 1, 1 }, true, isExit);
|
||||
}
|
||||
_udpService.Close();
|
||||
|
||||
@@ -199,12 +199,15 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int GetNearRiderCount()
|
||||
{
|
||||
return onlineUserHelper.OnlineUsers.Count();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取附近的人(当前在线的所有人)
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static object GetNearRiderData(int pageIndex, int pageSize = 5, double[] point = null)
|
||||
public static IList<NearRiderModel> GetNearRiderData(int pageIndex, int pageSize = 5, double[] point = null)
|
||||
{
|
||||
if (point == null) return null;
|
||||
|
||||
@@ -212,7 +215,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
var allOnlineUsers = onlineUserHelper.OnlineUsers;
|
||||
foreach (var item in allOnlineUsers)
|
||||
{
|
||||
if (item.Id == PubCommData.CurrentUser.Id)
|
||||
if (item.Id == App.CurrentUser.Id)
|
||||
{
|
||||
dict.Add(new Tuple<double, OnlineUser>(0, item));
|
||||
continue;
|
||||
@@ -233,15 +236,16 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Near = n.Item1, //Math.Round(TurfHelper.GetDistances(point, n.Point) / 1000, 2),
|
||||
KGWeight = n.Item2.WeightKg.ToString(),
|
||||
Speed = Math.Round(n.Item2.Speed, 1),
|
||||
CountryImg = ConfigHelper.Host + $"User/GetCountryImg?userid={n.Item2.Id}",
|
||||
IsSelf = n.Item2.IsSelf
|
||||
});
|
||||
|
||||
return new
|
||||
{
|
||||
NearData = nearData,
|
||||
PageCount = (int)Math.Ceiling((double)allList.Count() / pageSize)
|
||||
};
|
||||
CountryImg = App.Host + $"User/GetCountryImg?userid={n.Item2.Id}",
|
||||
IsSelf = n.Item2.IsSelf,
|
||||
Id = n.Item2.Id
|
||||
}).ToList();
|
||||
return nearData;
|
||||
//return new
|
||||
//{
|
||||
// NearData = nearData,
|
||||
// PageCount = (int)Math.Ceiling((double)allList.Count() / pageSize)
|
||||
//};
|
||||
}
|
||||
|
||||
|
||||
@@ -322,7 +326,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
var list = mes.ToList();
|
||||
//去除自己的数据和命令包
|
||||
//mes.RemoveAll(item => item.MemberId == PubCommData.CurrentUser.Id || item.Point[0] == 0);
|
||||
//mes.RemoveAll(item => item.MemberId == App.CurrentUser.Id || item.Point[0] == 0);
|
||||
list.RemoveAll(item => item.Point[0] == 0 && item.Point[1] == 0);
|
||||
//去除重复数据
|
||||
list = list.Distinct(new OlineUserComparer()).ToList();
|
||||
|
||||
@@ -18,38 +18,44 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
base.Init();
|
||||
}
|
||||
TargetData targetData;
|
||||
/// <summary>
|
||||
/// 计算数据,父类会在此方法后处理动画
|
||||
/// </summary>
|
||||
protected override void Compute()
|
||||
protected override void Compute()
|
||||
{
|
||||
//计算数据
|
||||
//speed = mainController.UpDateSpeed();
|
||||
heartRate = mainController.UpDateHeart()??0;
|
||||
power = mainController.UpdatePower();
|
||||
cadance = mainController.UpdateCadence();
|
||||
|
||||
#if UNITY_EDITOR
|
||||
power = 2000;//测试功率
|
||||
|
||||
#endif
|
||||
speed = Helper.CalculateSpeed(elevation, currentSlope, power, weight, bicycleWeight);
|
||||
distance = mainController.UpdateDistance(speed);
|
||||
totalDistance += distance;
|
||||
//记录骑行数据
|
||||
#if UNITY_EDITOR
|
||||
var recorderData = cyclingExcutor.recorderData;
|
||||
recorderData.RiderDatas.Add(new TargetData
|
||||
targetData = new TargetData
|
||||
{
|
||||
Ticks = ticks,
|
||||
_Power = power,
|
||||
_Speed = speed,
|
||||
_Distance = totalDistance> mapData.TotalDistance? mapData.TotalDistance: totalDistance,
|
||||
_Distance = totalDistance > mapData.TotalDistance ? mapData.TotalDistance : totalDistance,
|
||||
_Cadence = cadance,
|
||||
_HeartRate = heartRate,
|
||||
_Lat = nextlatlong.x,
|
||||
_Lon = nextlatlong.y
|
||||
});
|
||||
};
|
||||
recorderData.RiderDatas.Add(targetData);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
protected override void SendTcp()
|
||||
{
|
||||
mainController.cyclingController.Run(null);
|
||||
}
|
||||
//上传数据
|
||||
protected override void Upload()
|
||||
{
|
||||
|
||||
@@ -1,32 +1,41 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
|
||||
namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
public class PlayerItemFactory : MonoBehaviour
|
||||
public class NearByItemFactory : MonoBehaviour
|
||||
{
|
||||
public GameObject prefab; // This is our prefab object that will be exposed in the inspector
|
||||
|
||||
private GameObject nearByItem;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Populate();
|
||||
nearByItem = Resources.Load<GameObject>("UI/Prefab/Ride/NearbyItem");
|
||||
Assert.IsNotNull(nearByItem);
|
||||
}
|
||||
|
||||
float t = 1;
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Populate()
|
||||
{
|
||||
GameObject newObj; // Create GameObject instance
|
||||
|
||||
for (int i = 0; i < 16; i++)
|
||||
t -= Time.deltaTime;
|
||||
while (t < 0)
|
||||
{
|
||||
// Create new instances of our prefab until we've created as many as we specified
|
||||
newObj = (GameObject)Instantiate(prefab, transform);
|
||||
//var nearList = MapUDPService.GetNearRiderData(1, 20, new double[] { playerController.Nextlatlong.x, playerController.Nextlatlong.y });
|
||||
//Debug.Log(nearList.Count());
|
||||
GameObject newObj; // Create GameObject instance
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
// Create new instances of our prefab until we've created as many as we specified
|
||||
newObj = (GameObject)Instantiate(nearByItem, transform);
|
||||
var nearByItemscript = newObj.GetComponent<NearByItemScript>();
|
||||
nearByItemscript.setName("");
|
||||
nearByItemscript.setRatio("");
|
||||
nearByItemscript.setSpeed("");
|
||||
nearByItemscript.setHead("");
|
||||
t = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
Material _material;
|
||||
[SerializeField]
|
||||
[Range(1, 10)]
|
||||
private float UpdateFrequency = 2;
|
||||
private float UpdateFrequency = 1;
|
||||
|
||||
private int _counter;
|
||||
|
||||
@@ -127,9 +127,9 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
{
|
||||
Transform camreatra = Camera.main.transform;
|
||||
Vector3 viewPos = Camera.main.WorldToViewportPoint(position);
|
||||
Vector3 dir = (position - camreatra.position).normalized;
|
||||
Vector3 dir = (position - camreatra.localPosition).normalized;
|
||||
float dot = Vector3.Dot(camreatra.forward, dir);
|
||||
if (dot > -1 && viewPos.x > -1 && viewPos.x < 2 && viewPos.y > -1 && viewPos.y < 2)
|
||||
if (dot > -1 && viewPos.x >= -1 && viewPos.x <= 2 && viewPos.y >= -1 && viewPos.y <= 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -182,7 +182,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
lineRender.SetWidth(0.2f, 0.2f);
|
||||
lineRender.SetVertexCount(dat.Count);
|
||||
lineRender.SetPositions(feat.Points[0].ToArray());
|
||||
//lineRender.numCapVertices = 90;
|
||||
lineRender.loop = false;
|
||||
//lineRender.numCapVertices = 90;
|
||||
float alpha = 1.0f;
|
||||
//Gradient gradient = new Gradient();
|
||||
//gradient.SetKeys(
|
||||
|
||||
@@ -18,27 +18,18 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
public class SingleUIManager : MonoBehaviour
|
||||
{
|
||||
#region UI control
|
||||
[SerializeField]
|
||||
Text Fps;//开始按钮
|
||||
[SerializeField]
|
||||
Text Fps;//fps
|
||||
Button startBtn;//开始按钮
|
||||
[SerializeField]
|
||||
Button simpleBtn;//进入简约模式按钮
|
||||
[SerializeField]
|
||||
Text ditance;//当前骑行距离
|
||||
[SerializeField]
|
||||
Text totalDistance;//当前骑行距离
|
||||
[SerializeField]
|
||||
Text candance;//踏频
|
||||
[SerializeField]
|
||||
Text heartRate;//心率
|
||||
[SerializeField]
|
||||
GameObject rightPanel;//右边列表
|
||||
[SerializeField]
|
||||
GameObject leftPanel;//左边列表
|
||||
[SerializeField]
|
||||
|
||||
GameObject nextSlopePanel;//下一个坡度面板
|
||||
[SerializeField]
|
||||
|
||||
GameObject currentSlopePanel;//当前坡度面板
|
||||
[SerializeField]
|
||||
Text nextSlopeText;//下一个坡度
|
||||
@@ -75,8 +66,8 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
#region 控制器
|
||||
|
||||
PlayerController playerController;//当前用户
|
||||
CyclingController mainController;//主控制器
|
||||
public PlayerController playerController;//当前用户
|
||||
public CyclingController mainController;//主控制器
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -85,6 +76,19 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
|
||||
void Awake()
|
||||
{
|
||||
Fps = transform.Find("Panel/FPS").GetComponent<Text>();
|
||||
leftPanel = transform.Find("Panel/ReviewPanel").gameObject;
|
||||
rightPanel = transform.Find("Panel/NearPanel").gameObject;
|
||||
startBtn = transform.Find("Panel/StartButton").GetComponent<Button>();
|
||||
simpleBtn = transform.Find("Panel/SimpleButton").GetComponent<Button>();
|
||||
ditance = transform.Find("Panel/CyclingComputerPanel/Distance").GetComponent<Text>();
|
||||
totalDistance = transform.Find("Panel/TotalDistancePanel/TotalDistance").GetComponent<Text>();
|
||||
candance = transform.Find("Panel/PowerPanel/Cadance").GetComponent<Text>();
|
||||
heartRate = transform.Find("Panel/PowerPanel/Hrv").GetComponent<Text>();
|
||||
nextSlopePanel = transform.Find("Panel/NextSlopePanel").gameObject;
|
||||
currentSlopePanel = transform.Find("Panel/CurrentSlopePanel").gameObject;
|
||||
|
||||
|
||||
startBtn.onClick.AddListener(StartRide);
|
||||
simpleBtn.onClick.AddListener(ClearPanel);
|
||||
StartOrPauseButton.onClick.AddListener(PauseRide);
|
||||
@@ -98,7 +102,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
mainController = FindObjectOfType<CyclingController>();
|
||||
var route = mainController.GetRoute();
|
||||
mapName.text = route.RouteInstance.Name;
|
||||
totalDistance.text = "/" + Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";
|
||||
totalDistance.text = Math.Round(mainController.GetMapData().TotalDistance, 2).ToString() + "KM";//总里程
|
||||
RenderChart();
|
||||
startIndex = playerController.CurrentIndex;
|
||||
}
|
||||
@@ -182,6 +186,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
//显示设备连接
|
||||
private void ShowDevicePanel()
|
||||
{
|
||||
UIManager.Show(UIManager.Instance.DevicePanel, transform.Find("Panel").gameObject);
|
||||
}
|
||||
//显示设置
|
||||
private void ShowSettingPanel()
|
||||
@@ -192,8 +197,7 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
private void ClearPanel()
|
||||
{
|
||||
leftPanel.transform.DOLocalMove(new Vector3(leftPanel.transform.localPosition.x + isSimple * -430f, leftPanel.transform.localPosition.y, leftPanel.transform.localPosition.z), 1);
|
||||
rightPanel.transform.DOLocalMove(new Vector3(rightPanel.transform.localPosition.x+ isSimple* 330f, rightPanel.transform.localPosition.y, rightPanel.transform.localPosition.z), 1);
|
||||
//elevationChart.transform.DOMoveX(elevationChart.transform.position.x + isSimple * 286.1764f, 1);
|
||||
rightPanel.transform.DOLocalMove(new Vector3(rightPanel.transform.localPosition.x + isSimple * 330f, rightPanel.transform.localPosition.y, rightPanel.transform.localPosition.z), 1);
|
||||
isSimple *= -1;
|
||||
}
|
||||
|
||||
@@ -230,7 +234,10 @@ namespace Assets.Scenes.Ride.Scripts
|
||||
}
|
||||
|
||||
elevationChart.RefreshChart();
|
||||
Utils.DisplayImage(StartCoroutine, img, App.CurrentUser.WxHeadImg);
|
||||
if (App.CurrentUser != null)
|
||||
{
|
||||
Utils.DisplayImage(StartCoroutine, img, App.CurrentUser.WxHeadImg);
|
||||
}
|
||||
}
|
||||
//长路线动态更新chart
|
||||
private int initCount;
|
||||
|
||||
Reference in new issue
Block a user